Integration
Swapping and Aggregation
Javascript SDK
Get Quote

Get Quote

getQuote

Fetches a quote for swapping tokens based on the provided quoteRequest and an options argument.

getQuote(
  quoteRequest: QuoteRequest,
  options?: RequestOptions
): Promise<QuoteResponse>

The quoteRequest object describes the swap for which a quote is returned.

ParamDescriptionData type
srcChainSource chain for the swapChainId
destChainDestination chain for the swapChainId
srcAssetAsset to be swapped from the source chainstring
destAssetAsset to be received on the destination chainstring
amountAmount of the source token to be swappedstring

Example

import { Chains, Assets } from "@chainflip-io/chainflip-sdk/swap";
 
const quoteRequest = {
  srcChain: Chains.Ethereum,
  destChain: Chains.Bitcoin,
  srcAsset: Assets.ETH,
  destAsset: Assets.BTC,
  amount: (1.5e18).toString(), // 1.5 ETH
};
 
console.log(await swapSDK.getQuote(quoteRequest));

Sample Response

{
  "srcChain": "Ethereum",
  "destChain": "Bitcoin",
  "srcAsset": "ETH",
  "destAsset": "BTC",
  "amount": "1500000000000000000", // 1.5 ETH
  "quote": {
    "intermediateAmount": "2000000000", // 2000 USDC
    "egressAmount": "10000000", // 0.1 BTC
    "includedFees": [
      { "type": "network", "asset": "USDC", "amount": "2000000" },
      { "type": "liquidity", "asset": "ETH", "amount": "15000000000000000" },
      { "type": "liquidity", "asset": "USDC", "amount": "2000000" }
    ]
  }
}

The intermediate amount is the value of the first swap leg.

In this case, BTC > ETH requires both BTC/USDC and USDC/ETH pools (or legs).

Learn more about Chainflip's $USDC Denominated Pools.

;