What Is a Sandwich Attack in Crypto Trading?
A sandwich attack profits from your trade in the seconds before it confirms — no hacking required, just visibility. Here's exactly how it works.
A sandwich attack happens in the few seconds between submitting a trade and having it confirmed — a window most people don't even realize is exploitable. By the time the trade executes, someone else has already profited from knowing it was coming.
What "Sandwich" Actually Refers To
The name describes the structure: an attacker's transaction goes in right before yours, and another one goes in right after — your trade is sandwiched between the two. Both of the attacker's transactions are built specifically around the trade you were about to make.
How the Attacker Sees Your Trade Coming
Before a transaction is confirmed and added to the blockchain, it sits briefly in a public waiting area called the mempool, visible to anyone monitoring it. Specialized bots continuously scan this mempool looking for pending trades large enough to be worth targeting.
The Two-Part Attack
When a bot spots a target trade, it submits its own buy order first, paying a higher fee to guarantee it processes first — pushing the price up slightly before your trade executes. Your trade then executes at that now-worse price. Immediately after, the bot sells what it just bought, at the price your own trade helped push even higher, pocketing the difference.
Why This Doesn't Require Hacking Anything
A sandwich attack doesn't exploit a bug or steal from your wallet directly — it uses the same liquidity pool mechanics that let a small trade move a thin pool's price against you, purely by acting on public, visible information faster than you can.
Why Larger Trades on Thinner Pools Are Targeted More
The profit available from a sandwich attack scales with how much a trade moves the price — a large trade on a low-liquidity pool creates more room for the attacker to extract value than a small trade on a deep, well-established pool.
What Slippage Tolerance Has to Do With This
Your slippage tolerance setting — how much price movement you're willing to accept before a trade fails — directly caps how much a sandwich attack can extract from you. A high slippage tolerance gives an attacker more room to work with before your transaction would fail instead of executing at a worse price.
What Reduces Exposure to This
Setting a tighter slippage tolerance, trading during lower-volatility periods when bots have less incentive to target routine trades, and using a private transaction relay that doesn't expose your trade to the public mempool before it confirms are the main practical mitigations available.
Check a token's liquidity depth before trading — thinner pools make sandwich attacks more profitable for whoever's watching.