SwapKit API Code Examples

API By Developers, For Developers

SwapKit API is a cutting-edge price quote and trade routing API for cross-chain swaps. This comprehensive tool integrates decentralized exchanges (DEXs) and DEX aggregators into your platform- enabling anyone to swap assets across a diversity of blockchains in a totally decentralized manner.

Example 1: Request Supported Chains

Access a growing list of supported chains and cross-chain trading options.

Example 2: Request Providers

Access a growing list of supported liquidity sources and aggregators.

Example 3: Request a Quote

Retrieve quotes for THORChain and DEX aggregation swaps.

Retrieve a list of all the chains the API supports by querying the /chains endpoint:

				
					const getSupportedChains = async () => {

const result = await axios.get('https://api.thorswap.net/aggregator/chains');

return result.data;

}
				
			

The result contains a list of chains like the following:

				
					{
"ETH": "1",
"AVAX": "43114",
"THOR": "thorchain-mainnet-v1",
"BTC": "bitcoin",
"LTC": "litecoin",
"BNB": "Binance-Chain-Tigris",
"BSC": "56",
"BCH": "bitcoincash",
"GAIA": "cosmoshub-4",
"DOGE": "dogecoin"
}
				
			

To get a full list of the providers supported by the API, the /supportedProviders endpoint can be queried:

				
					const getSupportedProviders = async () => {
    const result = await axios.get('https://api.thorswap.net/aggregator/providers/supportedProviders');
    return result.data
}
				
			

The result contains a list of providers like the following:

				
					[
    "KYBER",
    "ONEINCH",
    "SUSHISWAP",
    "THORCHAIN",
    "UNISWAPV2",
    "UNISWAPV3",
    "ZEROX",
    "ONEINCH-AVAX",
    "PANGOLIN",
    "TRADERJOE",
    "KYBER-AVAX",
    "WOOFI-AVAX",
    "PANCAKESWAPV2-BSC"
]
				
			

Send a transaction from any off supported wallets via SwapKit /quote endpoint:

				
					const getQuote = async (sellAsset, toAsset, sellAmount, senderAddress, recipientAddress) => {
    const result = await axios.get('https://api.thorswap.net/aggregator/tokens/quote', {
        params: {
            sellAsset,
            toAsset,
            sellAmount,
            senderAddress,
            recipientAddress,
        }
    });
    return result.data;
}

const sellAsset = 'BTC.BTC';
const toAsset = 'ETH.ETH';
const sellAmount = 0.1;
const senderAddress = BTC_WALLET_ADDRESS;
const recipientAddress = ETH_WALLET_ADDRESS;

const quote = await getQuote(sellAsset, toAsset, sellAmount, senderAddress, recipientAddress);
				
			

The future of finance is multi-chain and permissionless, get ready today with SwapKit