The App Kit SDK includes the Swap capability that lets you swap two
tokens in a few lines of code. Swap
supports many
stablecoins (including USDC, EURC, USDT, USDe, DAI, and PYUSD) and native tokens
on supported blockchains. You need a (free)
kit key from the
Circle Console to use Swap.
Among testnets, only Arc Testnet supports Swap (USDC, EURC, and cirBTC only).
Use mainnet for Swap on any other blockchains.
Quick look
Same-chain swap
Crosschain swap
This example swaps 1 USDC for EURC on Arc Testnet:const result = await kit.swap({
from: { adapter: viemAdapter, chain: "Arc_Testnet" },
tokenIn: "USDC",
tokenOut: "EURC",
amountIn: "1.00",
config: {
kitKey: process.env.KIT_KEY as string, // Your kit key from the Circle Console
},
});
See Swap tokens on a blockchain
for a full working example. This example swaps 1 USDC on Base for native POL delivered on Polygon in a
single call:const result = await kit.swap({
from: { adapter: viemAdapter, chain: "Base" },
tokenIn: "USDC",
tokenOut: "NATIVE",
amountIn: "1.00",
to: {
chain: "Polygon",
recipientAddress: "0xYourRecipientAddress",
},
config: {
kitKey: process.env.KIT_KEY as string,
},
});
See
Swap tokens across blockchains
for a full working example.
Installation
Install the App Kit SDK to use Swap. If you
only need to swap and don’t want to install the full App Kit SDK, install the
standalone Swap Kit for your preferred adapter below.
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/kit @solana/web3.js
npm install @circle-fin/swap-kit @circle-fin/adapter-circle-wallets