Skip to main content
In this guide you swap tBOT for USDT on BDEX V3 testnet: you find the pool for each fee tier, quote each one with QuoterV2 and swap through the pool with the best price.
Everything on this page uses testnet (chain 968). Get free test tokens from the faucet.

What you’ll build

A viem script that checks the WBOT/USDT pools on the 0.05%, 0.30% and 1.00% fee tiers, picks the best quote, and swaps 0.0005 tBOT through the V3 SwapRouter. You send native tBOT as value, so you don’t need to wrap or approve anything.

Prerequisites

  • The bot-defi project and .env file from Wrap BOT.
  • At least 0.001 tBOT: 0.0005 for the swap plus gas.

Steps

1

Write the script

swap-v3.ts
2

Understand each part

  • getPool(tokenA, tokenB, fee) on the V3 factory returns the pool for one fee tier, or the zero address if nobody created it. Token order doesn’t matter.
  • quoteExactInputSingle runs the swap inside the quoter and reverts to return the result. It isn’t a view function, so call it with simulateContract. A pool with no liquidity at the current price makes it revert, which is why the call is wrapped in try.
  • fee is in hundredths of a basis point: 500 is 0.05%, 3000 is 0.30% and 10000 is 1.00%.
  • amountOutMinimum is the best quote minus 0.5%. If the swap would return less, it reverts.
  • value: amountIn sends tBOT with the call. Because tokenIn is WBOT, the router wraps it before the swap.
  • sqrtPriceLimitX96: 0n means no price limit. Leave it at zero unless you want the swap to stop at a given price.
3

Run it

Verify it worked

Output
The three testnet pools quoted very different prices, and the lowest fee tier gave the worst one. That’s normal for thin pools: the price depends on where liquidity sits, not on the fee. Your numbers will differ.

Swap an ERC-20 token instead

To swap a token such as USDT, drop value and approve the SwapRouter for amountIn first, the same way as in Swap on BDEX V2. To receive native tBOT instead of WBOT, use the router’s multicall to combine exactInputSingle (with the router as recipient) and unwrapWETH9.

Troubleshooting

The output fell below amountOutMinimum. Quote again right before the swap, and raise the slippage only for very thin pools.
The deadline passed before the transaction was mined. Build the deadline right before sending.
The router couldn’t pull your input token. Approve the SwapRouter for at least amountIn and check your balance. You won’t see this when you pay with value.
No pool has liquidity at the current price for your amount. Try a smaller amount, or use the V2 pool.
The error strings come from the SwapRouter’s verified source on BOTScan.

Next steps

Slippage and deadlines

Choose safe values for both.

Provide V3 liquidity

Learn how concentrated liquidity works.
Last modified on October 3, 2026