How to Build a MEV Bot
Building a profitable MEV bot from scratch typically takes 6–12 months of focused development by a small team (one Solidity engineer + one infrastructure engineer + one quant). The build splits into four interlocking workstreams: on-chain Solidity contracts for atomic sandwich and flash-loan execution, an off-chain mempool listener in Rust or Go, Flashbots / direct-builder bundle submission, and a gas + bribe optimizer tuned per relay. A rough budget — engineering salary + infrastructure + working capital — lands in the $600,000 to $1.3 million range. Most teams never break even; the established operators tune for years and own builder relationships you can't replicate from scratch. Our own reference bot — JaredFromSubway, contract 0x1f2F…F387 — has accumulated 5,900+ ETH in net profit since March 2023.
This guide walks through what it actually takes to build a MEV bot — Solidity contracts, off-chain mempool monitoring, Flashbots integration, gas optimization — and compares the time + capital cost against licensing a working bot.
- The Solidity contracts you'll need
- Infrastructure: RPC nodes, mempool feeds, builders
- Flashbots and the relay submission stack
- Gas optimization + bundle assembly
- Time to first profit
- Build vs buy: real numbers
The Solidity contracts you'll need
At minimum, your MEV bot needs a router contract that exposes entry points for each strategy:
- Sandwich entry — front-run + back-run swap path, with the victim transaction landing between them in the bundle (not in the contract).
- Multi-hop arbitrage — chained swap calls across Uniswap V2, V3, V4, Curve, Balancer Vault.swap, Sushiswap.
- Flash-loan callbacks — Aave executeOperation, Balancer receiveFlashLoan, Uniswap V3 swap callback.
- JIT liquidity — direct UniswapV3Pool.mint + burn calls (bypassing the NFT NonfungiblePositionManager for gas savings).
- Profit check + revert protection — if any leg of the path returns less than expected, revert the entire bundle.
- Operator wallet integration — funds in, builder coinbase tip out, profit kept.
Production contracts are heavily gas-optimized — typically using assembly for the hot paths and avoiding standard libraries (OpenZeppelin) entirely. A naïve OpenZeppelin implementation costs 2-3x more gas per transaction than hand-tuned production code.
Infrastructure: RPC nodes, mempool feeds, builders
Off-chain, the bot needs:
- Dedicated Ethereum nodes — Geth, Erigon, or Reth running on bare metal in low-latency data centers. Public RPCs (Infura, Alchemy, QuickNode) are too slow for competitive MEV.
- Mempool subscription — direct peer connections to major validator nodes for fast pending-transaction visibility. Optionally augmented by BloXroute or Eden mempool feeds.
- Pool state cache — every Uniswap V2/V3/V4 + Curve + Balancer pool you care about, with reserves updated each block.
- Path-finding engine — Bellman-Ford or SPFA running continuously to identify arbitrage opportunities as pool states change.
- Bundle constructor — Rust or Go, signing bundles with the operator wallet, submitting to all six relays in parallel.
Geographic placement matters. Many top MEV operators co-locate near major validator clusters (Zurich, Frankfurt, Ashburn VA) for sub-20ms latency to builders. Generic cloud regions cost you 50–200ms per round-trip — enough to lose every competitive opportunity.
Flashbots and the relay submission stack
After the merge, blocks are produced through proposer-builder separation. Your bundle doesn't go to a single "mempool" — it goes through a relay to one or more block builders, who include it in their proposed block. The six major relays are Flashbots, Beaverbuild, Titan, rsync-builder, BloXroute Max, and Builder0x69. Each has its own bundle API; production bots submit to all six in parallel with carefully sized coinbase tips (typically 95–99.9% of expected profit). Bundle inclusion is binary — either the full bundle lands in the next block or none of it does — so revert protection is critical.
Gas optimization + bundle assembly
Gas optimization is the difference between a profitable and unprofitable bot. Production sandwich transactions on Ethereum are typically 200k–400k gas; production flash-loan arbitrage transactions are 300k–600k gas. Open-source implementations usually cost 600k–1.5M gas for the same work. Techniques include: writing critical paths in inline assembly, avoiding SafeMath (Solidity 0.8+ handles overflow natively), inlining function calls, packing storage slots, and using transient storage (EIP-1153) for cross-call state.
Time to first profit
A realistic timeline for a small team building from scratch:
- Months 1-2: Solidity router contract, basic 3-leg arbitrage, testnet deployment.
- Months 3-4: mempool subscription, pool state cache, path-finding engine.
- Months 5-6: Flashbots integration, first mainnet bundles. Most fail at this stage.
- Months 7-9: gas optimization, builder relationships, debugging revert cases. First sustained profit.
- Months 10-12: sandwich strategies, multi-layer attacks, JIT integration. Match the established operators.
Many teams stall at month 6 — they get bundles landing but find the spreads captured don't cover gas + bribe. Improving past this point requires strategy-specific tuning that production operators have spent years on.
Build vs buy: real numbers
Building from scratch:
- 2-3 engineers × 12 months × $250k/yr fully-loaded = $500k–$750k in salary.
- Infrastructure: dedicated nodes, mempool feeds, monitoring = $2k–$10k/mo.
- Capital for the operator wallet (gas, working balances) = $50k–$500k.
- Total: $600k–$1.3M before any guarantee of profitability.
Buying the JaredETH bot via JaredETH:
- 5,000 USDT/yr License to use the app (managed infrastructure included).
- 10,000 USDT one-time for full source code (you own and self-host).
- Up and running in hours, not months.
- Battle-tested with 5,900+ ETH in proven extraction.
Further reading and references
- Flashbots documentation — Full reference for MEV-Boost, Flashbots Relay, and the bundle-submission API any MEV bot needs.
- Reth (Paradigm Ethereum client) — Modular Rust Ethereum execution client used by many low-latency MEV operators.
- Flash Boys 2.0 (Daian et al., 2019) — The academic baseline for understanding the MEV attack surface you're building against.
The JaredFromSubway MEV bot — battle-tested with 5,900+ ETH in extracted profit.
See pricing →