Private Mempool Setup
Ethereum's public mempool is a broadcasting system where your unconfirmed transaction is visible to any node within seconds of sending. MEV-bots, front-runners, and sandwich attackers don't need to hack anything — they're just subscribed to pending transactions and automatically react. If your protocol performs large swap operations, liquidations, or arbitrage — public mempool is direct money loss.
Private mempool solves this: the transaction goes directly to a block builder, bypassing public broadcasting, and lands in a block without advance notice.
MEV and Why It's Real Money
Before talking about solution — need to understand problem scale. MEV (Maximal Extractable Value) on Ethereum since transition to PoS is hundreds of millions per year. Mechanics:
Sandwich attack — classic against DEX traders. Bot sees your pending transaction on Uniswap, inserts buy before it (front-run) and sell after (back-run). Your swap executes at worse price, difference goes to bot. At 1% slippage tolerance on $100k swap — potential $1000 loss to attacker.
Liquidation front-running — in lending protocols (Aave, Compound) liquidating positions is profitable: liquidator gets discount. If you try to liquidate a position publicly — competing bot can intercept transaction with higher gas price.
Arbitrage — less harmful to you, but shows how transparent mempool is. Arbitrageurs react to your transactions within one block.
Private Transaction Delivery Architecture
Flashbots: Basic Infrastructure
Flashbots is a research organization that created MEV-Boost and Flashbots Protect. Since transition to PoS, most Ethereum blocks are built via PBS (Proposer-Builder Separation): validator proposes block, but doesn't build it — chooses the best bid from block builders.
Flashbots Protect RPC — simplest option. Change RPC endpoint in wallet or code to https://rpc.flashbots.net. Transactions go to Flashbots bundle pool, not public mempool. Protect works via eth_sendPrivateTransaction under the hood.
const provider = new ethers.JsonRpcProvider("https://rpc.flashbots.net");
// Transactions now go through Flashbots, not public mempool
const tx = await signer.sendTransaction({ to, value, data });
Limitation: no guarantee of inclusion in specific block, no way to bundle multiple transactions atomically.
Flashbots Bundles: Atomic Execution
For complex operations — bundles. Bundle = set of transactions that must execute atomically in one block in specified order. If even one transaction reverts — whole bundle is not included.
import { FlashbotsBundleProvider } from "@flashbots/ethers-provider-bundle";
const flashbotsProvider = await FlashbotsBundleProvider.create(
provider,
authSigner, // key to sign requests to Flashbots relay
"https://relay.flashbots.net"
);
const bundle = [
{ signer: wallet, transaction: approveTx },
{ signer: wallet, transaction: swapTx },
];
const targetBlock = (await provider.getBlockNumber()) + 2;
const simulation = await flashbotsProvider.simulate(bundle, targetBlock);
if ("error" in simulation) throw new Error(simulation.error.message);
// Send bundle to multiple blocks ahead for reliability
for (const blockNumber of [targetBlock, targetBlock + 1, targetBlock + 2]) {
await flashbotsProvider.sendBundle(bundle, blockNumber);
}
Bid mechanism: bundle must be attractive to builder. Builder selects bundles that maximize their profit. Need to include coinbase payment — ETH transfer directly to block builder:
// In last transaction of bundle
block.coinbase.transfer(minerTip);
Tip size determines bundle priority. For arbitrage strategies, usually percentage of arbitrage profit.
MEV Blocker and Alternative Relays
Flashbots is not the only option. MEV relay ecosystem:
MEV Blocker (https://rpc.mevblocker.io) — aggregates private transactions through network of searchers who signed non-front-running rules. Searchers can back-run your transactions (arbitrage after you), but not front-run or sandwich. Part of back-running profit is returned to transaction sender.
Beaver Build — block builder with private RPC, offers bundle API compatible with Flashbots.
bloXroute — enterprise solution, fast bundle delivery through own p2p node network.
For maximum reliability of inclusion — send bundle in parallel to multiple relays:
const RELAYS = [
"https://relay.flashbots.net",
"https://relay.ultrasound.money",
"https://agnostic-relay.net",
];
await Promise.all(
RELAYS.map(relayUrl =>
sendBundle(bundle, targetBlock, relayUrl)
)
);
Setting Up Your Own Private Relay
For protocols with constant transaction flow (liquidation protocols, treasury management) it makes sense to deploy your own MEV relay.
Components
MEV-Boost — middleware between Ethereum validator and block builders. Validator installs MEV-Boost as sidecar process, it accepts bids from builders and selects the best.
mev-relay (Flashbots open source) — relay server, accepts bundles from searchers and delivers them to builders. Requires whitelisted builder partners to include bundle in blocks.
Infrastructure requirements:
- Ethereum archive node (Erigon or Geth with
--gcmode=archive) — minimum 3 TB NVMe, 64GB RAM - Low latency to major block builders: bundle inclusion probability critically depends on delivery speed. Use servers in datacenters near major builders (Equinix NY4, Interxion AMS)
- Monitoring inclusion rate: what percentage of bundles actually landed in block, in which block, what was actual gas price
Operational Nuances
Simulation before sending is mandatory. Sending bundle with reverting transaction — loss of gas and time. Tenderly or own fork (Anvil / Hardhat) for simulation:
anvil --fork-url $ETH_RPC --fork-block-number latest
# Simulate bundle locally before sending
Nonce management — critical point. If you send multiple bundles for parallel blocks, all use same nonce. When one bundle is included, others automatically become invalid — this is expected behavior, not error. But on retry need to increment nonce.
Cancellation: eth_cancelPrivateTransaction in Flashbots allows revoking unconfirmed transaction. Works only if transaction hasn't been included in block yet. For bundles — no direct cancellation, only target block expiration.
L2 and Alternative Networks
On L2 (Arbitrum, Optimism, Base) situation is different: centralized sequencer determines transaction order itself, public mempool practically absent. This protects against external MEV-bots, but not from sequencer itself.
Arbitrum has fair ordering: transactions ordered by time received by sequencer. Sandwich attacks via gas auctions are technically impossible. However sequencer is centralized — Offchain Labs operates it.
For Solana MEV-protection built differently: Jito Labs provides Flashbots equivalent for Solana — jito-solana client and bundle API for atomic transactions.
Success Metrics
After setting up private mempool, measure:
- Inclusion rate: % of bundles that landed in target block ± 2
- MEV savings: comparison of actual execution prices vs spot price at sending moment
- Gas efficiency: with bundles often possible to reduce effective gas through order optimization
- P&L impact: for arbitrage strategies — direct comparison before/after







