Skip to main content
Change the DEX integration template’s slippage, tokens and routes, or move the swap widget into your own app.
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.

What you’ll build

Your own swap scripts and widget on top of BDEX. Each change below is independent. The scripts and the widget share frontend/src/dex/, so most changes apply to both at once.

Prerequisites

Options per run

These need no code changes:
Terminal
  • --slippage 1 accepts up to 1% less than the quote, for this run only.
  • --fee 500, --fee 3000 or --fee 10000 picks a V3 pool. Without it, swap-v3 uses the pool with the best quote.

Change the code

1

Make your change

Edit the defaults in frontend/src/dex/math.ts. Values are in basis points, so 50 means 0.5%.
frontend/src/dex/math.ts
Raising the maximum lets users accept worse prices by mistake. Keep it low unless you have a reason.
2

Run the tests

Terminal
npm test covers the slippage maths and the failure reasons. Add a test for any new rule.
3

Try it on testnet

Terminal
Quote first, then send a small swap from the widget and check the BOTScan link.

Embed the widget in your app

SwapCard in frontend/src/App.tsx is self-contained. To use it in your own wagmi app, copy:
  1. SwapCard from App.tsx, with SwapResult.tsx.
  2. The whole frontend/src/dex/ folder.
  3. frontend/src/styles.css, and the variables from theme.css if you want the same look.
Your app must already have a WagmiProvider and a QueryClientProvider. See wagmi setup.

Change the look

Edit the variables at the top of frontend/src/theme.css for colours and fonts. The two background glows switch off for users who prefer reduced motion.

Mainnet

Mainnet uses real BOT and real USDT, and this template hasn’t been audited. Check the quote, the minimum received and the router address before you approve anything. Use a separate wallet.
Terminal
Every script that sends a transaction waits for you to type MAINNET. For the widget, set VITE_CHAIN_ID=677 in frontend/.env, run npm --prefix frontend run build, and host the frontend/dist folder on any static host.

Verify

There’s no contract to verify. After a swap, open the BOTScan link the script printed and check the token transfers match the “After” balances.

Troubleshooting

More than 20 minutes passed between building the swap and mining it, usually because the wallet popup stayed open. Swap again for a fresh deadline.
The price moved past your slippage. Nothing was swapped and only gas was spent. Quote again, or raise slippage a little with --slippage 1.
Not every tier has a pool. On testnet there was no 0.01% WBOT/USDT pool when the template was tested. Run npm run find-pools to see which exist.
Use npm run wrap -- 1 or npm run wrap -- 1 --unwrap. In the widget, the button says Wrap or Unwrap.
Quotes appear about half a second after you stop typing. If they never do, check the browser console. A slow or blocked RPC is the usual cause. Set VITE_RPC_URL in frontend/.env and restart npm run frontend.
Its decimals in getTokens doesn’t match the contract. Read decimals() on BOTScan and fix the entry.

Next steps

BDEX V3 swaps

Fee tiers and the SwapRouter by hand.

Token template

Make a token, then add a pool for it.
Last modified on October 3, 2026