πŸ“¦ Install dKiT SDK

πŸ”„ Swap

Before making a swap, you need to request the best route from the dKiT 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;
}

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

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 dKiT 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 { doritoKitApi } from '@doritokit/sdk'

const quoteParams = {
  buyAsset: "BTC.BTC",
  includeTx: true,
  destinationAddress: client.getWallet(Chain.Bitcoin),
  sellAmount: "1",
  sellAsset: "ETH.ETH",
  sourceAddress: client.getWallet(Chain.Ethereum).address,
};

const quote = await fetch("https://crunchy.dorito.club/api/quote", {
  body: JSON.stringify(quoteParams),
  headers: { "content-type": "application/json" },
  method: "POST",
});

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

import { FeeOption } from '@doritokit/sdk';

const bestRoute = routes.find(({ optimal }) => optimal)

const txHash = await dkClient.swap({
    route: bestRoute,
    recipient: '...',
    feeOptionKey: FeeOption.Fast
    // FeeOption multiplies current base fee by:
    // Average => 1.2 
    // Fast => 1.5
    // Fastest => 2
});

// Returns explorer url like etherscan, viewblock, etc.
const explorerUrl = skClient.getExplorerTxUrl(inputChain, txHash)

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

import { FeeOption } from '@doritokit/sdk';

const bestRoute = routes.find(({ optimal }) => optimal)

const txHash = await dkClient.swap({
    route: bestRoute,
    recipient: '...',
    feeOptionKey: FeeOption.Fast
    // FeeOption multiplies current base fee by:
    // Average => 1.2 
    // Fast => 1.5
    // Fastest => 2
});

// Returns explorer url like etherscan, viewblock, etc.
const explorerUrl = skClient.getExplorerTxUrl(inputChain, txHash)

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

🚨 Executing ERC20 Swaps with tokens on EVM chains need approval spending. Check if asset has been approved with built in methods.

import { AmountWithBaseDenom, AssetEntity } from '@doritokit/sdk'

const isApproved = dkClient.isAssetApprovedForContract(
  asset, // AssetEntity
  contractAddress: selectedRoute.contract
  amount, // AmountWithBaseDenom => amount to check that's possible to spent, default MaxInt256
)

const approveTx = dkClient.approveAssetForContract(
  asset, // AssetEntity
  contractAddress: selectedRoute.contract
  amount, // AmountWithBaseDenom => amount approved to spent, default MaxInt256
)

Join our Community β†’

Any other questions? Book a Call β†’

dKiT

Β·

Β©

2025

All rights reserved

dKiT

Β·

Β©

2025

All rights reserved

dKiT

Β·

Β©

2025

All rights reserved