useQuote
The useQuote hook allows you to fetch and compare bridge quotes from multiple providers (Relay.link and deBridge) to find the best rate for a cross-chain swap.
Usage
import { useQuote } from '@silentswap/react';
import { useAccount } from 'wagmi';
function QuoteComponent() {
const { address } = useAccount();
const { getQuote, isLoading, error } = useQuote({ address });
const handleFetchQuote = async () => {
try {
const quote = await getQuote(
1, // Source chain ID (Ethereum)
'0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48', // Source token (USDC)
'1000000', // Amount (1e6 units = 1 USDC)
43114, // Destination chain ID (Avalanche)
'0xB97EF9Ef8734C71904D8002F8b6Bc66Dd9c48a6E' // Destination token (USDC.e)
);
console.log('Best provider:', quote.provider);
console.log('Estimated output:', quote.outputAmount);
} catch (err) {
console.error('Failed to fetch quote:', err);
}
};
return (
<button onClick={handleFetchQuote} disabled={isLoading}>
{isLoading ? 'Fetching Quote...' : 'Get Best Quote'}
</button>
);
}Options
| Property | Type | Default | Description |
|---|---|---|---|
address | string | - | User's address (required for provider-specific optimizations). |
maxImpactPercent | number | 5 | Maximum allowed price impact percentage. |
Return Values
| Property | Type | Description |
|---|---|---|
getQuote | Function | Async function to fetch the best quote. Signature: (srcChainId, srcToken, srcAmount, dstChainId, dstToken, recipientAddress?, sourceAddress?) => Promise<BridgeQuoteResult>. Optional recipientAddress and sourceAddress are required for Solana destinations. |
estimateLive | Function | Get live estimate for a given direction. Signature: (direction: 'ingress' | 'egress', assetCaip19, chainId, tokenAddress, amount, usdPrice, externalSignal?, recipientAddress?, isReverseCalculation?, targetAmount?) => Promise<EstimateResult>. |
interpolateSamples | Function | Interpolate retention rate from samples. Signature: (samples: EstimateSample[], usdValue: number, marginHi?: number) => number. |
isLoading | boolean | Whether a quote request is currently in flight. |
error | Error | null | Error object if the last request failed. |
ingressEstimates | Record<string, Estimate> | Cache of ingress estimates indexed by CAIP-19. |
egressEstimates | Record<string, Estimate> | Cache of egress estimates indexed by CAIP-19. |