3Swap

Before making a swap, you need to request the best route from the doritoKit API.

Step 1: Create a QuoteParams Object

The QuoteParams object defines the details of a swap between supported blockchains. It includes all the necessary information to find the best routing options.

Here’s the interface structure for QuoteParams:

interface QuoteParams {
    affiliateBasisPoints?: string;
    buyAsset: string;
    recipientAddress?: string;
    sellAmount: string;
    sellAsset: string;
    senderAddress?: string;
    slippage: string;
}
circle-info

The buyAsset & sellAsset must be of the format 'chain.ticker' For example, BTC.BTC.

circle-info

The recipientAddress must be a valid address for the buyAsset blockchain. Similarly the senderAddress must be a valid address for the sellAsset.

Step 2. Call getQuote from doritoKit API package

After creating the quoteParams object, you can pass it to the getQuote function of the dKitApi class.

// or directly from @doritokit/api
import { SwapKitApi } from '@doritokit/sdk'

const quoteParams = {
    sellAsset: 'BTC.BTC',
    sellAmount: '1',
    buyAsset: 'ETH.ETH',
    senderAddress: '...', // A valid Ethereum address
    recipientAddress: '...', // A valid Bitcoin address
    slippage: '3',
};

const { routes } = await SwapKitApi.getQuote(quoteParams);

Step 3: Choose fee option multiplier, route & execute swap

The skClient used above assumes a wallet has been connected as described in Set up the SDK.

circle-exclamation

Last updated