MEV Bots and Sandwich Attacks in Crypto

MEV bots exploit public mempool transaction order to sandwich your DEX trade, buying before you and selling after

BASICS4 min readBy AlgoSys Editorial TeamPublished Apr 25, 2026Updated Jun 24, 2026
Contents

In public blockchains, transactions are collected into blocks, and the miner or validator decides which ones to include and in what order. This very right to choose the sequence creates a loophole: specialized programs monitor pending transactions and earn money by placing their own trades in the right places within the block.

Such programs are usually called MEV bots (from Maximal Extractable Value). They extract profit from the network itself by influencing the order of transactions within a block. An ordinary user encounters them not directly, but through their consequences: unexpected price slippage during a trade on a DEX or increased gas fees.

Understanding MEV is useful for anyone trading through decentralized applications because it directly impacts the efficiency and fairness of a trade. The topic well illustrates how even the basic mechanics of a blockchain can be turned into a source of income by experienced participants.

KEY CONCEPTS

MEV bots are automated programs that maximize profit by playing on the transaction order in the blockchain. To make further analysis easier, let's agree on the terms.

Maximal Extractable Value (MEV): the profit a block producer receives by including, excluding, or reordering transactions within a block.

Transaction Pool (mempool): a "waiting room" for unconfirmed transactions until they are included in a block.

Block Producer: a miner or validator who assembles new blocks in a Proof-of-Work or Proof-of-Stake network.

Smart Contract: a self-executing contract with terms written directly into the code; MEV bots actively use them.

DEX (Decentralized Exchange): a platform where cryptocurrencies are traded directly from a wallet, without intermediaries.

Slippage: the difference between the expected trade price and the price at which it was actually executed, usually due to the price moving during execution.

Front-running: a bot notices another user's pending transaction and pushes its own transaction with a higher gas fee to get into the block earlier and profit from the price movement.

Back-running: a bot places its transaction immediately after a detected one to capture profit from its consequences.

HOW IT WORKS

An MEV bot continuously scans the mempool for profitable opportunities. As soon as it notices a large pending transaction (e.g., a big buy order on a DEX), it acts lightning-fast: it places its own buy order right before the other user's transaction and a sell order immediately after it.

This combination is called a sandwich attack. The bot's purchase slightly pushes the price up, and the user's large purchase pushes it even higher. Then, the bot sells at the higher price what it bought earlier and pockets the difference. The user's transaction ends up literally squeezed between the bot's two trades, hence the name.

To guarantee priority for its transactions with the block producer, bots often pay increased gas fees. This allows the entire scheme to be included in the same block as the victim's trade and extract maximum value from them. Profit is generated from the price shift created by these carefully placed trades.

EXAMPLES OF USE

To make it clearer, let's break down a sandwich attack with hypothetical numbers. A user wants to buy a token at a price of 100, sends a large order, and sees it in the mempool. The events then unfold as follows:

  1. The bot notices the order and buys the token first at 100, slightly raising the price to 101.
  2. The user's purchase executes, and the large volume pushes the price to 103.
  3. The bot immediately sells at 103 what it bought at 101, pocketing a profit of 2 per unit.

The user ultimately bought at a higher price than expected, and this is exactly the slippage they see in the trade report. Most often, people encounter this outcome on DEXs: they received fewer tokens than expected because the bot managed to execute a sandwich attack.

A second typical scenario is arbitrage. MEV bots instantly find price discrepancies between different DEXs or between trading pairs on the same platform and execute trades to capture this small difference before normal market activity smooths it out.

Gas fees also indirectly increase. Bots willing to pay higher fees for priority drive up the average gas prices for everyone in the mempool, which is particularly noticeable during periods of high network congestion.

To keep track of who profits from what, it's useful to summarize the two main tactics in a table.

Tactic What the Bot Does Source of Profit
Sandwich Attack Buys before a user's order and sells after it Price shift created by the victim's large trade
Arbitrage Exploits price discrepancies between DEXs or pairs The difference in quotes before the market smooths it out

FREQUENTLY ASKED QUESTIONS

MEV bots operate on many blockchains with a public mempool, including Ethereum. Their complexity and the amount of value extracted depend on network activity and the block production mechanism. The topic is not simple, but even understanding that MEV exists helps in anticipating potential slippage on DEXs.

Users cannot completely ban MEV bots because it is an inherent property of public blockchains. However, the consequences can be mitigated: use DEX aggregators that route trades more intelligently, trade during periods of low network activity, be mindful of potential slippage, and if necessary, break down large trades into smaller parts.

MEV appears to be an unfair advantage, but it also has a flip side: bots quickly close arbitrage discrepancies, thereby supporting market efficiency. Some blockchain research is aimed at making MEV more transparent or distributing its benefits more widely among network participants.

FAQ

What is MEV in simple terms?

MEV (Maximal Extractable Value) is the profit that a block producer or a related bot earns by deciding which transactions to include in a block and in what order. The very right to set the order of trades becomes the source of income.

How does a sandwich attack work?

A bot notices a large user order in the mempool, places its own buy order right before it, and its sell order immediately after. The user's trade moves the price up, and the bot sells at a higher price than it bought. The user's transaction ends up sandwiched between the bot's two trades, hence the name.

Why do I lose on slippage when trading on a DEX?

Often, the reason is precisely a sandwich attack: a bot managed to buy the token before you and drove up the price, so your order was executed at a higher price than expected, and you received fewer tokens. The slippage in the trade report shows exactly this difference.

Can I protect myself from MEV bots?

It's impossible to completely ban them; it's an inherent property of public blockchains. However, the consequences can be mitigated: use DEX aggregators with smart routing, trade during periods of low network load, account for potential slippage, and if necessary, break down large trades into smaller parts.

On which blockchains do MEV bots occur?

Anywhere there is a public mempool of unconfirmed transactions, including Ethereum. The extent to which bots are active and how much value they extract depends on network load and the block production mechanism.

Is MEV only harmful, or is there any benefit?

From the outside, it looks like an unfair advantage, but MEV also has a useful function: bots quickly close price arbitrage discrepancies between platforms, thereby maintaining market efficiency. Some research aims to make MEV more transparent and distribute its benefits more widely.

Put this to work in the terminal

Live charts, derivatives, on-chain and macro data, free.

Open terminal →