Frontrunning is one of the oldest tricks in markets: learn about an order before it executes, then trade ahead of it. On public blockchains it is easier than in traditional markets, because pending transactions are visible to anyone watching the mempool. This article explains how frontrunning works on Polygon, how to recognize it, and the techniques that reduce it, without pretending any of them is a perfect shield.
In short: frontrunners watch Polygon’s public mempool for profitable pending transactions and get their own transaction included first, usually by paying a higher priority fee. Keeping sensitive transactions out of the public mempool with private submission removes the main opportunity. Tight slippage, deadlines and careful contract design reduce what is left.
What frontrunning is
In traditional finance, frontrunning means a broker trading ahead of a client’s order using knowledge of that order. Onchain, nobody needs inside access. A pending transaction in the public mempool reveals what it will do: which pool, which direction, how much and with what slippage. A bot that can get its own transaction included first can profit from the price change the original transaction is about to cause.
How frontrunning works on Polygon, step by step
- You submit a transaction to a public RPC endpoint. It enters the node’s transaction pool and is gossiped across the network.
- A bot sees it. Bots subscribe to pending transactions and decode them, looking for swaps, liquidations, mints or other profitable actions.
- The bot simulates the outcome. It works out whether acting first is profitable, and by how much.
- The bot submits its own transaction with a higher priority fee, so that the block producer is more likely to include it before yours.
- Both land in the same block. The bot’s transaction executes first. Yours executes at a worse price, or fails if the price moved beyond your slippage limit.
On Polygon PoS, the window between submission and inclusion is short, a matter of seconds. Automated bots operate comfortably within it.
Types of frontrunning
Researchers usually describe three patterns:
- Displacement. The bot’s transaction replaces the opportunity entirely. For example, it claims an arbitrage, a reward or a limited mint before you can.
- Insertion. The bot places a transaction before yours and another after it. This is the sandwich attack, covered in detail in sandwich attacks on Polygon.
- Suppression. The bot floods blocks with its own transactions to delay others. This is rarer and expensive.
There are also generalized frontrunners: bots that copy any pending transaction that would be profitable if they sent it themselves, replacing your address with theirs.
How to tell whether you were frontrun
Open your transaction on Polygonscan and look at the block it landed in:
- Is there a transaction just before yours that interacts with the same pool or contract, in the same direction?
- If it was a swap, is there a matching opposite trade from the same address right after yours? That pattern is a sandwich.
- Did the transaction just before yours pay a noticeably higher priority fee?
- Did you receive close to the minimum output your slippage setting allowed?
One instance does not prove intent, as busy pools have many legitimate trades. A pattern of these signs on your trades is a strong hint.
How to prevent frontrunning on Polygon
No single measure removes all risk. These work best together.
1. Submit sensitive transactions privately
The most direct defence is to keep pending transactions out of the public mempool. A private RPC endpoint receives your signed transaction and routes it toward block production without broadcasting it publicly, so bots that rely on mempool data never see it. With Hyperstrate, this usually means changing the URL your application sends transactions to. See how to send private transactions on Polygon.
2. Keep slippage tight
Slippage tolerance is the maximum price movement you accept. For a frontrunner, it is the budget. Use the smallest tolerance that lets your trade succeed under normal conditions, and avoid “auto” settings that allow large tolerances on volatile pairs.
3. Use deadlines
DEX routers usually accept a deadline. If your transaction is delayed, it reverts instead of executing later at a stale price.
4. Reduce price impact
Large trades in thin pools create large price moves, which are more profitable to frontrun. Split large orders, route them across several pools, or use venues with deeper liquidity.
5. Protect admin and time-sensitive operations
Frontrunning is not only about trading. Revoking an approval, updating a parameter, claiming a reward or responding to an incident can all be raced if the pending transaction reveals what is about to happen. Polygon Labs cited a frontrun approval revocation as one of the motivations for its Private Mempool. Treat these operations as sensitive and submit them privately.
6. Design contracts that are harder to frontrun
If you build on Polygon, reduce the advantage of going first:
- Use commit-reveal schemes for actions such as auctions or games, so the content of an action is hidden until it can no longer be raced.
- Require minimum outputs and deadlines in functions that trade.
- Avoid first-come rewards that anyone can claim by copying a pending transaction.
- Bind sensitive actions to the sender, so a copied transaction does not benefit the copier.
What does not work well
- Paying a very high priority fee. Bots can outbid you, and you pay more either way.
- Hoping your trade is too small. Low fees on Polygon mean even small trades can be worth attacking.
- Relying on a dedicated RPC alone. A dedicated endpoint improves reliability but may still broadcast your transaction publicly. See public vs private RPC on Polygon.
Frequently asked questions
Is frontrunning illegal on Polygon?
Polygon is a permissionless network, and transaction ordering by fee is part of how it works. The legal status of onchain frontrunning depends on jurisdiction and context, so this article does not offer legal advice. Practically, the best response is to reduce your exposure.
Can private transactions prevent frontrunning completely?
They remove the most common source: bots reading the public mempool. They cannot rule out every party that handles a transaction before inclusion, and they do not affect what happens after inclusion, so combine private submission with tight slippage and deadlines.
Does a higher gas fee protect me from frontrunning?
Not reliably. A frontrunner can always offer a higher priority fee than you, and you pay the higher fee either way.
Conclusion
Frontrunning on Polygon depends on one thing above all: seeing your transaction before it is included. Private submission takes that away for the transactions that matter, while tight slippage, deadlines, sensible trade sizes and careful contract design limit what remains. Together they turn an easy target into a hard one.
Hyperstrate provides private transaction submission for Polygon through one authenticated endpoint. Read MEV protection on Polygon for the bigger picture, or talk to our team.