DeFi Safety
What is Sandwich attack?
A type of front-running where a bot buys before your trade and sells after it, profiting from the price move your own trade causes.
How it works
Your pending swap is visible in the mempool. A bot places one trade just before yours (pushing the price up) and one just after (selling into it), skimming value at your expense. Tight slippage tolerance and private routes reduce it.
Example
In practiceYou swap a large amount; a bot sees it pending, buys first, then dumps right after your fill at your cost.
How do I avoid sandwich attacks?
Lower slippage tolerance, split large trades, or use a MEV-protected / private transaction route.
Go deeper: DeFi From Scratch
The complete, step-by-step guide — every command, config, and the reasoning behind it.
Get the guide