On-Chain Automation: Building Safe Arbitrage Bots Without Getting MEV'd
A practical guide to writing on-chain arbitrage and rebalancing bots in 2026 — RPC strategy, simulation, private mempools, and the honest economics of small-cap edge.
The myth and the reality
The myth is that on-chain arbitrage is a print-money button. The reality is that 90% of obvious opportunities are eaten by MEV searchers within one block, and the remaining 10% require either low-latency infrastructure or a niche others ignore.
This is a builder's guide to operating in that remaining 10% — without becoming someone else's exit liquidity.
Pick your niche before you pick your stack
Three honest niches still pay in 2026:
- Long-tail DEX pairs on Base, Linea, and emerging L2s where searcher density is low.
- Cross-venue spreads between perp DEXs and centralized venues during high-vol windows.
- Liquidation rebates on lending protocols, especially during fast moves on smaller assets.
Everything else (Uniswap v3 majors, Curve stablepool routes) is dominated by professional MEV firms with a 6-figure infra bill. Compete elsewhere.
RPC architecture
- Read path: self-hosted Erigon or Reth node, plus a fallback Alchemy/Quicknode endpoint. Never rely on a single RPC.
- Write path: private mempool only — Flashbots Protect, MEVBlocker, or chain-native equivalents. Public mempool submission for arb is a donation.
- Simulation: Tenderly or self-hosted Anvil fork before every send. Costs you 80ms, saves you a bricked transaction.
The bot loop
block event → candidate scan → simulate → size → bundle → submit → reconcile
A few non-obvious details:
- Candidate scan must be pre-filtered by gas-adjusted EV. Anything under 1.5x gas cost is noise.
- Sizing uses on-chain liquidity depth, not vibes. Hit a Uniswap v3 tick boundary and your slippage assumption explodes.
- Bundle with a competitive priority fee, but cap it. A bidding war you win at 95% of the EV is a loss.
- Reconcile every fill back to a Postgres ledger. You cannot improve what you cannot measure.
How searchers will hunt you
If you are profitable, you will be reverse-engineered. Defenses:
- Randomize submission timing within a block window.
- Rotate signing addresses.
- Avoid encoding intent in calldata. Use minimal proxy contracts.
- Never publish your bot's address on Twitter. People do this. Don't.
The honest economics
A disciplined small-cap arb bot in 2026 nets 8-25% APY on deployed capital, depending on niche, with sharp drawdowns during quiet markets. Anyone promising 100%+ is either lying, taking uncompensated tail risk, or running on borrowed time before a smart-contract exploit hits.
It is a real business — not a get-rich-quick scheme.
What we teach in the AI Tools & Automation track
- Building the simulator in TypeScript with viem.
- Writing the candidate scanner in Rust for hot-loop performance.
- Operating on Base + Arbitrum from a Hetzner box in Frankfurt.
- Risk gates that cut the bot off before it bleeds.
Graduates leave with a working, audited bot they can deploy on day 1.
Closing
On-chain automation rewards engineers who treat it as engineering, not gambling. Build the simulator first, the bot second, the dashboards third. The PnL is a lagging indicator of how seriously you took the first three.