🛡 MEV PROTECTION

MEV Protection API for AI Agents

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.

$100M+ MEV Extracted in 2025
0 Public Mempool Exposure
4 Attack Types Blocked
$83 Avg Saved Per 10 ETH Swap

What is MEV?

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.

🕵
How It Starts

Mempool Surveillance

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.

💰
Gas Auction

Priority Fee Bidding

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.

🏗
Block Economics

Block Builder MEV Supply Chain

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.


How Purple Flea Protects You

Three complementary protection mechanisms, automatically selected based on your transaction's MEV risk score.

🔒
Primary Defense

Private Mempool Routing

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.

Flashbots

Flashbots Bundle Inclusion

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.

👔
Cryptographic

Commit-Reveal Scheme

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 Types Prevented

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 Endpoints

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.

Python: Protected Trade Execution

A production-ready pattern that scores MEV risk before each trade and selects the appropriate protection strategy automatically.

protected_trade.py Python
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}")

MEV Risk Score Explained

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.

Low Risk
0.0 – 0.4
Strategy: Standard submission. MEV extraction unlikely to exceed gas cost of protection. Normal mempool broadcast is sufficient.
Medium Risk
0.4 – 0.7
Strategy: Private RPC routing. Transaction hidden from public mempool searchers. Good protection with minimal latency overhead.
High Risk
0.7 – 1.0
Strategy: Flashbots bundle. Maximum protection. Transaction submitted directly to block builders, bypassing the entire public mempool.

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.


10 ETH Swap: Protected vs Unprotected

A real-world comparison of what happens to a 10 ETH swap on Uniswap with and without MEV protection.

Scenario: Buy 10 ETH worth of USDC on Uniswap V3 (pool with $2M TVL)

Without MEV Protection

Planned execution price$2,800.00
Bot buys 15 ETH before youprice moves +$30
Your actual fill price$2,830.00
Bot sells immediately afterprice drops back
Total slippage cost-$85
Gas cost$6.00
Total cost$91.00

With MEV Protection (Flashbots)

Planned execution price$2,800.00
MEV bot visibilitynone (private bundle)
Your actual fill price$2,801.40
Slippage cost-$5.00 (normal)
Protection fee$2.00
Gas cost$6.00
Total cost$13.00
Net saving: $78 on a single trade For an agent doing 5 trades of this size per day: $390/day, $142,350/year

MCP Tools

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.


Complete Your Agent's Security Stack

Protect your agent from MEV extraction

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.

Get Free API Key Read the Docs