Home › Profit, Risk & Law › How to Protect Yourself From Sandwich Attacks in Crypto
How to Protect Yourself From Sandwich Attacks in Crypto
To protect yourself from sandwich attacks, keep slippage tight, avoid large swaps in thin pools, split big orders, and send trades through a private route where your chain and wallet support one. None of these removes the risk completely, but together they shrink what a bot can take.
How the attack works
On chains with a public mempool, your pending swap is visible before it is confirmed. A bot sees it, estimates how much it will move the pool’s price, and builds a pair of trades around yours:
- The front leg buys the same token just before you, pushing the price up.
- Your swap executes at that worse price.
- The back leg sells right after, taking the difference.
The profit is paid for by your worse execution. The ethereum.org MEV page describes this class of strategy among the ways transaction ordering is monetised.
The bot has to pay fees on both legs, and it only proceeds when the expected profit exceeds them. CryptoMEV Bot’s sandwich bot page describes exactly that logic from the attacker’s side: it simulates profit against the gas cost of both transactions and proceeds only if it looks profitable. That is a useful way to think about defence too: your goal is to make your trade unprofitable to target.
What makes a swap an attractive target
| Factor | Why it attracts bots | What you can do |
|---|---|---|
| Large size relative to pool | Bigger price impact, bigger profit | Split the order; use deeper pools |
| High slippage tolerance | More room to push the price | Tighten the cap |
| Public mempool visibility | Bots can see it | Use a private route |
| Thin liquidity | Small trades move price a lot | Prefer deeper liquidity |
| Popular new token | Many bots watching | Be extra cautious on launches |
Key takeaway: a sandwich bot needs two things from you: a visible trade and room to move the price. Remove either and the attack gets harder or unprofitable.
Defences, in order of usefulness
1. Tight slippage
The slippage cap defines how far the price can move before your trade reverts. A tight cap leaves less for a bot to take, though it can cause failed trades. Our guide to sniping bot slippage settings explains the trade-off.
2. Smaller or split orders
Price impact scales with size relative to liquidity. Splitting an order into smaller pieces, or choosing deeper pools, reduces how much a bot can profit per sandwich. This does cost extra fees, so weigh the two.
3. Private transaction routes
If your transaction is never broadcast to the public mempool, a bot cannot see it in time. Services such as Flashbots Protect on Ethereum are designed for this. Their documentation explains how the service works and its limits; check it for the current behaviour. Some wallets and aggregators offer private routing or built-in protection. Support differs by chain and changes, so check each tool’s current documentation.
On Solana the architecture differs from Ethereum’s public mempool, and tools such as bundle submission change what is visible; see Jito bundles and sniping. Still, slippage discipline matters there too.
4. Choose venues and routes carefully
Some aggregators and DEX interfaces include protections or let you choose routing. Read what they say, and do not assume protection is on by default.
5. Avoid the busiest moments for new tokens
Newly launched tokens attract the most bots. If you are buying one, assume you are being watched and size accordingly.
How to check whether you were sandwiched
- Open your transaction in a block explorer.
- Look at transactions immediately before and after yours in the same block.
- A pattern of one address buying before you and selling after you, with a poor price for you, is the signature.
- Compare your executed price with the quote you saw.
Tools and dashboards that label such events exist, but we have not verified any specific one and so do not recommend one here. A block explorer is enough to inspect the pattern yourself.
If you run bots yourself
Many people reading about sandwiching also run sniping tools. Two honest points apply:
- Your own buys are potential targets. Loose slippage on a launch is an invitation.
- Running a sandwich strategy yourself takes value from other users and carries higher legal and reputational risk. We explain why in front running bot crypto and is a crypto sniping bot legal. The vendor page above notes that failed attacks can lose gas and the trade itself, and it says little about the effect on the users who are sandwiched.
A short checklist before you swap
- Is the pool deep enough for my size?
- Have I set the tightest slippage that still works?
- Is a private route available and enabled?
- Could I split this order?
- Do I understand what happens if the trade fails and costs me fees?
Protections change as services and chains evolve. Check current documentation for your wallet and network, and only trade what you can afford to lose.
Why this matters to the whole ecosystem
Sandwiching is a tax paid by ordinary swappers, and it is one reason private routing and protection tools exist. The vendor’s blog explainer on what an MEV bot is itself describes sandwich attacks as a kind of tax on users, even while the same site sells a sandwich bot. Whether you view that as candour or contradiction, it supports the point that the cost lands on someone, and that you can reduce your share.
When you cannot avoid exposure
Sometimes you must trade a thin token on a public route. In that case, minimise the damage: use the smallest size that serves your purpose, accept that failed trades are better than bad fills, and avoid broadcasting at moments of intense activity. Consider whether the position is worth the likely cost. If a product claims it can help you capture value in this space rather than defend against it, such as the front-run bot described by CryptoMEV Bot, remember that you would be moving from the victim side to the extractor side, with the legal and ethical questions that follow.
Frequently asked questions
What is a sandwich attack?
A bot places one trade before your swap and another after it, profiting from the price movement your swap causes. You receive a worse price.
How can I avoid being sandwiched?
Use tight slippage, split large swaps, avoid thin pools and use a private transaction route where your wallet or chain supports one.
How do I know if I was sandwiched?
Look at the transactions just before and after yours in the same block. A buy before and a sell after, from one address, around a poor fill is the typical pattern.
Do private RPCs fully prevent sandwiching?
They reduce exposure on public-mempool chains but do not guarantee protection. Details depend on the service and the chain.
Sources
- ethereum.org – Maximal extractable value (MEV) – https://ethereum.org/en/developers/docs/mev/
- Flashbots – Protect overview – https://docs.flashbots.net/flashbots-protect/overview