Web37 min read

Layer 2 Scaling (Optimism, Base, Arbitrum)

Deploy and interact with smart contracts on Ethereum L2s: Optimism, Base, and Arbitrum. Understand rollup mechanics, bridging, and developer differences.

layer2ethereumoptimismbase

Layer 2 (L2) networks settle transactions on Ethereum L1 at a fraction of the cost using rollup technology. Optimistic rollups (Optimism, Base, Arbitrum) and ZK rollups (zkSync, Polygon zkEVM) reduce gas costs 10-100× while inheriting Ethereum security.

Deploy new contracts on L2 by default - the UX is better, costs are lower, and security is derived from Ethereum. Use the OP Stack (Optimism/Base) for its large developer ecosystem. Understand bridging delays before designing user flows.

Workflow

  1. Understand L2 architecture choicesDifferent L2s have different trade-offs; choosing the wrong one adds migration pain.
  2. Deploy contracts to L2L2 deployment is identical to L1 from Solidity's perspective - same tools, same code.
  3. Bridge assets between L1 and L2Users and contracts need to move assets between chains; bridging has different UX/security trade-offs.
  4. Handle L2-specific differencesSmall differences in opcodes or gas accounting can break contracts that work on L1.
  5. Configure wagmi for multi-L2 frontenddApps need to support multiple chains and guide users to the right network.

Output Format

Contracts deployed to L2 (Base/Optimism), wagmi configured for multi-chain, bridging documentation, L2-specific differences documented in README.

Examples

Hardhat L2 config: `base: { url: process.env.BASE_RPC_URL || "https://mainnet.base.org", chainId: 8453, accounts: [process.env.PRIVATE_KEY!] }`
Chain address map: `const TOKEN_ADDRESS: Record<number, Address> = { [base.id]: "0xabc...", [optimism.id]: "0xdef...", [mainnet.id]: "0x123..." }`
L2 gas oracle: `import { optimism } from "@eth-optimism/sdk"; const l1DataFee = await publicClient.readContract({ address: GAS_ORACLE, abi, functionName: "getL1Fee", args: [encodedTx] })`

Edge Cases & Gotchas

  • 7-day withdrawal window confuses users: clearly communicate this in the UI before users initiate native bridge withdrawal
  • Sequencer centralization: all optimistic rollups have a single sequencer that can censor transactions (short-term); L1 force-include exists as a safety valve
  • Re-org risk: L2 transactions can re-org before L1 finalization; wait for appropriate confirmations for high-value operations

When to Break These Rules

  • For DeFi protocols with complex MEV considerations, Ethereum mainnet remains the standard - L2 sequencers have different MEV characteristics.

Reference Files

  • Optimism docs: https://docs.optimism.io/
  • Base docs: https://docs.base.org/
  • Arbitrum docs: https://docs.arbitrum.io/
  • L2Beat (L2 comparison): https://l2beat.com/

More skills in this library

Browse all technical skills - Mobile, AI/ML, Web, Backend, Design, and Product.