Crypto Bots

Base Chain Trading Bots: How to Build Bots on Coinbase's L2 (2026)

Base is Coinbase's Ethereum L2 โ€” fast, cheap, and rapidly growing in DeFi liquidity. Learn how to build trading bots on Base using Aerodrome, BaseSwap, and the Coinbase Developer Platform.

A
AI Agents Hubยท2026-03-18ยท4 min readยท714 words

Builder of AI agents, crypto trading bots, and open-source automation tools. Sharing practical guides on how to build, deploy, and profit from AI and DeFi technology.

Why Build on Base?

Base is Coinbase's Layer 2 built on the OP Stack. Launched in 2023, it has become one of the fastest-growing DeFi ecosystems. For bot builders, it offers a compelling combination:

  • Ultra-low fees: Transactions cost $0.001-0.01, compared to $5-50 on Ethereum mainnet
  • 2-second finality for most operations
  • Growing liquidity: $2B+ TVL with Aerodrome, Uniswap V3, and Curve
  • Coinbase integration: Easy onramp for mainstream users
  • EVM compatible: Your Ethereum code works on Base with minimal changes

If you're currently running bots on Ethereum mainnet and paying high gas, migrating to Base can cut costs by 100-1000x.

Setting Up Base Development Environment

npm install ethers viem wagmi
import { createPublicClient, createWalletClient, http } from 'viem'
import { base } from 'viem/chains'
import { privateKeyToAccount } from 'viem/accounts'

const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`)

const publicClient = createPublicClient({
  chain: base,
  transport: http(process.env.BASE_RPC_URL || 'https://mainnet.base.org'),
})

const walletClient = createWalletClient({
  account,
  chain: base,
  transport: http(process.env.BASE_RPC_URL || 'https://mainnet.base.org'),
})

console.log('Connected to Base. Account:', account.address)

Trading on Aerodrome (Base's Largest DEX)

Aerodrome is Base's leading DEX with the highest liquidity. It's a fork of Velodrome (Optimism) with some Base-specific improvements.

const AERODROME_ROUTER = '0xcF77a3Ba9A5CA399B7c97c74d54e5b1Beb874E43'

const ROUTER_ABI = [
  'function swapExactTokensForTokens(uint amountIn, uint amountOutMin, (address from, address to, bool stable, address factory)[] routes, address to, uint deadline) returns (uint[] amounts)',
  'function getAmountsOut(uint amountIn, (address from, address to, bool stable, address factory)[] routes) view returns (uint[] amounts)',
]

async function swapOnAerodrome(
  tokenIn: `0x${string}`,
  tokenOut: `0x${string}`,
  amountIn: bigint,
  slippage = 0.005  // 0.5%
) {
  const router = getContract({ address: AERODROME_ROUTER, abi: ROUTER_ABI, client: walletClient })
  
  const routes = [{
    from: tokenIn,
    to: tokenOut,
    stable: false,  // Use volatile pool for most pairs
    factory: '0x420DD381b31aEf6683db6B902084cB0FFECe40Da',
  }]
  
  // Get quote
  const amounts = await publicClient.readContract({
    address: AERODROME_ROUTER,
    abi: ROUTER_ABI,
    functionName: 'getAmountsOut',
    args: [amountIn, routes],
  }) as bigint[]
  
  const amountOutMin = amounts[amounts.length - 1] * BigInt(Math.floor((1 - slippage) * 1000)) / 1000n
  const deadline = BigInt(Math.floor(Date.now() / 1000) + 300)
  
  const hash = await walletClient.writeContract({
    address: AERODROME_ROUTER,
    abi: ROUTER_ABI,
    functionName: 'swapExactTokensForTokens',
    args: [amountIn, amountOutMin, routes, account.address, deadline],
  })
  
  return hash
}

Arbitrage Between Aerodrome and Uniswap V3 on Base

const UNISWAP_V3_QUOTER = '0x3d4e44Eb1374240CE5F1B136Ea395B4c8d2D2e7'

async function checkBaseArbitrage(
  tokenA: `0x${string}`,
  tokenB: `0x${string}`,
  amount: bigint
) {
  const [aeroPrice, uniV3Price] = await Promise.all([
    getAerodromeQuote(tokenA, tokenB, amount),
    getUniswapV3Quote(tokenA, tokenB, amount),
  ])
  
  const spread = Number(aeroPrice > uniV3Price 
    ? aeroPrice - uniV3Price 
    : uniV3Price - aeroPrice
  ) / Number(amount)
  
  const GAS_COST_USD = 0.01  // ~$0.01 on Base
  const PROFIT_THRESHOLD = 0.005  // 0.5% minimum spread
  
  if (spread > PROFIT_THRESHOLD) {
    const estimatedProfit = Number(amount) * spread / 1e6 - GAS_COST_USD
    console.log(`Arbitrage: ${(spread * 100).toFixed(3)}% spread, ~$${estimatedProfit.toFixed(2)} profit`)
    
    if (estimatedProfit > 0) {
      const buyDex = aeroPrice > uniV3Price ? 'uniswap' : 'aerodrome'
      const sellDex = buyDex === 'uniswap' ? 'aerodrome' : 'uniswap'
      await executeArb(buyDex, sellDex, tokenA, tokenB, amount)
    }
  }
}

Base-Specific Opportunities

1. BALD Token Patterns

Base had several viral token launches. Monitoring social sentiment on Base-specific communities can identify early momentum plays.

2. Coinbase-Listed Token Arbitrage

When Coinbase lists a new token, it often appears on Base DEXs before the mainnet exchange catches up. This creates brief arb windows.

3. Base Bridge Arbitrage

Assets bridged from Ethereum to Base sometimes have pricing discrepancies in the first 10-15 minutes.

Getting Base RPC Access

For production bots, don't use the public RPC (mainnet.base.org). It rate-limits aggressively.

Recommended providers:

  • Alchemy (best for Base, native support)
  • QuickNode (fast with archive access)
  • Infura (reliable but slightly slower)
  • Coinbase Developer Platform (direct Base support, makes sense for Base-native bots)
// Use Alchemy for production
const BASE_RPC = `https://base-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_KEY}`
const BASE_WS = `wss://base-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_KEY}`

Monitoring Your Base Bot

async function logBotStats() {
  const ethBalance = await publicClient.getBalance({ address: account.address })
  
  // Check USDC balance (most common trading token on Base)
  const USDC_BASE = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913'
  const usdcBalance = await publicClient.readContract({
    address: USDC_BASE,
    abi: ERC20_ABI,
    functionName: 'balanceOf',
    args: [account.address],
  }) as bigint
  
  console.log(`ETH: ${formatEther(ethBalance)} | USDC: ${formatUnits(usdcBalance, 6)}`)
}

Base is one of the best chains for building bots right now โ€” the combination of low fees, growing liquidity, and Coinbase's distribution makes it a high-opportunity environment for automated trading in 2026.

Related Articles