The SDK supports three patterns for performing token swaps on EVM networks, working with both Regular Accounts (EOAs) and Smart Accounts.
1. All-in-one pattern (Recommended)
Use account.swap() or smartAccount.swap() for a simple, single-line execution. This handles everything automatically.
2. Get pricing information
Use cdp.evm.getSwapPrice() to get quick estimates and check liquidity without committing to a swap. This is suitable for UI displays and is less strictly rate-limited.
3. Create and execute separately
Use account.quoteSwap() or smartAccount.quoteSwap() when you need full control. This returns a quote object that you can inspect before calling .execute().
Note: quoteSwap() signals a soft commitment and may reserve funds on-chain, so it is more strictly rate-limited.
Key Differences: EOA vs Smart Account
- EOAs: Return
transactionHash and execute immediately. - Smart Accounts: Return
userOpHash and execute via user operations (ERC-4337), supporting gas sponsorship via paymasters.
// Recommended: All-in-one swap for EOA
const { transactionHash } = await account.swap({
network: "base",
toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
fromToken: "0x4200000000000000000000000000000000000006",
fromAmount: BigInt("1000000000000000000"),
slippageBps: 100,
});
// Recommended: All-in-one swap for Smart Account
const { userOpHash } = await smartAccount.swap({
network: "base",
toToken: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
fromToken: "0x4200000000000000000000000000000000000006",
fromAmount: BigInt("1000000000000000000"),
slippageBps: 100,
});