Prerequisites
Before this page: a connected or embedded wallet (see Connecting external wallets).What you’ll build
A swap flow has four steps:- Quote — ask for a route between two tokens.
- Show the estimated amount received and gas cost.
- Execute — sign and submit from the user’s wallet.
- Track — poll until the swap is done.
1000000 for 1 USDC with 6 decimals).
Quoting a swap
getSwapQuote takes a from and to side. Set from.amount to quote by input (or to.amount to quote by desired output — they’re mutually exclusive). The response includes the signingPayload you’ll execute and the estimated to.amount.
- TypeScript
- React
Executing the swap
Pass the quote’ssigningPayload to executeSwapTransaction. ERC-20 swaps may need a separate approval first — onStepChange tells you which step is running so you can update the UI.
- TypeScript
- React
Tracking status
A swap can take time to settle — especially across chains. PollgetSwapStatus with the transaction hash until the status is DONE or FAILED.
- TypeScript
- React
Re-check on an interval and resolve only once the swap reaches a terminal status.
Handling errors
See also
- Transaction confirmation & simulation — confirm the underlying transaction
- Token balances & display — reflect balances after the swap
- Funding flows — get tokens to swap