Skip to main content
Follow the DEX integration template file by file: how it finds pools, prices routes, handles native BOT and protects each swap.
Ready. This template is published in uzolabs/templates and has been deployed and verified on testnet. It’s a learning template and hasn’t been audited. Use test funds only.

Project layout

Project layout
The scripts and the widget share frontend/src/dex/, so a quote in the terminal and a quote in the browser come from the same code. There are no contracts.

Finding pools

Terminal
Output
This output is from 1 October 2026. The script calls getPair on the V2 factory and getPool on the V3 factory once per fee tier. Not every tier has a pool, and some hold very little.

Quotes

Terminal
Output
  • V2 quotes come from Router02’s getAmountsOut.
  • V3 quotes come from QuoterV2’s quoteExactInputSingle. It isn’t a view function: it runs the swap and reverts with the result. The template calls it with viem’s simulateContract, which uses eth_call, so nothing is sent.
The best route is the one that gives you the most.

BOT and WBOT

Pools hold ERC-20 tokens. BOT isn’t one, so pools trade WBOT, which is always worth exactly 1 BOT. “ETH” in the router function names means the chain’s native coin, which is BOT here.

Slippage, deadline and approvals

  • Slippage. The minimum you accept is the quote minus your slippage, 0.5% by default and at most 5%. If the pool would give less, the swap reverts and you only lose gas.
  • Deadline. Each swap carries a deadline 20 minutes ahead, so a transaction stuck in the mempool can’t fill hours later.
  • Approvals. Before swapping a token, the script approves the router for exactly the trade amount. Router02 and SwapRouter each need their own approval. If enough is already approved, the script skips that step.
  • Decimals. USDT has 6 decimals and BOT and WBOT have 18. Every amount goes through parseUnits(amount, token.decimals). See USDT and decimals.

A swap from the terminal

Terminal
Output
The BOT change after the swap includes gas. If the public RPC is busy, the scripts retry for about 15 seconds before they stop. A step that already went through, such as an approval, isn’t repeated when you run the command again.

The widget

“What you got” is your balance after the block minus your balance before it. If a transaction reverted on chain, the widget replays it on the block before to get the router’s reason. It never reads event logs, because BOT Chain’s public RPCs don’t serve eth_getLogs.

Next steps

Customize

Change slippage, add tokens and routes.

Slippage and deadlines

How the minimum and deadline protect a swap.
Last modified on October 2, 2026