Barrigaz Blog
All posts

Trading bots: MEV explained

Danil Vahidov
Danil Vahidov CTO & Co-founder
·
· 3 min read
Trading bots: MEV explained

What is MEV?

Maximal Extractable Value (MEV) refers to the extra profit that miners, validators, or specialized bots can earn by manipulating the order of transactions within a block. MEV typically occurs in DeFi ecosystems, where transactions rely on smart contracts for trading, liquidations, and arbitrage.

MEV exists because some transactions are sensitive to the order in which they are executed. By reordering, delaying, or front-running transactions, an entity with control over transaction sequencing can extract additional value.

Let’s break down how transaction processing works on EVM-compatible blockchains like Ethereum.

When a user submits a transaction, it doesn’t get confirmed instantly. Instead, it goes through several steps:

  • The transaction is validated by a blockchain node.
  • The node then broadcasts it to other nodes in the network.
  • The transaction is stored in the mempool — a temporary storage (like a queue) where all pending transactions wait before being included in a block.
  • Block builders and validators select which transactions will be included in the next block, usually prioritizing those that pay the highest gas fees.

Since transactions sit in the mempool before being confirmed, they are visible to everyone — including trading bots looking for profitable opportunities.


Miner Extractable Value → Maximal Extractable Value

The term “Miner Extractable Value” was originally used because, in proof-of-work blockchains, miners had the power to decide which transactions to include and in what order.

However, with Ethereum’s transition to proof-of-stake, the term evolved into Maximal Extractable Value. Today, MEV is no longer just about miners — it involves validators, block builders, and advanced trading bots.


Why do bots fight for priority?

Let’s say a user submits a transaction that creates an arbitrage opportunity, and this transaction is now sitting in the mempool.

At the same time, I — a highly specialized bot — am continuously scanning the mempool for opportunities. Once I detect this transaction, I can submit my own transactions before or after it, capturing the arbitrage profit for myself by offering higher gas fees or direct payments, ensuring my transaction gets executed in the right order.

If I am fast enough, smart enough, and willing to pay enough, I can control the order of transactions within a block and extract MEV profit.

However, I’m not the only one doing this — hundreds of trading bots are competing for the same opportunities. This competition often results in gas wars, where bots bid excessively high fees, sometimes paying nearly all their profit as a priority fee to miners or validators just to secure execution.

On the other hand, miners and validators also benefit from MEV. By choosing which transactions to include and in what order, they can execute their own strategies or sell priority access to the highest bidder.

Danil Vahidov
Danil Vahidov CTO & Co-founder

Software architect passionate about distributed systems and automation. Leads product and infrastructure at Barrigaz.