01

Who is trading just before and after you?

After a large swap on a decentralized exchange returns less than expected, a block explorer sometimes shows a trade in the same token immediately before yours and another immediately after. That is often not a coincidence but a form of maximal extractable value (MEV), profit drawn from the ordering of transactions.

This guide explains why ordering within a block creates value and how that value becomes a cost to users, with a hypothetical calculation. It also covers what protection features do and do not prevent, and what to check before trading.

02

Value created by ordering

Ethereum.org defines MEV as the value that can be extracted from block production in excess of the standard block reward and fees, by including, excluding, or reordering transactions. Participants who look for these opportunities are called searchers, and they run automated programs that analyze pending transactions.

Not all MEV is harmful. Arbitrage that aligns prices across exchanges and liquidations that close undercollateralized loans on time help markets function. The problem is the kind that uses a particular user's trade to that user's detriment.

03

How block order is decided

Most Ethereum transactions wait in the public mempool before being included in a block. Since the move to proof of stake, a structure that separates block builders from block proposers has become widespread, and builders try to arrange transactions in the most profitable order.

Transactions that pay higher priority fees, or pay builders directly, can therefore claim earlier positions. The visibility of pending transactions provides transparency but also gives others the chance to act on your trade before it executes.

04

A hypothetical sandwich in a shallow pool

Ethereum.org describes sandwich trading as a common MEV method: a searcher spots a large pending swap, buys ahead of it to push the price up, and sells right after it executes. Below, a user buys ETH with 30,000 USDC from a hypothetical pool holding 100 ETH and 300,000 USDC (fees excluded).

A sandwich attack compared with no attack (hypothetical, before fees and gas)
StepTradeResult
No attackUser buys with 30,000 USDCUser receives ≈ 9.091 ETH
1. Front-runAttacker buys with 7,000 USDCAttacker receives ≈ 2.280 ETH; price rises
2. User's tradeUser buys with 30,000 USDCUser receives ≈ 8.699 ETH (-4.3%)
3. Back-runAttacker sells 2.280 ETHAttacker receives ≈ 8,416 USDC
Attacker's result-≈ +1,416 USDC before gas and fees

Because the user's slippage tolerance was 5%, a fill 4.3% worse still went through. The tolerance sets the ceiling on what can be extracted.

05

The cost passed to users

In the example, the user received about 0.39 ETH less, most of which became the attacker's profit. Because the result was within the user's slippage setting and the trade did not fail, the user may never realize it happened.

These costs grow with shallower pools, larger trades, and wider slippage tolerances. Uniswap's documentation asks traders to consider price impact and slippage separately for exactly this reason: the tolerance becomes the maximum someone else can take.

06

Limits of protection features

Some wallets and services offer private transaction submission, sending trades directly to builders rather than to the public mempool. This can reduce sandwich risk, but it requires trusting the recipient, and inclusion can be slower or fail.

Protection does not remove price impact. A large trade in a shallow pool still fills at a poor price with no attacker involved. Protection features do not replace the basic habits of keeping slippage tolerance tight and splitting large trades.

07

Before you trade

Work through these steps before a large swap on a DEX.

  1. Compare your trade size with the pool's total liquidity to gauge price impact, and split the trade if impact is high.
  2. Set slippage tolerance yourself, no wider than necessary.
  3. Check whether your wallet or service offers private submission or MEV protection, and read how it works and its limits.
  4. After the trade, look in a block explorer for transactions in the same pool immediately before and after yours.
  5. If you trade large amounts regularly, consider deeper markets or limit-style orders.
08

The questions MEV leaves

MEV is a structural result of how blockchains order transactions, so individuals cannot avoid it entirely. Protocol-level changes continue to be discussed, but for users, habits that limit exposure are the most practical defense.

The calculation above uses a hypothetical pool and excludes fees. When trading, check the service's current documentation and interface with their revision dates in mind, and decide your own tolerance and trade size.