MEV Sandwich Attacks: How Your Trade Gets Trapped and How to Protect It
MEV is additional profit extracted by those arranging transactions in a block. This guide explains how a common form, the sandwich attack, harms ordinary users and how beginners can reduce their exposure.
What Is MEV?
Maximal Extractable Value (MEV) is extra profit that block producers, such as miners, validators, or connected bots, extract by reordering, inserting, or excluding transactions within a block. It was previously called miner extractable value; following the move to Proof of Stake (PoS), the term broadened to include validators.
The key is that a transaction sent to a blockchain is not executed immediately. It first sits publicly in a queue called the mempool. Anyone can inspect pending transactions. Bots use that information to insert their own trades before or after yours and profit.
Front-Running and Sandwich Attacks
Front-running means placing a trade in the same direction immediately before someone else's trade executes. Knowing that a large buy will raise the price, a bot pays a higher gas fee to put its own buy first.
A sandwich attack takes this further by surrounding the victim's trade. The bot's transactions are the slices of bread, and your transaction is the filling between them.
- ① First trade — buy: The bot buys the same coin just before your purchase, nudging its price upward.
- ② Your trade: You buy at the more expensive price created by the bot.
- ③ Last trade — sell: The bot immediately sells at the higher price and takes the difference.
You plan to swap $1,000 of coins on a decentralized exchange. A bot sees the transaction in the mempool and buys first, raising the price by 1%. Your trade executes at that higher price, and the bot sells afterward for a profit. You receive fewer coins, and the difference becomes the bot's gain.
How Ordinary Users Lose Money
The direct loss appears as slippage, the difference between the expected and actual execution price. Because the bot artificially moves the price before your transaction, you buy or sell at a worse price.
| Situation | Expected Result | With a Sandwich Attack |
|---|---|---|
| $1,000 swap | Receive 100 coins | Receive 98–99 coins |
| Execution price | Current market price | Higher price pushed up by the bot |
| Where the difference goes | No difference | To the bot and validator |
One loss may seem small, but larger trades and thinner liquidity increase the damage. Low-liquidity altcoins can move sharply with relatively little money, making them easier targets.
Slippage Protection and Practical Defenses
There is no perfect defense, but practical measures can reduce losses.
- Set a low slippage tolerance: A tolerance such as 0.1–0.5% cancels a transaction when the price becomes worse by more than that amount. Too low a setting can also fail ordinary transactions.
- Split large trades: A large order creates greater price impact and an attractive target. Splitting it reduces impact and exposure.
- Use pools with adequate liquidity: Deeper, actively traded pools move less for the same trade size, reducing the attacker's potential profit.
- Use private transactions: Some wallets and services submit transactions without exposing them in the public mempool, making advance inspection harder for bots.
MEV and sandwich attacks arise structurally from blockchain's transparent transaction system, so eliminating them completely is difficult. Focus on controlling your own loss exposure through slippage limits and trade sizing rather than trying to beat every bot.
This article is informational and is not investment advice. Crypto trading can lose principal, and no protection prevents losses 100% of the time. Understand the process before trading and use only amounts you can afford to lose.
NOONOO TRADING invites you to follow live trading in our free chat.
Start in the bot📈 OKX trading fee discount for new registrations
Register for the OKX Fee Discount →