Best ways to avoid sandwich attacks on Uniswap: three steps
The best ways to avoid sandwich attacks on Uniswap are private RPC routing, tight slippage and UniswapX for larger swaps, where size and pool depth matter.
iCrypto Editorial5 min read
To avoid sandwich attacks on Uniswap, send swaps through a private RPC first, set slippage tolerance as low as your trade allows, and use UniswapX for larger swaps. A sandwich attack puts a bot’s buy before your swap and its sell after it in the same block; hiding the pending swap and limiting the price room can make the attack harder or less profitable.
Start with the swap’s size compared with the pool’s liquidity. A small trade in a deep pool is rarely worth a bot’s effort, while a large trade in a thin pool can move the price enough to attract one. If you’re new to Uniswap, these three steps give you a practical order of operations.
1. Route swaps through a private RPC
A private RPC sends your swap through a transaction route that keeps it out of the public mempool, where bots watch for pending trades. In practice, you add a provider’s RPC endpoint in your wallet and select it when you use Uniswap. Flashbots is a research and infrastructure organization focused on how Ethereum handles transaction ordering; this flashbots review can help explain its role. Flashbots Protect is one example of a private RPC, and MEV Blocker is another.
This is the best first setup for a beginner who makes ordinary swaps but wants to reduce exposure before adjusting every trade by hand. Check that the RPC supports the network you’re using, then confirm your wallet is connected to it before swapping. A private route can keep a pending transaction out of public view, which removes a key ingredient a public-mempool sandwich bot relies on.
It won’t make every swap risk-free: execution still depends on the route, pool conditions and the transaction being processed. But it is a useful default, especially when a trade is large relative to the liquidity available in its pool.
2. Keep slippage tolerance tight
Slippage tolerance sets how far the price can move before your swap is rejected. A lower limit gives a bot less room to worsen your execution and still have the trade succeed. When you review the swap in Uniswap, look at the displayed minimum amount you’ll receive and avoid accepting a wider limit than you need.
The trade-off is failed swaps. Prices can move during normal trading, especially for volatile tokens or thin pools, so a limit set too tightly may stop a legitimate swap from completing. If a swap fails, review the price and market movement before retrying; raising slippage automatically can expose you to a worse execution.
Pool depth helps you judge the risk. A trade that is small compared with a deep pool is less likely to cause a meaningful price move. A large order in a thin pool faces more price impact and may need a smaller size, a different route, or UniswapX. Tight slippage is not a substitute for choosing a suitable pool: it limits the price you’ll accept, while liquidity affects how much the trade moves the market in the first place.
3. Use UniswapX for larger swaps
UniswapX turns a swap into a signed order that fillers compete to execute, instead of broadcasting your pending swap as a public-mempool transaction. A filler is a participant that takes your signed order and completes the trade. Because there is no pending transaction for a public-mempool bot to sandwich, UniswapX can be a useful choice for larger trades, particularly when the pool is thin relative to your order.
When you prepare a swap, check whether UniswapX is available and compare the quoted amount with the alternative route shown. The goal is to protect a trade that could noticeably move a pool while still checking the price you’ll receive. An order’s off-chain signing changes how it gets filled; it does not remove the need to review the quote and your price limits.
Use the trade’s size relative to pool liquidity to decide when this step matters most. If a modest swap is going into a deep pool, a private RPC and sensible slippage may be enough. If you’re moving a larger amount through a shallow pool, prioritize UniswapX where available, and consider reducing the order size if the quote or price impact looks poor.
Questions traders ask next
Does a private RPC make my Uniswap swap slower?
A private RPC can change how your transaction reaches the network, so speed depends on the provider and current network conditions. It may take a similar amount of time or longer than your usual route. Try it with a routine swap first, and check that it is included before relying on the same setup for a time-sensitive trade.
What slippage setting should I use for stablecoin swaps?
Use the tightest setting that still lets the stablecoin swap complete under normal price movement. Stablecoins often trade close to their intended value, but their pool depth and current conditions vary, so there is no single setting that fits every pair. Review the quoted output and minimum received amount, then widen the limit only if a legitimate swap repeatedly fails and you understand the extra price movement you’re allowing.