Skip to main content
Merkle Street

Protocols, markets, policy, people

How to tell if my swap was sandwich attacked: spot the pattern

How to tell if my swap was sandwich attacked: find the same bot buying just before your swap and selling just after it in the same block and pool.

Merkle Street Newsroom#a7508d3 min read

How to tell if my swap was sandwich attacked: spot the pattern

A sandwich attack is likely when one address buys the token you want just before your swap, then sells it just after, in the same block and pool. On Etherscan, compare the transactions immediately around yours and check whether your fill landed close to your minimum received.

  • The buy appears at the transaction index just before yours.
  • The sell appears at the index just after yours.
  • Both trades use the same pool and usually the same bot contract.

What does a sandwich attack look like in a block?

A sandwich attack puts the attacker’s buy and sell on either side of your swap in the block’s transaction order. A bot sees your pending transaction in Ethereum’s public mempool, buys the token first, lets your swap execute, then sells after it.

That first buy pushes the token price up in the pool. Your swap then trades at a worse price, and the bot sells into the price movement your trade helped create. Think of it as someone stepping into the queue ahead of you, changing the price, then selling after you accept it.

Sandwiching is a form of MEV: value gained by influencing how transactions are ordered or executed. The paper “Flash Boys 2.0” by Daian and co-authors (2019) describes front-running and sandwich mechanics in decentralized exchanges. In practice, the visible clue is a buy, your swap, and a sell, ordered together in one block.

How can I check my swap on Etherscan?

Etherscan shows the block and transaction index you need to inspect. Paste your transaction hash into Etherscan, open the transaction, note its block, and open that block’s transaction list.

When checking a Matcha swap, confirm the transaction’s network first. Matcha swap is a decentralized exchange aggregator that routes token exchanges across liquidity sources; use matcha supported chains to verify that Ethereum is among the supported networks.

Find your transaction in the block and compare the entries at index minus one and index plus one. Transactions in a block have an ordered index, so these entries show what executed immediately before and after your swap. Open each neighboring transaction and inspect its token transfers or swap details to identify the pool and the direction of the trade.

The pattern to look for is a buy of the token you received immediately before your swap, followed by your swap, then a sale of that token immediately after. Compare the pool addresses as well as the tokens: the attacker’s two trades should use the same pool as yours. If both neighboring trades also come from one address or bot contract, that strengthens the match.

Then compare your execution with the minimum received shown in your swap details. A fill close to that minimum, alongside the same-pool buy and sell bracketing your transaction, is strong evidence that the swap was sandwiched. The attacker’s buy raises the price before your trade; the sale after it captures value from the resulting move, while your transaction can be pushed down to its slippage limit.

If the bracket appears, you have a concrete pattern to report or investigate: the block, the three transaction indexes, the pool, and the bot address. If you want to reduce exposure on a future swap, Flashbots Protect documentation describes private transaction submission that keeps swaps out of the public mempool, where bots can watch pending transactions.

The deciding evidence is the ordered pair of same-pool trades around your swap, especially when the fill is near your minimum received. That block pattern lets you confirm whether the bad fill fits a sandwich attack.