Featured

What Is a Sandwich Attack? How Bots Take a Cut of Your Memecoin Trade

Mark Arguinbaev

Founder

A sandwich attack: a bot buys $2,500 before your $5,000 buy and sells right after for a $485 profit

A sandwich attack is three trades in a row, and yours is the one in the middle. A bot buys just before you, your buy fills at a worse price, and the bot sells right after. The bot keeps the difference, and it comes out of your trade. This guide follows What Is Slippage? and uses the same pool, so you can see exactly how much a bot can take and what decides that number.

For the full video explanation, check out this YouTube video:

The Pool We Are Using

The same simple pool as in the slippage guide:

  • $50,000 of ETH on one side
  • 500 million tokens on the other
  • Price on screen: $0.0001 a token

You send in a buy for $5,000. Your quote is about 45.45 million tokens. (It is not 50 million, because your own buy moves the price. That part is price impact, covered in the slippage guide.)

Your Trade Waits Where Bots Can Read It

On Ethereum, a trade does not land the moment you press the button. It first waits in a public queue called the mempool, until it is put into a block. Anyone can read that queue, and bots read it all day.

A waiting trade shows two things a bot cares about:

  • Its size: a $5,000 buy.
  • Your slippage setting: the trade carries a minimum number of tokens. If it would return fewer, it fails.

Say you set slippage to 10%. Your minimum is then about 40.9 million tokens. That tells the bot how far it can push the price before your trade stops going through.

The Sandwich, Step by Step

StepTradePool price after
1The bot buys $2,500 of the coin, right ahead of you$0.00011
2Your $5,000 buy lands at that higher price$0.000132
3The bot sells its tokens right after you$0.000119

What each side ends up with:

Result
Your quote45,454,545 tokens
What you get41,407,867 tokens
Fewer than your quote4,046,678 tokens (about 9%)
The bot pays in step 1$2,500
The bot gets back in step 3about $2,985
The bot's profit, before feesabout $485

You got about 41.4 million tokens. That is still above your 40.9 million minimum, so your trade went through and nothing looked broken. You simply got 4 million tokens fewer than you were quoted.

Why the Bot Takes Almost No Risk

The bot does not hope its trades land in the right order. It sends all three as one package to the people who build blocks, and pays them to place the trades in exactly that order: its buy, your buy, its sell. If the package does not work out, it is not included.

So the bot only holds the coin for a moment, and its profit is known before anything lands. That profit came out of your fill.

Defense 1: A Tight Slippage Setting

The slippage setting decides how much room the bot has. Same pool, same $5,000 buy:

Your settingYour minimumMost the bot can buy firstBot's profit, before fees
10%40,909,091 tokensabout $2,834about $545
5%43,181,818 tokensabout $1,361about $274
1%45,000,000 tokensabout $264about $55

At 1%, the bot can only buy about $264 ahead of you. Any more and your trade would return less than your minimum and fail, and the bot's plan fails with it. Its profit drops to about $55, and it still has to pay network fees, swap fees and the payment to the block builder. A tight setting makes you not worth the trouble.

The trade-off: on a coin whose price is moving fast, a tight setting means your trade fails more often. Raise it a little at a time, not straight to a huge number.

Defense 2: A Smaller Buy, or a Deeper Pool

A sandwich works because your buy moves the price. A smaller buy, or the same buy in a deeper pool, moves the price less, so there is less for the bot to sell into. Splitting a large buy into smaller ones helps for the same reason.

Defense 3: A Private Route

Some wallets and apps can send your trade privately, straight to the block builders, so it never sits in the public queue where bots can read it. The setting is usually called MEV protection. (MEV stands for "maximal extractable value", the name for profit made by choosing the order of trades. A sandwich is one kind of MEV.)

If your wallet has it, turn it on. It does not replace a tight slippage setting; use both.

What This Guide Does Not Cover

The numbers ignore swap fees and network fees, which make the bot's real profit smaller and your fill slightly smaller too. The example bot buys $2,500; the most a 10% setting allows here is about $2,834.

Chains differ. This guide describes Ethereum's public mempool. Some chains have no public mempool, and trades there can still be sandwiched by whoever orders the transactions. The defenses are the same: tight setting, smaller trades, and a protected route where the wallet offers one.

Tokens that charge a tax on each buy or sell need a wider slippage setting to trade at all, which also leaves more room for a sandwich.

The numbers are a worked example, not market data.

Key Takeaways

  • A sandwich is three trades: a bot buys before you, you fill at a worse price, the bot sells right after.
  • Bots can read your waiting trade, including its size and its slippage setting.
  • Your slippage setting is not just a safety net. It is the most a bot can take from you.
  • Keep the setting tight, keep buys small next to the pool, and use MEV protection if your wallet has it.

This article is for education only and is not financial advice.

Enjoyed this article?

Discover more insights and analysis

← More ArticlesJoin our Telegram