Stop frontrunning and sandwich attacks before they happen
Route your agent's transactions through Flashbots bundles and private mempools. MEV bots cannot extract value from transactions they cannot see. Zero public mempool exposure, zero frontrunning risk.
The Threat
Maximal Extractable Value (MEV) is profit extracted by reordering, inserting, or censoring transactions in a block. MEV bots extracted over $100 million from DeFi participants in 2025 alone.
Every transaction broadcast to the Ethereum network sits in the public mempool for 1-15 seconds before inclusion in a block. During that window, MEV bots scan every pending transaction 24/7, evaluating profitability of frontrunning or sandwiching each one.
When a bot identifies a profitable target, it submits a competing transaction with a higher priority fee to ensure it lands in the same block — either immediately before or after your transaction. Block builders and validators accept the highest bids, making this a reliable extraction mechanism.
Under PBS (Proposer-Builder Separation), specialized block builders construct blocks to maximize MEV extraction and split proceeds with validators. This creates a sophisticated, industrialized MEV extraction ecosystem operating at millisecond speed.
The Solution
Three complementary protection mechanisms, automatically selected based on your transaction's MEV risk score.
Transactions are submitted directly to block builders via private relay rather than the public mempool. MEV bots monitoring the public mempool never see the transaction, eliminating frontrunning and sandwich attack opportunities entirely.
High-risk transactions are wrapped in Flashbots bundles and submitted directly to the Flashbots relay. Bundles are atomic — they either land exactly as specified in a block or not at all. No partial execution, no frontrunning gap.
For the most sensitive trades, use commit-reveal: first commit a hash of your intended action, then reveal the actual transaction in a subsequent block. By the time the trade is visible, it is already committed, eliminating any frontrunning window.
Attack Coverage
All four major categories of MEV extraction that target DeFi transactions are blocked by default.
| Attack Type | How It Works | Typical Cost | Protection Method |
|---|---|---|---|
| Frontrunning | Bot sees your large buy in mempool, executes the same buy first at lower price, your tx moves price unfavorably | 0.1-2% of trade value | Private mempool routing |
| Sandwich Attack | Bot buys before your trade + sells immediately after. Your swap executes at inflated price, bot profits the spread | 0.5-3% of trade value | Flashbots bundle + slippage guards |
| Time-Bandit Attack | For very large trades, validators reorg the chain to capture MEV from a past block, rewriting history | 0.05-0.5% of trade value | Flashbots bundle with finality |
| JIT Liquidity Attack | LP provides liquidity just before your swap in the same block, earns fees, removes liquidity in next block — concentrating fee capture at your expense | 0.1-1% of trade value | Commit-reveal scheme |
API Reference
Four endpoints to evaluate risk, execute protected trades, and monitor Flashbots bundle inclusion.
| Method | Endpoint | Description |
|---|---|---|
| POST | /v1/mev/protect |
Submit a transaction with MEV protection. API automatically selects private RPC, Flashbots, or commit-reveal based on risk score and trade size. |
| GET | /v1/mev/risk-score |
Analyze a planned trade for MEV exposure. Returns a 0-1 risk score, estimated MEV extraction value, and recommended protection strategy. |
| GET | /v1/mev/bundle-status |
Check inclusion status of a submitted Flashbots bundle. Returns block target, current block, and inclusion probability estimate. |
| POST | /v1/mev/flashbots-bundle |
Submit a raw Flashbots bundle directly to the Flashbots relay. Use when you need full control over bundle construction and block targeting. |
Code Example
A production-ready pattern that scores MEV risk before each trade and selects the appropriate protection strategy automatically.
import requests
PF_BASE = "https://purpleflea.com/api"
HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}
def get_mev_risk(symbol, size_usd):
"""Score a trade for MEV risk before execution"""
resp = requests.post(
f"{PF_BASE}/v1/mev/risk-score",
json={"symbol": symbol, "size_usd": size_usd},
headers=HEADERS, timeout=5
)
return resp.json()
def protected_trade(symbol, size_usd, side):
"""Execute trade with MEV protection, strategy chosen by risk score"""
# Step 1: assess risk
risk = get_mev_risk(symbol, size_usd)
score = risk["score"] # 0.0 = no risk, 1.0 = extreme risk
# Step 2: select strategy
if score > 0.7:
strategy = "flashbots" # highest protection
elif score > 0.4:
strategy = "private_rpc" # private mempool
else:
strategy = "standard" # normal submission
print(f"MEV risk: {score:.2f} → using {strategy}")
print(f"Estimated extraction risk: ${risk['estimated_loss_usd']:.2f}")
# Step 3: execute with selected protection
result = requests.post(
f"{PF_BASE}/v1/mev/protect",
json={
"symbol": symbol,
"side": side,
"size": size_usd,
"strategy": strategy,
"slippage_tolerance": 0.005 # 0.5% max slippage
},
headers=HEADERS
).json()
return result
# Example: execute a $10K ETH buy with protection
result = protected_trade("ETH", 10000, "buy")
print(f"Execution price: ${result['fill_price']:,.2f}")
print(f"MEV saved: ${result['mev_saved_usd']:.2f}")
Risk Scoring Model
Every trade receives a 0-1 MEV risk score based on trade size, asset liquidity, current mempool congestion, and historical MEV rates for similar trades.
Risk score inputs include: trade size relative to pool liquidity, current mempool searcher activity, time of day, and asset-specific MEV history. Scores are recalculated per-request in real time.
Case Study
A real-world comparison of what happens to a 10 ETH swap on Uniswap with and without MEV protection.
MCP Integration
MEV protection available as native MCP tools for agents running on the Purple Flea MCP server.
mev_protect_transaction
Submit a transaction with automatic MEV protection strategy selection based on real-time risk scoring.
mev_risk_score
Get a 0-1 MEV risk score for a planned trade before execution. Includes estimated extraction value and recommended strategy.
mev_bundle_status
Check the inclusion status of a submitted Flashbots bundle, including current block progress and probability estimate.
Related APIs
MEV bots run 24/7 and never miss a vulnerable transaction. Your agent should have the same level of protection. Start with a free API key — no credit card required.