Skip to main content
This page shows you how to set the two values that protect every swap: the minimum amount you’ll accept, and the time after which the swap must not run.

Slippage

Slippage is the difference between the price you were quoted and the price you get. It happens because other trades can move the pool between your quote and your transaction. Your own trade also moves the price, more so in a thin pool. You can’t stop the price moving, but you can set a floor. Every BDEX swap function takes a minimum output (amountOutMin on V2, amountOutMinimum on V3). If the swap would return less, it reverts and you only lose the gas. Compute the minimum from a fresh quote, in basis points, using bigint:
slippage.ts
Output

Choose a value

These are common starting points, not rules. Never set the minimum to zero. A zero minimum accepts any price, so a bot that sees your pending transaction can move the pool, let your swap fill at a terrible price and move it back. This is called a sandwich attack.
High slippage doesn’t fix a bad quote. If a swap only succeeds with 10% or more, the pool is too thin for your size. Swap less, or use another pool.

Let users choose

In a UI, show the minimum received next to the quote, default to 0.5%, and warn above about 3%. Quote again right before you send, not when the page loaded.

Deadlines

The deadline is a Unix timestamp in seconds. If the transaction is mined after it, the router reverts: BotDexV2Router: EXPIRED on V2 and Transaction too old on V3. Without a deadline, a transaction stuck in the mempool could run hours later at a price that no longer suits you. Your minimum output still protects you, but a deadline also keeps old, forgotten swaps from running at all.
deadline.ts

Choose a value

  • Scripts and bots: 1 to 5 minutes. They send right away, so a short deadline is safe.
  • Wallet UIs: 10 to 20 minutes, to give the user time to review and sign.
The router compares your deadline with the block’s timestamp, not your computer’s clock. If your clock is far off, you may see EXPIRED on transactions you just sent.

Both together

The guides in this section use 0.5% slippage and a 20-minute deadline. See them applied in Swap on BDEX V2 and Swap on BDEX V3. The same two values protect adding and removing liquidity, where they guard both token amounts. See Provide V2 liquidity.

Troubleshooting

Check that you quote right before sending, and that the quote and the swap use the same path or fee tier. If the pool is thin, swap a smaller amount.
Check the decimals. A minimum computed from a quote in USDT base units must stay in USDT base units. See USDT and decimals.

Next steps

Swap on BDEX V2

Apply both values to a V2 swap.

Swap on BDEX V3

Compare fee tiers and swap.
Last modified on October 2, 2026