Before you start
- The user’s address, which sends the swap and pays the gas.
- The user’s wallet, to sign the transaction.
- An API key, for production. You can build and test without one.
1
Get a price
Send the two tokens and the amount. Use
native for the chain’s native token.route: "swap"means it happens on one chain.to.amountis what the user should receive after Tern’s fee, andto.minAmountthe least they’ll receive.feesbreaks down the cost: see Fees and pricing.sourceGasis the gas the user will pay. Includesenderin the request and it only counts the approval that address actually needs.etaSecsis how long the chain takes to confirm.
sourceGas unsold.2
Get the transaction
When the user confirms, ask again with
sender (who sends and pays) and recipient (who receives). You can also set slippageBps: how far below the expected amount the swap may land before it reverts. It’s 50 (0.5%) by default and at most 300 (3%).3
Send it right away
From
sender’s wallet:- EVM chains: send
execute.transactionsin order. An approval comes first when it’s needed, and USDT on Ethereum may get an extra approval of zero before it. When selling the native token, the amount travels as the transaction’svalue. - Starknet: send
execute.callstogether, as a single transaction.
expiresAt the contract refuses the swap, so get a new quote rather than sending late.4
Track it
GET /v1/quote/{id} shows awaiting_deposit until the transaction confirms, then completed. A swap that isn’t sent in time becomes expired.Both source.txHash and destination.txHash are the swap’s one transaction. source.amount is what it spent and destination.amount is what the user received.If something goes wrong
How it differs from a cross-chain swap
- No secret, no reveal step, and no deposit address: only
sendercan send the swap. - If the minimum can’t be met, the transaction reverts and nothing moves. There’s never a refund to wait for.
- The quote lasts about a minute, not 30 minutes.
Next steps
Private swaps
The same swap, from a shielded balance on Starknet.
TernSwap
How the swap contract guarantees the minimum.