MEV and sandwich attacks explained

Risk & safety·6 min read·Updated August 14, 2026

Every time you swap on a DEX, your transaction sits publicly in the mempool before it is mined. Sophisticated bots watch that queue and profit by reordering, inserting or censoring transactions — a practice known as MEV (Maximal Extractable Value). The most common form that hits ordinary traders is the sandwich attack.

What MEV actually is

MEV is the profit a block builder or bot can extract by choosing the order of transactions in a block, beyond the standard gas fees and rewards. Because Ethereum transactions are public before confirmation, anyone can see a pending swap and act on it first. MEV is not a bug — it is an emergent consequence of transparent, ordered blockchains.

How a sandwich attack works

A bot spots your large buy in the mempool. It buys the same token first (pushing the price up), lets your trade execute at the now-worse price, then immediately sells into the bump you created. You get a poor fill; the bot pockets the difference. It exploits exactly the price impact your trade causes.

  • Front-run: bot buys just before you, raising your entry price.
  • Your trade: executes at the inflated price, moving it further.
  • Back-run: bot sells into your impact for a near-riskless profit.

How to protect your trades

You cannot stop bots from watching the mempool, but you can make yourself a poor target. The defences all reduce how much a bot can extract from your specific transaction.

  • Set a tight slippage tolerance so a sandwich cannot fill you at a much worse price.
  • Trade in deep pools where your price impact — the bot’s profit source — is small.
  • Use a private RPC or MEV-protected transaction relay to keep your swap out of the public mempool.
  • Split very large orders so no single transaction is worth attacking.

Reading depth to avoid it

The deeper the relevant liquidity, the less your trade moves the price and the less there is to extract. CoinVerum’s token pages show associated pool TVL and a scoped V2 estimate; use a live router quote to size an actual trade — see reading on-chain liquidity.

Frequently asked questions

Is MEV illegal?

No. MEV is an inherent property of public, ordered blockchains and is extracted by permissionless bots and builders. It is a market-structure issue, not a legal one, though the ecosystem is actively building tools to mitigate its harms.

How do I know if I was sandwiched?

If your executed price was noticeably worse than the quote for no obvious market reason, and you see a buy immediately before and a sell immediately after your transaction in the same block, you were likely sandwiched.

Does a lower slippage tolerance stop sandwich attacks?

It limits them. A tight tolerance caps how far your fill can move, shrinking the bot’s profit — sometimes enough that the attack is no longer worthwhile. It can also cause your swap to revert in fast-moving markets.

Keep reading & explore the data