Module 4 · Lesson 27 of 45

MEV, front-running & sandwich attacks

⏱ 7 min read ● Advanced Module 4 · Advanced concepts

The moment you submit a trade, it's usually visible to everyone before it settles. Specialized bots read that public queue and profit from it — a phenomenon called MEV. Knowing how it works lets you avoid being the easy target.

What MEV is

Maximal Extractable Value is the profit bots (and validators) can extract by choosing the order of transactions in a block. Because pending transactions sit publicly in the mempool, a bot can see your trade coming and arrange its own around it.

The sandwich attack

The most common form against ordinary traders has three steps:

  1. Front-run — the bot sees your buy and buys the same token just before you, pushing the price up.
  2. Your trade fills at that worse, inflated price.
  3. Back-run — the bot immediately sells into the price your trade created, pocketing the difference.

You got a worse fill; the bot earned the gap. Crucially, the more slippage tolerance you set, the more room the bot has to inflate the price — which is exactly why over-high tolerance is dangerous (Lesson 19).

How to protect yourself

  • Keep slippage tight — only as high as the pair truly needs. The simplest and biggest defense.
  • Use a private / MEV-protected route — endpoints that send your transaction privately to a block builder, so it never sits in the public mempool. Some wallets and DEXes offer this by default.
  • Split very large orders so no single trade is a juicy target.
  • Use an aggregator — many route through private flow or split orders to reduce exposure.

Keep it in perspective

For small swaps on liquid pairs with sensible slippage, MEV is usually negligible. It matters most on large trades, thin tokens, and when tolerance is carelessly high. Tight slippage plus a protected route handles the vast majority of the risk.

Key terms
MEVMaximal Extractable Value — profit from ordering transactions in a block.
MempoolThe public waiting room of pending transactions bots can read.
Front-runningPlacing a trade just ahead of yours to profit from the move it causes.
Sandwich attackFront-running and back-running your trade to capture the spread.
!Common mistakes
  • Setting a high slippage tolerance, handing sandwich bots the room they need.
  • Sending a very large trade through the public mempool with no protection.
  • Assuming MEV is only a 'whale' problem and ignoring slippage discipline.
Finished reading? Track your progress through the journey.