Skip to main content
These examples use GIWA Sepolia (91342) and Viem. Replace the sample tokens and recipient with your own values. Always request a fresh quote immediately before a trade.

Shared setup

Direct V2 swap — without SOR

Use this when you intentionally want one known V2 path. It does not search V3 pools or alternative paths. The example reads the V2 quote from the router, applies 0.5% slippage protection, approves the V2 router, then sends the swap.
getAmountsOut is a V2-only estimate. It can change before your transaction lands. Never set amountOutMin to zero in a production integration.

Smart-order-routed swap — with SOR

The Topokki API evaluates available V2 and V3 routes and returns ready-to-submit Universal Router calldata. For ERC-20 input tokens, authorize both Permit2 and the Universal Router in Permit2 before sending the quote’s transaction. See Get a swap quote for the complete endpoint reference.
The first two approvals can be skipped when the existing allowances already cover the input amount and intended expiry. For native ETH input, request a quote with tokenInIsNative=true; do not perform ERC-20/Permit2 approval for that input.
Do not modify the transaction destination, calldata, or value returned by the quote. If the amount, recipient, slippage, or route requirements change, request a new quote.