App Kit includes the Swap capability that lets you swap two tokens
on the same blockchain in a few lines of code. If you only need to swap and
don’t want the full App Kit, you can install the Swap package
on its own. You need a (free)
kit key from the
Circle Console to use Swap.
Swap is not available on Arc Testnet and other testnets. Use mainnet for Swap.
Quick look
This example swaps USDT for USDC in a single method call:
// Swap 1.00 USDT for USDC on Ethereum
const result = await kit.swap({
from: { adapter: viemAdapter, chain: "Ethereum" },
tokenIn: "USDT",
tokenOut: "USDC",
amountIn: "1.00",
config: {
kitKey: process.env.KIT_KEY as string, // Your kit key from the Circle Console
},
});
Installation
App Kit comes with the Swap capability installed by default. If you’ve already
installed App Kit, you can skip this section.
If you only need to swap and don’t want the full App Kit, you can install just
the Swap package.
Install the Swap package and the adapter that matches your environment:
Viem
Ethers
Solana
Circle Wallets
npm install @circle-fin/swap-kit @circle-fin/adapter-viem-v2 viem
npm install @circle-fin/swap-kit @circle-fin/adapter-ethers-v6 ethers
npm install @circle-fin/swap-kit @circle-fin/adapter-solana-kit solana
npm install @circle-fin/swap-kit @circle-fin/adapter-circle-wallets