Skip to content

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

PropertyTypeDefaultDescription
addressstring-User's address (required for provider-specific optimizations).
maxImpactPercentnumber5Maximum allowed price impact percentage.

Return Values

PropertyTypeDescription
getQuoteFunctionAsync 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.
estimateLiveFunctionGet live estimate for a given direction. Signature: (direction: 'ingress' | 'egress', assetCaip19, chainId, tokenAddress, amount, usdPrice, externalSignal?, recipientAddress?, isReverseCalculation?, targetAmount?) => Promise<EstimateResult>.
interpolateSamplesFunctionInterpolate retention rate from samples. Signature: (samples: EstimateSample[], usdValue: number, marginHi?: number) => number.
isLoadingbooleanWhether a quote request is currently in flight.
errorError | nullError object if the last request failed.
ingressEstimatesRecord<string, Estimate>Cache of ingress estimates indexed by CAIP-19.
egressEstimatesRecord<string, Estimate>Cache of egress estimates indexed by CAIP-19.