What is a sandwich attack (MEV), and how do you avoid it?
You swap $1,000 of ETH for USDC and receive a little less than the quote said. Often that's no accident. Bots watch for swaps like yours and squeeze value out of them. This is called a sandwich attack, one form of MEV.
How a sandwich attack works
- You send a swap. Before it is included in a block, it waits in a public queue where anyone can see it.
- A bot sees your swap and the slippage you allowed, for example “up to 1% worse than quoted”.
- The bot buys the same token just before you, pushing the price up.
- Your swap goes through at that worse price, still inside your slippage limit, so it doesn't fail.
- The bot sells right after you and keeps the difference.
Your trade is the filling in the bot's sandwich. You paid more, and the bot earned exactly what you lost.
What MEV means
MEV stands for “maximal extractable value”: profit someone can make by choosing the order of transactions in a block. Sandwich attacks are the kind that hurt ordinary traders most directly.
How to tell if it happened to you
- You received noticeably less than the quote, close to your slippage limit.
- On a block explorer, your swap sits between two trades of the same token by the same address, one just before and one just after.
How to avoid it
- Keep slippage low. The more slippage you allow, the more a bot can take. Only raise it when a swap keeps failing.
- Avoid tiny, illiquid pools for large amounts. Thin markets are easier to push around.
- Use a swap that doesn't put your trade in the public queue. This is the strongest protection.
Bonus: matched trades
When two people in the same batch want opposite trades (one sells ETH for USDC, another buys ETH with USDC), CoW Protocol can match them directly. That's called a “coincidence of wants”, and it skips the pool and its fees entirely for the matched part.
Open the swap pageNothing here is financial advice. Crypto transactions cannot be reversed.