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>
Param | Description | Data type |
---|---|---|
quoteRequest (required) | Object containing the quote request parameters. You can find the interface definition below. | Object |
options (optional) | Options related to the HTTP request. | Object |
The quoteRequest
object describes the swap for which a quote is returned.
Param | Description | Data type |
---|---|---|
srcChain (required) | Source chain for the swap | Chain |
destChain (required) | Destination chain for the swap | Chain |
srcAsset (required) | Asset to be swapped from the source chain | Asset |
destAsset (required) | Asset to be received on the destination chain | Asset |
amount (required) | Amount of the source token to be swapped, represented in the base unit of the source token. | string |
Example
import { Chains, Assets } from "@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.