A sandwich attack is a bot trading just before and after your DEX swap to profit from its price move. See a worked example and how to avoid one.

A sandwich attack is a trading exploit in which a bot places one trade immediately before and one immediately after a victim's DEX swap, profiting from the price move the victim's trade causes. The victim's swap still goes through, but at a worse price, and the difference ends up with the attacker. It is one of the most common forms of MEV on decentralized exchanges.
The name describes the shape of the attack: the victim's transaction is the filling between two attacker transactions. The first trade (the front-run) buys the same asset the victim is buying, pushing its price up. The victim then buys at that inflated price. The second trade (the back-run) sells into the price the victim pushed even higher.
Sandwich attacks are a specific kind of front-running. Front-running in crypto means acting on knowledge of a pending transaction before it executes; a sandwich adds the second leg so the attacker exits with a profit in the same block.
The attack only works because swaps carry a slippage tolerance. The bot calculates exactly how far it can push the price while keeping the victim's trade just inside its minimum-received limit.
The attacker needs control over ordering, which it buys with high fees or by sending bundles to block builders. That is why sandwich risk depends heavily on how a chain orders transactions and how visible pending trades are.
A hypothetical constant-product pool holds 100 ETH and 300,000 USDC (spot price 3,000). You submit a swap of 30,000 USDC for ETH with a 5% slippage tolerance. Fees and gas are ignored.
Had you set a 0.5% tolerance instead, your minimum would have been 9.0455 ETH, and a front-run of this size would have made your trade revert. The attack would not have been worth attempting.
Front-running in crypto means placing a transaction ahead of a known pending transaction to profit from the price move it will cause. A sandwich attack is front-running plus a second trade after the victim's, so the attacker closes the position immediately.
Set a tight slippage tolerance, trade in deep pools, split large orders, and use wallets or aggregators that offer private or MEV-protected transaction submission where available.
Arbitrage profits from a price difference between two markets and helps align prices. A sandwich attack profits by forcing a specific user's trade to fill at a worse price, so its profit comes directly out of that user's output.
JewelSwap Crypto Glossary · educational, not financial advice. Updated 2 October 2026. Browse the full glossary.