← GlossaryTrading & DeFi
What Is a Sandwich Attack? How Bots Profit From Your Swap
A sandwich attack is a form of MEV in which a bot places one trade just before and one just after a victim's pending swap, profiting from the price movement the victim's trade causes and leaving the victim with a worse price.
Key takeaways
- The bot sees your pending swap in the mempool and trades around it.
- It buys first, pushing the price up, then sells after your trade executes.
- Your outcome is a worse price, up to the slippage limit you allowed.
- Lower slippage limits, smaller trades and deeper pools reduce the profit available.
How it works
When you submit a swap on a decentralised exchange, it waits in a public queue before being included in a block. A searcher bot watches that queue for large trades. ethereum.org describes sandwich trading as a searcher placing a profitable buy order before a large trade and a sell order after it, profiting from the price movement the large order causes.
Step by step
First, the bot sees your pending swap and calculates that it will move the pool's price. It sends its own buy of the same token with a higher fee so that it executes just before yours. That pushes the price up, so your swap executes at a worse rate. Then the bot sells straight after your trade, locking in the profit. The three transactions are placed together in the order bot, you, bot.
Why the slippage setting matters
Your slippage tolerance tells the exchange how much worse a price than quoted you will accept. A bot can only push the price as far as that limit allows before your transaction fails. A very loose limit invites a bigger sandwich. A tight limit means you might fail more often but lose less when attacked.
How to reduce your exposure
Keep slippage as low as the market allows, trade in deeper pools where the same size moves the price less and split large trades into smaller ones. Where available, use routing that hides your transaction from the public queue until it is included. Be especially careful with thinly traded tokens, where one trade moves the price a lot and where a bot has the most to gain.
Example
You swap 10 ETH for a token in a small pool with 5% slippage allowed. A bot buys first, raising the price by 3%, your swap executes at that worse price, and the bot sells afterwards. You received about 3% less than the quote, and the bot kept it.
Put it into practice
Check price impact before you swap
Scrypt Wallet's swap form shows price impact before you confirm. If it looks high for a small pool, reduce the size or choose a deeper market.
Create a free wallet Get Scrypt for AndroidFrequently asked questions
Can I tell if I was sandwiched?
A block explorer shows transactions around yours in the same block. Two trades from the same address on either side are the sign.
Does it only happen on Ethereum?
Similar attacks occur on other chains with public transaction queues.
Does low slippage fully protect me?
It limits the loss but cannot remove the risk, and it may make your trade fail.
Written by the Scrypt Wallet team · Updated 2026-10-02. General education, not financial, tax or legal advice.