Comparing arbitrum with optimism
arbitrum
View full →Author
@0xinit
Stars
53
Repository
0xinit/cryptoskills
Arbitrum
Arbitrum is the largest Ethereum L2 by TVL, running an optimistic rollup via the Nitro execution engine. Nitro compiles a modified Geth (go-ethereum) to WASM, enabling full EVM equivalence with fraud proofs. Arbitrum One targets general-purpose DeFi, Arbitrum Nova uses AnyTrust (data availability committee) for high-throughput gaming/social, and Orbit lets teams launch custom L3s settling to Arbitrum.
What You Probably Got Wrong
AI models trained before late 2024 carry stale assumptions about Arbitrum. These corrections are critical.
block.numberreturns the L1 block number, not L2 — On Arbitrum,block.numberin Solidity returns the L1 Ethereum block number at the time the sequencer processed the transaction. UseArbSys(0x64).arbBlockNumber()for the actual L2 block number.block.timestampis the L1 timestamp — Same issue.block.timestampreflects L1 time. For L2ley timing useArbSys(0x64).arbBlockNumber()and correlate.- Arbitrum does NOT have the same gas model as Ethereum — Every Arbitrum transaction pays two gas components: (1) L2 execution gas (similar to Ethereum but cheaper), and (2) L1 data posting cost (calldata compressed and posted to Ethereum). The L1 component often dominates for data-heavy transactions. Use
NodeInterface.gasEstimateComponents()to get the breakdown. - You need
--legacyfor Foundry deployments — Arbitrum's sequencer does not support EIP-1559 type-2 transactions natively in forge scripts. Use--legacyflag or your deployment will fail with a cryptic RPC error. msg.senderin cross-chain calls is aliased — When an L1 contract sends a message to L2 via retryable tickets,msg.senderon L2 is NOT the L1 contract address. It is the L1 address +0x1111000000000000000000000000000000001111(the "address alias"). This prevents L1/L2 address collision attacks.- Retryable tickets can fail silently — An L1-to-L2 retryable ticket that runs out of gas on L2 does NOT revert on L1. It sits in the retry buffer for 7 days. You must monitor and manually redeem failed retryables, or your cross-chain message is lost after the TTL.
- Withdrawals take 7 days, not minutes — L2-to-L1 messages go through the optimistic rollup challenge period. After calling
ArbSys.sendTxToL1(), the user must wait ~7 days, then execute the message on L1 via the Outbox contract. There is no fast path in the native bridge. - There is no mempool — Arbitrum uses a centralized sequencer that orders transactions on a first-come-first-served basis. There is no traditional mempool, so MEV extraction works differently (no frontrunning via gas price bidding).
Quick Start
Chain Configuration
import { defineChain } from "viem";
import { arbitrum, arbitrumNova, arbitrumSepolia } from "viem/chains";
// Arbitrum One — mainnet
// Chain ID: 42161
// RPC: https://arb1.arbitrum.io/rpc (public, rate-limited)
// Arbitrum Nova — AnyTrust chain for gaming/social
// Chain ID: 42170
// RPC: https://nova.arbitrum.io/rpc
// Arbitrum Sepolia — testnet
// Chain ID: 421614
// RPC: https://sepolia-rollup.arbitrum.io/rpc
Client Setup
import { createPublicClient, createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { arbitrum } from "viem/chains";
const publicClient = createPublicClient({
chain: arbitrum,
transport: http(process.env.ARBITRUM_RPC_URL),
});
const account = privateKeyToAccount(
process.env.PRIVATE_KEY as `0x${string}`
);
const walletClient = createWalletClient({
account,
chain: arbitrum,
transport: http(process.env.ARBITRUM_RPC_URL),
});
Chain Details
| Property | Arbitrum One | Arbitrum Nova | Arbitrum Sepolia |
|---|---|---|---|
| Chain ID | 42161 | 42170 | 421614 |
| RPC | https://arb1.arbitrum.io/rpc | https://nova.arbitrum.io/rpc | https://sepolia-rollup.arbitrum.io/rpc |
| Explorer | https://arbiscan.io | https://nova.arbiscan.io | https://sepolia.arbiscan.io |
| Bridge | https://bridge.arbitrum.io | https://bridge.arbitrum.io | https://bridge.arbitrum.io |
| Native Token | ETH | ETH | ETH |
| Block Time | ~0.25s | ~0.25s | ~0.25s |
| Finality | ~7 days (challenge period) | ~7 days | ~7 days |
Deployment
Foundry Deployment
The --legacy flag is required — Arbitrum's sequencer does not natively support EIP-1559 type-2 transaction envelopes in forge broadcast.
# Deploy to Arbitrum One
forge create src/MyContract.sol:MyContract \
--rpc-url $ARBITRUM_RPC_URL \
--private-key $PRIVATE_KEY \
--legacy
# Deploy to Arbitrum Sepolia (testnet)
forge create src/MyContract.sol:MyContract \
--rpc-url https://sepolia-rollup.arbitrum.io/rpc \
--private-key $PRIVATE_KEY \
--legacy
# Using forge script
forge script script/Deploy.s.sol:DeployScript \
--rpc-url $ARBITRUM_RPC_URL \
--private-key $PRIVATE_KEY \
--broadcast \
--legacy
Hardhat Deployment
// hardhat.config.ts
import { HardhatUserConfig } from "hardhat/config";
const config: HardhatUserConfig = {
solidity: "0.8.24",
networks: {
arbitrumOne: {
url: process.env.ARBITRUM_RPC_URL ?? "https://arb1.arbitrum.io/rpc",
accounts: [process.env.PRIVATE_KEY!],
chainId: 42161,
},
arbitrumSepolia: {
url: "https://sepolia-rollup.arbitrum.io/rpc",
accounts: [process.env.PRIVATE_KEY!],
chainId: 421614,
},
},
etherscan: {
apiKey: {
arbitrumOne: process.env.ARBISCAN_API_KEY!,
arbitrumSepolia: process.env.ARBISCAN_API_KEY!,
},
},
};
export default config;
Contract Verification
# Verify on Arbiscan (Foundry)
forge verify-contract \
--chain-id 42161 \
--etherscan-api-key $ARBISCAN_API_KEY \
--compiler-version v0.8.24 \
$CONTRACT_ADDRESS \
src/MyContract.sol:MyContract
# Verify with constructor args
forge verify-contract \
--chain-id 42161 \
--etherscan-api-key $ARBISCAN_API_KEY \
--constructor-args $(cast abi-encode "constructor(address,uint256)" 0xYourAddress 1000) \
$CONTRACT_ADDRESS \
src/MyContract.sol:MyContract
# Verify on Sourcify
forge verify-contract \
--chain-id 42161 \
--verifier sourcify \
$CONTRACT_ADDRESS \
src/MyContract.sol:MyContract
Cross-Chain Messaging
L1 to L2: Retryable Tickets
Retryable tickets are Arbitrum's mechanism for sending messages from Ethereum L1 to Arbitrum L2. The L1 Inbox contract accepts the message and ETH for L2 gas, then the sequencer auto-executes it on L2.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IInbox {
/// @notice Create a retryable ticket to send an L1→L2 message
/// @param to L2 destination address
/// @param l2CallValue ETH value to send to L2 destination
/// @param maxSubmissionCost Max cost for L2 submission (refund if overestimated)
/// @param excessFeeRefundAddress L2 address to refund excess fees
/// @param callValueRefundAddress L2 address to refund call value on failure
/// @param gasLimit L2 gas limit for execution
/// @param maxFeePerGas Max L2 gas price
/// @param data L2 calldata
function createRetryableTicket(
address to,
uint256 l2CallValue,
uint256 maxSubmissionCost,
address excessFeeRefundAddress,
address callValueRefundAddress,
uint256 gasLimit,
uint256 maxFeePerGas,
bytes calldata data
) external payable returns (uint256);
}
// TypeScript: send L1→L2 message via retryable ticket
import { createPublicClient, createWalletClient, http, parseEther } from "viem";
import { mainnet } from "viem/chains";
const INBOX = "0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f" as const;
const inboxAbi = [
{
name: "createRetryableTicket",
type: "function",
stateMutability: "payable",
inputs: [
{ name: "to", type: "address" },
{ name: "l2CallValue", type: "uint256" },
{ name: "maxSubmissionCost", type: "uint256" },
{ name: "excessFeeRefundAddress", type: "address" },
{ name: "callValueRefundAddress", type: "address" },
{ name: "gasLimit", type: "uint256" },
{ name: "maxFeePerGas", type: "uint256" },
{ name: "data", type: "bytes" },
],
outputs: [{ name: "", type: "uint256" }],
},
] as const;
const l1PublicClient = createPublicClient({
chain: mainnet,
transport: http(process.env.ETHEREUM_RPC_URL),
});
const maxSubmissionCost = parseEther("0.001");
const gasLimit = 1_000_000n;
const maxFeePerGas = 100_000_000n; // 0.1 gwei
// Total ETH needed: l2CallValue + maxSubmissionCost + (gasLimit * maxFeePerGas)
const totalValue = 0n + maxSubmissionCost + gasLimit * maxFeePerGas;
const { request } = await l1PublicClient.simulateContract({
address: INBOX,
abi: inboxAbi,
functionName: "createRetryableTicket",
args: [
"0xYourL2ContractAddress", // to
0n, // l2CallValue
maxSubmissionCost, // maxSubmissionCost
account.address, // excessFeeRefundAddress
account.address, // callValueRefundAddress
gasLimit, // gasLimit
maxFeePerGas, // maxFeePerGas
"0x", // data (encoded L2 function call)
],
value: totalValue,
account: account.address,
});
const hash = await walletClient.writeContract(request);
L2 to L1: ArbSys.sendTxToL1
L2-to-L1 messages go through the 7-day challenge period before they can be executed on L1.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IArbSys {
/// @notice Send a transaction from L2 to L1
/// @param destination L1 destination address
/// @param data L1 calldata
/// @return unique message ID
function sendTxToL1(
address destination,
bytes calldata data
) external payable returns (uint256);
/// @notice Get the current L2 block number
function arbBlockNumber() external view returns (uint256);
}
// ArbSys is at a fixed precompile address on all Arbitrum chains
IArbSys constant ARBSYS = IArbSys(0x0000000000000000000000000000000000000064);
contract L2ToL1Sender {
event L2ToL1MessageSent(uint256 indexed messageId, address destination);
function sendMessageToL1(
address l1Target,
bytes calldata l1Calldata
) external payable {
uint256 messageId = ARBSYS.sendTxToL1{value: msg.value}(
l1Target,
l1Calldata
);
emit L2ToL1MessageSent(messageId, l1Target);
}
}
Address Aliasing
When an L1 contract sends a retryable ticket, the msg.sender seen on L2 is the aliased address:
L2 alias = L1 address + 0x1111000000000000000000000000000000001111
// Reverse the alias to get the original L1 sender
function undoL1ToL2Alias(address l2Address) internal pure returns (address) {
uint160 offset = uint160(0x1111000000000000000000000000000000001111);
unchecked {
return address(uint160(l2Address) - offset);
}
}
// Verify an L2 call came from a specific L1 contract
modifier onlyFromL1Contract(address expectedL1Sender) {
require(
undoL1ToL2Alias(msg.sender) == expectedL1Sender,
"NOT_FROM_L1_CONTRACT"
);
_;
}
ArbOS Precompiles
Arbitrum provides system-level functionality through precompile contracts at fixed addresses. These are available on all Arbitrum chains.
ArbSys (0x0000000000000000000000000000000000000064)
Core system functions for L2 operations.
interface IArbSys {
function arbBlockNumber() external view returns (uint256);
function arbBlockHash(uint256 blockNumber) external view returns (bytes32);
function arbChainID() external view returns (uint256);
function arbOSVersion() external view returns (uint256);
function sendTxToL1(address dest, bytes calldata data) external payable returns (uint256);
function withdrawEth(address dest) external payable returns (uint256);
}
const arbSysAbi = [
{
name: "arbBlockNumber",
type: "function",
stateMutability: "view",
inputs: [],
outputs: [{ name: "", type: "uint256" }],
},
{
name: "withdrawEth",
type: "function",
stateMutability: "payable",
inputs: [{ name: "destination", type: "address" }],
outputs: [{ name: "", type: "uint256" }],
},
] as const;
const ARBSYS = "0x0000000000000000000000000000000000000064" as const;
const l2BlockNumber = await publicClient.readContract({
address: ARBSYS,
abi: arbSysAbi,
functionName: "arbBlockNumber",
});
ArbRetryableTx (0x000000000000000000000000000000000000006E)
Manage retryable tickets on L2.
interface IArbRetryableTx {
/// @notice Redeem a retryable ticket that failed auto-execution
function redeem(bytes32 ticketId) external;
/// @notice Get the TTL for retryable tickets (default: 7 days)
function getLifetime() external view returns (uint256);
/// @notice Get the timeout timestamp for a specific ticket
function getTimeout(bytes32 ticketId) external view returns (uint256);
/// @notice Extend the lifetime of a retryable ticket
function keepalive(bytes32 ticketId) external returns (uint256);
}
ArbGasInfo (0x000000000000000000000000000000000000006C)
Gas pricing information, especially the L1 data cost component.
interface IArbGasInfo {
/// @notice Get gas prices: [perL2Tx, perL1CalldataUnit, perStorageAlloc, perArbGasBase, perArbGasCongestion, perArbGasTotal]
function getPricesInWei() external view returns (uint256, uint256, uint256, uint256, uint256, uint256);
/// @notice Get estimated L1 base fee
function getL1BaseFeeEstimate() external view returns (uint256);
/// @notice Get L1 gas pricing parameters
function getL1GasPriceEstimate() external view returns (uint256);
}
const arbGasInfoAbi = [
{
name: "getPricesInWei",
type: "function",
stateMutability: "view",
inputs: [],
outputs: [
{ name: "perL2Tx", type: "uint256" },
{ name: "perL1CalldataUnit", type: "uint256" },
{ name: "perStorageAlloc", type: "uint256" },
{ name: "perArbGasBase", type: "uint256" },
{ name: "perArbGasCongestion", type: "uint256" },
{ name: "perArbGasTotal", type: "uint256" },
],
},
{
name: "getL1BaseFeeEstimate",
type: "function",
stateMutability: "view",
inputs: [],
outputs: [{ name: "", type: "uint256" }],
},
] as const;
const ARBGASINFO = "0x000000000000000000000000000000000000006C" as const;
const prices = await publicClient.readContract({
address: ARBGASINFO,
abi: arbGasInfoAbi,
functionName: "getPricesInWei",
});
const l1BaseFee = await publicClient.readContract({
address: ARBGASINFO,
abi: arbGasInfoAbi,
functionName: "getL1BaseFeeEstimate",
});
NodeInterface (0x00000000000000000000000000000000000000C8)
Virtual contract for gas estimation — not callable from other contracts, only via eth_call / eth_estimateGas.
interface INodeInterface {
/// @notice Estimate gas for a retryable ticket submission
function estimateRetryableTicket(
address sender,
uint256 deposit,
address to,
uint256 l2CallValue,
address excessFeeRefundAddress,
address callValueRefundAddress,
bytes calldata data
) external;
/// @notice Get gas cost breakdown: gasEstimate, gasEstimateForL1, baseFee, l1BaseFeeEstimate
function gasEstimateComponents(
address to,
bool contractCreation,
bytes calldata data
) external payable returns (uint64, uint64, uint256, uint256);
}
const nodeInterfaceAbi = [
{
name: "gasEstimateComponents",
type: "function",
stateMutability: "payable",
inputs: [
{ name: "to", type: "address" },
{ name: "contractCreation", type: "bool" },
{ name: "data", type: "bytes" },
],
outputs: [
{ name: "gasEstimate", type: "uint64" },
{ name: "gasEstimateForL1", type: "uint64" },
{ name: "baseFee", type: "uint256" },
{ name: "l1BaseFeeEstimate", type: "uint256" },
],
},
] as const;
const NODE_INTERFACE = "0x00000000000000000000000000000000000000C8" as const;
// Estimate gas with L1/L2 breakdown
const result = await publicClient.simulateContract({
address: NODE_INTERFACE,
abi: nodeInterfaceAbi,
functionName: "gasEstimateComponents",
args: [
"0xTargetContract",
false,
"0xEncodedCalldata",
],
});
const [totalGas, l1Gas, baseFee, l1BaseFee] = result.result;
// L2 gas = totalGas - l1Gas
Gas Model
Arbitrum's gas model has two components. Understanding this is critical for accurate cost estimation.
Two-Component Gas
| Component | Source | Scales With |
|---|---|---|
| L2 execution gas | ArbOS computation | Opcodes executed (similar to Ethereum) |
| L1 data posting cost | Calldata posted to Ethereum | Transaction size in bytes |
The L1 data cost is computed as:
L1 cost = L1 base fee * (calldata bytes * 16 + overhead)
This L1 cost is converted to L2 gas units and added to the total gas used. For data-heavy transactions (large calldata, many storage writes that get batched), the L1 component can be 80%+ of total cost.
Gas Estimation
import { encodeFunctionData, formatEther } from "viem";
async function estimateArbitrumGas(
publicClient: PublicClient,
to: `0x${string}`,
data: `0x${string}`
) {
const nodeInterfaceAbi = [
{
name: "gasEstimateComponents",
type: "function",
stateMutability: "payable",
inputs: [
{ name: "to", type: "address" },
{ name: "contractCreation", type: "bool" },
{ name: "data", type: "bytes" },
],
outputs: [
{ name: "gasEstimate", type: "uint64" },
{ name: "gasEstimateForL1", type: "uint64" },
{ name: "baseFee", type: "uint256" },
{ name: "l1BaseFeeEstimate", type: "uint256" },
],
},
] as const;
const { result } = await publicClient.simulateContract({
address: "0x00000000000000000000000000000000000000C8",
abi: nodeInterfaceAbi,
functionName: "gasEstimateComponents",
args: [to, false, data],
});
const [totalGas, l1Gas, baseFee, l1BaseFee] = result;
const l2Gas = totalGas - l1Gas;
return {
totalGas,
l1Gas,
l2Gas,
baseFee,
l1BaseFee,
estimatedCostWei: BigInt(totalGas) * baseFee,
estimatedCostEth: formatEther(BigInt(totalGas) * baseFee),
};
}
Token Bridge
Bridging ETH (L1 to L2)
const INBOX = "0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f" as const;
const inboxAbi = [
{
name: "depositEth",
type: "function",
stateMutability: "payable",
inputs: [],
outputs: [{ name: "", type: "uint256" }],
},
] as const;
// Deposit 0.1 ETH from L1 to L2 (arrives at same address on L2)
const { request } = await l1PublicClient.simulateContract({
address: INBOX,
abi: inboxAbi,
functionName: "depositEth",
value: parseEther("0.1"),
account: account.address,
});
const hash = await l1WalletClient.writeContract(request);
const receipt = await l1PublicClient.waitForTransactionReceipt({ hash });
if (receipt.status !== "success") throw new Error("ETH deposit failed");
// ETH appears on L2 within ~10 minutes
Bridging ETH (L2 to L1)
// Withdraw ETH from L2 to L1 via ArbSys precompile
const ARBSYS = "0x0000000000000000000000000000000000000064" as const;
const arbSysAbi = [
{
name: "withdrawEth",
type: "function",
stateMutability: "payable",
inputs: [{ name: "destination", type: "address" }],
outputs: [{ name: "", type: "uint256" }],
},
] as const;
const { request } = await l2PublicClient.simulateContract({
address: ARBSYS,
abi: arbSysAbi,
functionName: "withdrawEth",
args: [account.address], // L1 destination
value: parseEther("0.1"),
account: account.address,
});
const hash = await l2WalletClient.writeContract(request);
// After 7-day challenge period, claim on L1 via Outbox contract
Bridging ERC20 Tokens (L1 to L2)
ERC20 tokens bridge through the Gateway Router, which routes to the appropriate gateway (standard, custom, or WETH).
const GATEWAY_ROUTER = "0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef" as const;
const gatewayRouterAbi = [
{
name: "outboundTransfer",
type: "function",
stateMutability: "payable",
inputs: [
{ name: "_token", type: "address" },
{ name: "_to", type: "address" },
{ name: "_amount", type: "uint256" },
{ name: "_maxGas", type: "uint256" },
{ name: "_gasPriceBid", type: "uint256" },
{ name: "_data", type: "bytes" },
],
outputs: [{ name: "", type: "bytes" }],
},
{
name: "getGateway",
type: "function",
stateMutability: "view",
inputs: [{ name: "_token", type: "address" }],
outputs: [{ name: "", type: "address" }],
},
] as const;
const USDC_L1 = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48" as const;
// Step 1: Approve the gateway (not the router) to spend tokens
const gateway = await l1PublicClient.readContract({
address: GATEWAY_ROUTER,
abi: gatewayRouterAbi,
functionName: "getGateway",
args: [USDC_L1],
});
// Step 2: approve gateway, then call outboundTransfer on the router
// The _data param encodes maxSubmissionCost and extra data
import { encodeAbiParameters, parseAbiParameters } from "viem";
const maxSubmissionCost = parseEther("0.001");
const extraData = encodeAbiParameters(
parseAbiParameters("uint256, bytes"),
[maxSubmissionCost, "0x"]
);
const bridgeAmount = 1000_000000n; // 1000 USDC (6 decimals)
const gasLimit = 300_000n;
const gasPriceBid = 100_000_000n; // 0.1 gwei
const totalValue = maxSubmissionCost + gasLimit * gasPriceBid;
const { request } = await l1PublicClient.simulateContract({
address: GATEWAY_ROUTER,
abi: gatewayRouterAbi,
functionName: "outboundTransfer",
args: [
USDC_L1,
account.address,
bridgeAmount,
gasLimit,
gasPriceBid,
extraData,
],
value: totalValue,
account: account.address,
});
Gateway Types
| Gateway | Address (L1) | Purpose |
|---|---|---|
| Standard ERC20 | 0xa3A7B6F88361F48403514059F1F16C8E78d60EeC | Default for most ERC20 tokens |
| Custom | Varies per token | Tokens needing custom L1/L2 logic |
| WETH | 0xd92023E9d9911199a6711321D1277285e6d4e2db | Handles WETH unwrap/wrap across bridge |
Orbit Chains
Orbit allows teams to launch custom L3 chains that settle to Arbitrum One or Nova. These are independent chains with configurable parameters.
Orbit Architecture
Ethereum L1 (settlement)
└── Arbitrum One L2 (execution + DA)
└── Your Orbit L3 (custom chain)
Orbit SDK Setup
import { createRollupPrepareConfig, createRollupPrepareTransactionRequest } from "@arbitrum/orbit-sdk";
// Prepare Orbit chain configuration
const config = createRollupPrepareConfig({
chainId: BigInt(YOUR_CHAIN_ID),
owner: "0xYourOwnerAddress",
chainConfig: {
// Custom gas token, data availability, etc.
homesteadBlock: 0,
daoForkBlock: null,
daoForkSupport: true,
eip150Block: 0,
eip150Hash: "0x0000000000000000000000000000000000000000000000000000000000000000",
eip155Block: 0,
eip158Block: 0,
byzantiumBlock: 0,
constantinopleBlock: 0,
petersburgBlock: 0,
istanbulBlock: 0,
muirGlacierBlock: 0,
berlinBlock: 0,
londonBlock: 0,
clique: { period: 0, epoch: 0 },
arbitrum: {
EnableArbOS: true,
AllowDebugPrecompiles: false,
DataAvailabilityCommittee: false, // true for AnyTrust
InitialArbOSVersion: 20,
InitialChainOwner: "0xYourOwnerAddress",
GenesisBlockNum: 0,
},
},
});
When to Use Orbit
| Use Case | Recommendation |
|---|---|
| App-specific chain with custom gas token | Orbit L3 |
| High-throughput gaming with cheap DA | Orbit L3 + AnyTrust |
| General DeFi app | Deploy to Arbitrum One directly |
| Cross-chain interop needed | Deploy to Arbitrum One (better liquidity) |
Key Differences from Ethereum
| Behavior | Ethereum | Arbitrum |
|---|---|---|
block.number | Current L1 block | L1 block number (NOT L2) |
block.timestamp | L1 timestamp | L1 timestamp |
| L2 block number | N/A | ArbSys(0x64).arbBlockNumber() |
| Gas model | Single gas price | L2 gas + L1 data posting cost |
| Transaction type | EIP-1559 (type 2) | Legacy (type 0) recommended |
| Mempool | Public, competitive | No mempool (FCFS sequencer) |
| Finality | ~12 seconds (1 epoch) | ~0.25s soft, ~7 days hard |
msg.sender cross-chain | Same address | Aliased (+0x1111...1111 offset) |
SELFDESTRUCT | Deprecated (EIP-6780) | Same as Ethereum post-Dencun |
| Contract size limit | 24KB (EIP-170) | 24KB (same) |
PUSH0 opcode | Supported (Shanghai) | Supported (Nitro supports it) |
Contract Addresses
Last verified: February 2026
Core Contracts (Arbitrum One)
| Contract | Address |
|---|---|
| Rollup | 0x5eF0D09d1E6204141B4d37530808eD19f60FBa35 |
| Inbox | 0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f |
| Outbox | 0x0B9857ae2D4A3DBe74ffE1d7DF045bb7F96E4840 |
| Bridge | 0x8315177aB297bA92A06054cE80a67Ed4DBd7ed3a |
| SequencerInbox | 0x1c479675ad559DC151F6Ec7ed3FbF8ceE79582B6 |
| Gateway Router (L1) | 0x72Ce9c846789fdB6fC1f34aC4AD25Dd9ef7031ef |
| Standard Gateway (L1) | 0xa3A7B6F88361F48403514059F1F16C8E78d60EeC |
| WETH Gateway (L1) | 0xd92023E9d9911199a6711321D1277285e6d4e2db |
| Gateway Router (L2) | 0x5288c571Fd7aD117beA99bF60FE0846C4E84F933 |
| Standard Gateway (L2) | 0x09e9222E96E7B4AE2a407B98d48e330053351EEe |
ArbOS Precompiles
| Precompile | Address |
|---|---|
| ArbSys | 0x0000000000000000000000000000000000000064 |
| ArbInfo | 0x0000000000000000000000000000000000000065 |
| ArbAddressTable | 0x0000000000000000000000000000000000000066 |
| ArbBLS (deprecated) | 0x0000000000000000000000000000000000000067 |
| ArbFunctionTable (deprecated) | 0x0000000000000000000000000000000000000068 |
| ArbosTest | 0x0000000000000000000000000000000000000069 |
| ArbOwner | 0x0000000000000000000000000000000000000070 |
| ArbGasInfo | 0x000000000000000000000000000000000000006C |
| ArbAggregator | 0x000000000000000000000000000000000000006D |
| ArbRetryableTx | 0x000000000000000000000000000000000000006E |
| ArbStatistics | 0x000000000000000000000000000000000000006F |
| NodeInterface | 0x00000000000000000000000000000000000000C8 |
Token Addresses (Arbitrum One)
| Token | Address |
|---|---|
| ARB | 0x912CE59144191C1204E64559FE8253a0e49E6548 |
| WETH | 0x82aF49447D8a07e3bd95BD0d56f35241523fBab1 |
| USDC (native) | 0xaf88d065e77c8cC2239327C5EDb3A432268e5831 |
| USDC.e (bridged) | 0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8 |
| USDT | 0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9 |
| DAI | 0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1 |
| WBTC | 0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f |
| GMX | 0xfc5A1A6EB076a2C7aD06eD22C90d7E710E35ad0a |
Error Handling
| Error | Cause | Fix |
|---|---|---|
NOT_ENOUGH_FUNDS | Insufficient ETH for L2 gas + L1 data cost | Account for both gas components in estimation |
RETRYABLE_TICKET_CREATION_FAILED | Retryable ticket underfunded | Increase maxSubmissionCost or gasLimit * maxFeePerGas |
ONLY_ROLLUP_OR_OWNER | Calling admin precompile without permission | These are restricted to chain owner |
NO_TICKET_WITH_ID | Redeeming non-existent or expired retryable | Check ticket still exists with getTimeout() |
ALREADY_REDEEMED | Retryable ticket already executed | No action needed — message was delivered |
L1_MSG_NOT_CONFIRMED | Trying to execute L2→L1 message too early | Wait for the 7-day challenge period to elapse |
| Nonce too high/low | Sequencer nonce mismatch | Reset nonce or wait for pending transactions |
Security
Cross-Chain Message Validation
// Always verify the sender of cross-chain messages
// L1→L2: check aliased sender
modifier onlyL1Contract(address expectedL1Sender) {
uint160 offset = uint160(0x1111000000000000000000000000000000001111);
unchecked {
require(
address(uint160(msg.sender) - offset) == expectedL1Sender,
"ONLY_L1_CONTRACT"
);
}
_;
}
// L2→L1: verify via Outbox on L1
modifier onlyL2Contract(address outbox) {
// The Outbox contract provides l2ToL1Sender() during execution
IOutbox(outbox).l2ToL1Sender();
_;
}
Gas Estimation Safety
- Always use
NodeInterface.gasEstimateComponents()instead of plaineth_estimateGas— the latter may not account for L1 data costs correctly in all cases. - Add a 20-30% buffer to gas estimates for L1 data cost fluctuations.
- For retryable tickets, overestimate
maxSubmissionCost— excess is refunded.
Retryable Ticket Monitoring
- Monitor all retryable tickets for auto-redeem failure.
- Failed retryables expire after 7 days — set up alerts.
- Use the
ArbRetryableTxprecompile to check status and manually redeem.
References
optimism
View full →Author
@0xinit
Stars
53
Repository
0xinit/cryptoskills
Optimism
Optimism is an EVM-equivalent Layer 2 using optimistic rollups. Transactions execute on L2 with data posted to Ethereum L1 for security. The OP Stack is the modular framework powering OP Mainnet, Base, Zora, Mode, and the broader Superchain. Smart contracts deploy identically to Ethereum — no custom compiler, no special opcodes.
What You Probably Got Wrong
- OP Mainnet IS EVM-equivalent, not just EVM-compatible — Your Solidity contracts deploy without modification. No
--legacyflag, no custom compiler.forge createandhardhat deploywork identically to Ethereum. If someone tells you to change your Solidity for "OP compatibility", they are wrong. - Gas has two components, not one — Every transaction pays L2 execution gas AND an L1 data fee for posting calldata/blobs to Ethereum. If you only estimate L2 gas via
eth_estimateGas, your cost estimate will be wrong. The L1 data fee often dominates total cost. Use theGasPriceOraclepredeploy at0x420000000000000000000000000000000000000F. - L2→L1 withdrawals take 7 days, not minutes — L1→L2 deposits finalize in ~1-3 minutes. L2→L1 withdrawals require a 7-day challenge period (the "fault proof window"). Users must prove the withdrawal, wait 7 days, then finalize. Three separate transactions on L1. If your UX assumes instant bridging both ways, it is broken.
block.numberreturns the L2 block number, not L1 — On OP Mainnet,block.numberis the L2 block number. To get the L1 block number, read theL1Blockpredeploy at0x4200000000000000000000000000000000000015. L2 blocks are produced every 2 seconds.msg.senderworks normally — there is notx.originaliasing on L2 — Cross-domain messages from L1 to L2 alias the sender address (add0x1111000000000000000000000000000000001111). But for normal L2 transactions,msg.senderbehaves exactly like Ethereum. Only worry about aliasing when receiving L1→L2 messages in your contract.- Predeploy contracts live at fixed addresses starting with
0x4200...— These are NOT deployed by you. They exist at genesis.L2CrossDomainMessenger,L2StandardBridge,GasPriceOracle,L1Block, and others all live at hardcoded addresses in the0x4200...range. Do not try to deploy them. - The sequencer is centralized but cannot steal funds — The sequencer orders transactions and proposes state roots. If it goes down, you cannot submit new transactions until it recovers (or until permissionless fault proofs allow forced inclusion). But the sequencer cannot forge invalid state — the fault proof system protects withdrawals.
- EIP-4844 blob data changed the gas model — After the Ecotone upgrade (March 2024), OP Mainnet posts data using EIP-4844 blobs instead of calldata. This reduced L1 data fees by ~10-100x. The
GasPriceOraclemethods changed. If you are reading pre-Ecotone documentation, the fee formulas are outdated. - SuperchainERC20 is not a standard ERC20 — It is a cross-chain token standard for OP Stack chains that enables native interop between Superchain members. Tokens must implement
ICrosschainERC20withcrosschainMintandcrosschainBurn. Do not assume a regular ERC20 works across chains.
Quick Start
Chain Configuration
import { defineChain } from "viem";
import { optimism, optimismSepolia } from "viem/chains";
// OP Mainnet is built-in
// Chain ID: 10
// RPC: https://mainnet.optimism.io
// Explorer: https://optimistic.etherscan.io
// OP Sepolia is also built-in
// Chain ID: 11155420
// RPC: https://sepolia.optimism.io
// Explorer: https://sepolia-optimistic.etherscan.io
Environment Setup
# .env
PRIVATE_KEY=your_private_key_here
OP_MAINNET_RPC=https://mainnet.optimism.io
OP_SEPOLIA_RPC=https://sepolia.optimism.io
ETHERSCAN_API_KEY=your_optimistic_etherscan_api_key
Viem Client Setup
import { createPublicClient, createWalletClient, http } from "viem";
import { optimism } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(`0x${process.env.PRIVATE_KEY}`);
const publicClient = createPublicClient({
chain: optimism,
transport: http(process.env.OP_MAINNET_RPC),
});
const walletClient = createWalletClient({
account,
chain: optimism,
transport: http(process.env.OP_MAINNET_RPC),
});
Chain Configuration
| Property | OP Mainnet | OP Sepolia |
|---|---|---|
| Chain ID | 10 | 11155420 |
| Currency | ETH | ETH |
| RPC | https://mainnet.optimism.io | https://sepolia.optimism.io |
| Explorer | https://optimistic.etherscan.io | https://sepolia-optimistic.etherscan.io |
| Block time | 2 seconds | 2 seconds |
| Withdrawal period | 7 days | ~12 seconds (testnet) |
Alternative RPCs
| Provider | Endpoint |
|---|---|
| Alchemy | https://opt-mainnet.g.alchemy.com/v2/<KEY> |
| Infura | https://optimism-mainnet.infura.io/v3/<KEY> |
| QuickNode | Custom endpoint per project |
| Conduit | https://rpc.optimism.io |
Deployment
OP Mainnet is EVM-equivalent. Deploy exactly as you would to Ethereum.
Foundry
# Deploy to OP Mainnet
forge create src/MyContract.sol:MyContract \
--rpc-url $OP_MAINNET_RPC \
--private-key $PRIVATE_KEY \
--broadcast
# Deploy with constructor args
forge create src/MyToken.sol:MyToken \
--rpc-url $OP_MAINNET_RPC \
--private-key $PRIVATE_KEY \
--constructor-args "MyToken" "MTK" 18 \
--broadcast
# Deploy via script
forge script script/Deploy.s.sol:DeployScript \
--rpc-url $OP_MAINNET_RPC \
--private-key $PRIVATE_KEY \
--broadcast \
--verify \
--etherscan-api-key $ETHERSCAN_API_KEY
Hardhat
// hardhat.config.ts
import { HardhatUserConfig } from "hardhat/config";
import "@nomicfoundation/hardhat-toolbox";
const config: HardhatUserConfig = {
solidity: "0.8.24",
networks: {
optimism: {
url: process.env.OP_MAINNET_RPC || "https://mainnet.optimism.io",
accounts: [process.env.PRIVATE_KEY!],
},
optimismSepolia: {
url: process.env.OP_SEPOLIA_RPC || "https://sepolia.optimism.io",
accounts: [process.env.PRIVATE_KEY!],
},
},
etherscan: {
apiKey: {
optimisticEthereum: process.env.ETHERSCAN_API_KEY!,
optimisticSepolia: process.env.ETHERSCAN_API_KEY!,
},
},
};
export default config;
npx hardhat run scripts/deploy.ts --network optimism
Verification
Foundry
# Verify after deployment
forge verify-contract <DEPLOYED_ADDRESS> src/MyContract.sol:MyContract \
--chain-id 10 \
--etherscan-api-key $ETHERSCAN_API_KEY
# Verify with constructor args
forge verify-contract <DEPLOYED_ADDRESS> src/MyToken.sol:MyToken \
--chain-id 10 \
--etherscan-api-key $ETHERSCAN_API_KEY \
--constructor-args $(cast abi-encode "constructor(string,string,uint8)" "MyToken" "MTK" 18)
Hardhat
npx hardhat verify --network optimism <DEPLOYED_ADDRESS> "MyToken" "MTK" 18
Blockscout
OP Mainnet also has a Blockscout explorer at https://optimism.blockscout.com. Verification works via the standard Blockscout API — set the verifier URL in Foundry:
forge verify-contract <DEPLOYED_ADDRESS> src/MyContract.sol:MyContract \
--verifier blockscout \
--verifier-url https://optimism.blockscout.com/api/
Cross-Chain Messaging
The CrossDomainMessenger is the canonical way to send arbitrary messages between L1 and L2. It handles replay protection, sender authentication, and gas forwarding.
Architecture
L1 → L2 (Deposits):
User → L1CrossDomainMessenger → OptimismPortal → L2CrossDomainMessenger → Target
L2 → L1 (Withdrawals):
User → L2CrossDomainMessenger → L2ToL1MessagePasser → [7 day wait] → OptimismPortal → L1CrossDomainMessenger → Target
L1 → L2 Message (Deposit)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IL1CrossDomainMessenger {
function sendMessage(
address _target,
bytes calldata _message,
uint32 _minGasLimit
) external payable;
}
contract L1Sender {
IL1CrossDomainMessenger public immutable messenger;
constructor(address _messenger) {
messenger = IL1CrossDomainMessenger(_messenger);
}
/// @notice Send a message from L1 to a contract on L2.
/// @param l2Target The L2 contract address to call.
/// @param message The calldata to send to the L2 target.
/// @param minGasLimit Minimum gas for L2 execution. Overestimate — unused gas is NOT refunded to L1.
function sendToL2(
address l2Target,
bytes calldata message,
uint32 minGasLimit
) external payable {
messenger.sendMessage{value: msg.value}(l2Target, message, minGasLimit);
}
}
L2 → L1 Message (Withdrawal)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface IL2CrossDomainMessenger {
function sendMessage(
address _target,
bytes calldata _message,
uint32 _minGasLimit
) external payable;
function xDomainMessageSender() external view returns (address);
}
contract L2Sender {
/// @dev L2CrossDomainMessenger predeploy address — same on all OP Stack chains
IL2CrossDomainMessenger public constant MESSENGER =
IL2CrossDomainMessenger(0x4200000000000000000000000000000000000007);
function sendToL1(
address l1Target,
bytes calldata message,
uint32 minGasLimit
) external payable {
MESSENGER.sendMessage{value: msg.value}(l1Target, message, minGasLimit);
}
}
Receiving Cross-Chain Messages
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
interface ICrossDomainMessenger {
function xDomainMessageSender() external view returns (address);
}
contract L2Receiver {
ICrossDomainMessenger public constant MESSENGER =
ICrossDomainMessenger(0x4200000000000000000000000000000000000007);
address public immutable l1Sender;
constructor(address _l1Sender) {
l1Sender = _l1Sender;
}
modifier onlyFromL1Sender() {
require(
msg.sender == address(MESSENGER) &&
MESSENGER.xDomainMessageSender() == l1Sender,
"Not authorized L1 sender"
);
_;
}
function handleMessage(uint256 value) external onlyFromL1Sender {
// Process the cross-chain message
}
}
Sender Aliasing
When an L1 contract sends a message to L2, the apparent msg.sender on L2 is the aliased address:
l2Sender = l1ContractAddress + 0x1111000000000000000000000000000000001111
The CrossDomainMessenger handles un-aliasing internally. If you bypass the messenger and send directly via OptimismPortal, you must account for aliasing yourself.
Predeploy Contracts
These contracts exist at genesis on every OP Stack chain. Do not deploy them — they are already there.
| Contract | Address | Purpose |
|---|---|---|
| L2ToL1MessagePasser | 0x4200000000000000000000000000000000000016 | Initiates L2→L1 withdrawals |
| L2CrossDomainMessenger | 0x4200000000000000000000000000000000000007 | Sends/receives cross-chain messages |
| L2StandardBridge | 0x4200000000000000000000000000000000000010 | Bridges ETH and ERC20 tokens |
| L2ERC721Bridge | 0x4200000000000000000000000000000000000014 | Bridges ERC721 tokens |
| GasPriceOracle | 0x420000000000000000000000000000000000000F | L1 data fee calculation |
| L1Block | 0x4200000000000000000000000000000000000015 | Exposes L1 block info on L2 |
| WETH9 | 0x4200000000000000000000000000000000000006 | Wrapped ETH |
| L1BlockNumber | 0x4200000000000000000000000000000000000013 | L1 block number (deprecated, use L1Block) |
| SequencerFeeVault | 0x4200000000000000000000000000000000000011 | Collects sequencer fees |
| BaseFeeVault | 0x4200000000000000000000000000000000000019 | Collects base fees |
| L1FeeVault | 0x420000000000000000000000000000000000001A | Collects L1 data fees |
| GovernanceToken | 0x4200000000000000000000000000000000000042 | OP token on L2 |
Reading L1 Block Info
interface IL1Block {
function number() external view returns (uint64);
function timestamp() external view returns (uint64);
function basefee() external view returns (uint256);
function hash() external view returns (bytes32);
function batcherHash() external view returns (bytes32);
function l1FeeOverhead() external view returns (uint256);
function l1FeeScalar() external view returns (uint256);
function blobBaseFee() external view returns (uint256);
function baseFeeScalar() external view returns (uint32);
function blobBaseFeeScalar() external view returns (uint32);
}
// Usage
IL1Block constant L1_BLOCK = IL1Block(0x4200000000000000000000000000000000000015);
uint64 l1BlockNumber = L1_BLOCK.number();
uint256 l1BaseFee = L1_BLOCK.basefee();
Gas Model
Every OP Mainnet transaction pays two fees:
- L2 execution fee — Standard EVM gas, priced by L2
basefee+ optional priority fee. Calculated identically to Ethereum. - L1 data fee — Cost of posting the transaction's data to Ethereum L1 as calldata or blob data. This is the OP-specific component.
Post-Ecotone Formula (Current)
After the Ecotone upgrade (March 2024), L1 data fee uses a two-component formula based on calldata gas and blob gas:
l1DataFee = (l1BaseFeeScalar * l1BaseFee * 16 + l1BlobBaseFeeScalar * l1BlobBaseFee) * compressedTxSize / 1e6
l1BaseFee— Ethereum L1 base fee (fromL1Blockpredeploy)l1BlobBaseFee— EIP-4844 blob base fee (fromL1Blockpredeploy)l1BaseFeeScalar— System-configured scalar for calldata cost componentl1BlobBaseFeeScalar— System-configured scalar for blob cost componentcompressedTxSize— Estimated compressed size of the signed transaction
GasPriceOracle
interface IGasPriceOracle {
/// @notice Estimate L1 data fee for raw signed transaction bytes
function getL1Fee(bytes memory _data) external view returns (uint256);
/// @notice Get current L1 base fee (read from L1Block)
function l1BaseFee() external view returns (uint256);
/// @notice Ecotone: get blob base fee
function blobBaseFee() external view returns (uint256);
/// @notice Ecotone: get base fee scalar
function baseFeeScalar() external view returns (uint32);
/// @notice Ecotone: get blob base fee scalar
function blobBaseFeeScalar() external view returns (uint32);
/// @notice Check if Ecotone is active
function isEcotone() external view returns (bool);
/// @notice Check if Fjord is active
function isFjord() external view returns (bool);
/// @notice Fjord: estimate compressed size using FastLZ
function getL1GasUsed(bytes memory _data) external view returns (uint256);
}
IGasPriceOracle constant GAS_ORACLE =
IGasPriceOracle(0x420000000000000000000000000000000000000F);
Estimating Total Cost in TypeScript
import { createPublicClient, http, parseAbi } from "viem";
import { optimism } from "viem/chains";
const client = createPublicClient({
chain: optimism,
transport: http(),
});
const GAS_ORACLE = "0x420000000000000000000000000000000000000F" as const;
const gasPriceOracleAbi = parseAbi([
"function getL1Fee(bytes memory _data) external view returns (uint256)",
"function l1BaseFee() external view returns (uint256)",
"function blobBaseFee() external view returns (uint256)",
"function baseFeeScalar() external view returns (uint32)",
"function blobBaseFeeScalar() external view returns (uint32)",
]);
async function estimateTotalCost(serializedTx: `0x${string}`) {
const [l2GasEstimate, gasPrice, l1DataFee] = await Promise.all([
client.estimateGas({ data: serializedTx }),
client.getGasPrice(),
client.readContract({
address: GAS_ORACLE,
abi: gasPriceOracleAbi,
functionName: "getL1Fee",
args: [serializedTx],
}),
]);
const l2ExecutionFee = l2GasEstimate * gasPrice;
const totalFee = l2ExecutionFee + l1DataFee;
return {
l2ExecutionFee,
l1DataFee,
totalFee,
};
}
Gas Optimization Tips
- Minimize calldata: the L1 data fee scales with transaction data size. Fewer bytes = lower L1 fee.
- Use
0bytes when possible: zero bytes cost 4 gas in calldata vs 16 gas for non-zero bytes. - Batch operations: one large transaction costs less in L1 data fee overhead than many small ones.
- After Ecotone, blob pricing makes L1 data fees much cheaper and more stable than pre-Ecotone calldata pricing.
Standard Bridge
The Standard Bridge enables ETH and ERC20 transfers between L1 and L2. It is a pair of contracts: L1StandardBridge on Ethereum and L2StandardBridge (predeploy) on OP Mainnet.
Bridge ETH: L1 → L2
interface IL1StandardBridge {
/// @notice Bridge ETH to L2. Appears at recipient address on L2 after ~1-3 min.
function depositETH(uint32 _minGasLimit, bytes calldata _extraData) external payable;
/// @notice Bridge ETH to a different address on L2.
function depositETHTo(
address _to,
uint32 _minGasLimit,
bytes calldata _extraData
) external payable;
}
Bridge ETH: L2 → L1
interface IL2StandardBridge {
/// @notice Initiate ETH withdrawal to L1. Requires prove + finalize after 7 days.
function withdraw(
address _l2Token,
uint256 _amount,
uint32 _minGasLimit,
bytes calldata _extraData
) external payable;
}
// Withdraw ETH from L2 to L1
// _l2Token = 0xDeadDeAddeAddEAddeadDEaDDEAdDeaDDeAD0000 (legacy ETH representation)
// Send ETH as msg.value, set _amount to the same value
Bridge ERC20: L1 → L2
interface IL1StandardBridge {
/// @notice Bridge ERC20 to L2. Token must have a corresponding L2 representation.
function depositERC20(
address _l1Token,
address _l2Token,
uint256 _amount,
uint32 _minGasLimit,
bytes calldata _extraData
) external;
function depositERC20To(
address _l1Token,
address _l2Token,
uint256 _amount,
address _to,
uint32 _minGasLimit,
bytes calldata _extraData
) external;
}
Bridge ERC20: L2 → L1
interface IL2StandardBridge {
function withdraw(
address _l2Token,
uint256 _amount,
uint32 _minGasLimit,
bytes calldata _extraData
) external payable;
function withdrawTo(
address _l2Token,
address _to,
uint256 _amount,
uint32 _minGasLimit,
bytes calldata _extraData
) external payable;
}
Withdrawal Lifecycle (L2 → L1)
Every L2→L1 withdrawal requires three L1 transactions:
- Initiate — Call
withdrawonL2StandardBridgeorL2CrossDomainMessenger. Produces a withdrawal hash. - Prove — After the L2 output root containing your withdrawal is proposed on L1 (~1 hour), call
proveWithdrawalTransactiononOptimismPortal. - Finalize — After the 7-day challenge period, call
finalizeWithdrawalTransactiononOptimismPortal.
import { getWithdrawals, getL2Output } from "viem/op-stack";
// After initiating withdrawal on L2, get the receipt
const l2Receipt = await publicClient.getTransactionReceipt({ hash: l2TxHash });
// Build withdrawal proof (after output root is proposed, ~1 hour)
const output = await getL2Output(l1Client, {
l2BlockNumber: l2Receipt.blockNumber,
targetChain: optimism,
});
// Prove on L1
const proveHash = await walletClient.proveWithdrawal({
output,
withdrawal: withdrawals[0],
targetChain: optimism,
});
// Wait 7 days, then finalize on L1
const finalizeHash = await walletClient.finalizeWithdrawal({
withdrawal: withdrawals[0],
targetChain: optimism,
});
SuperchainERC20
SuperchainERC20 is a cross-chain token standard enabling native token transfers between OP Stack chains in the Superchain. Tokens implementing this standard can move between chains without traditional bridge locking.
Interface
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {IERC20} from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @notice Interface for tokens that support cross-chain transfers within the Superchain.
interface ICrosschainERC20 {
/// @notice Emitted when tokens are minted via a cross-chain transfer.
event CrosschainMint(address indexed to, uint256 amount, address indexed sender);
/// @notice Emitted when tokens are burned for a cross-chain transfer.
event CrosschainBurn(address indexed from, uint256 amount, address indexed sender);
/// @notice Mint tokens on this chain as part of a cross-chain transfer.
/// @dev Only callable by the SuperchainTokenBridge.
function crosschainMint(address _to, uint256 _amount) external;
/// @notice Burn tokens on this chain to initiate a cross-chain transfer.
/// @dev Only callable by the SuperchainTokenBridge.
function crosschainBurn(address _from, uint256 _amount) external;
}
Implementation
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import {ICrosschainERC20} from "./ICrosschainERC20.sol";
/// @dev SuperchainTokenBridge predeploy address — same on all OP Stack chains
address constant SUPERCHAIN_TOKEN_BRIDGE = 0x4200000000000000000000000000000000000028;
contract MySuperchainToken is ERC20, ICrosschainERC20 {
constructor() ERC20("MySuperchainToken", "MST") {
_mint(msg.sender, 1_000_000 * 1e18);
}
function crosschainMint(address _to, uint256 _amount) external override {
require(msg.sender == SUPERCHAIN_TOKEN_BRIDGE, "Only bridge");
_mint(_to, _amount);
emit CrosschainMint(_to, _amount, msg.sender);
}
function crosschainBurn(address _from, uint256 _amount) external override {
require(msg.sender == SUPERCHAIN_TOKEN_BRIDGE, "Only bridge");
_burn(_from, _amount);
emit CrosschainBurn(_from, _amount, msg.sender);
}
}
Cross-Chain Transfer Flow
- User calls
SuperchainTokenBridge.sendERC20on the source chain - Bridge calls
crosschainBurnon the token contract (burns on source) - A cross-chain message is relayed to the destination chain
- Bridge calls
crosschainMinton the destination chain's token contract (mints on destination)
OP Stack
The OP Stack is the modular, open-source framework for building L2 blockchains. OP Mainnet, Base, Zora, Mode, and others are all OP Stack chains forming the Superchain.
Key Components
| Component | Description |
|---|---|
| op-node | Consensus client — derives L2 blocks from L1 data |
| op-geth | Execution client — modified go-ethereum |
| op-batcher | Posts transaction data to L1 (calldata or blobs) |
| op-proposer | Proposes L2 output roots to L1 |
| op-challenger | Runs fault proof games to challenge invalid proposals |
Superchain
The Superchain is a network of OP Stack chains sharing:
- Bridge contracts on L1
- Sequencer coordination
- Governance via the Optimism Collective
- Interoperability messaging
Current Superchain members include OP Mainnet, Base, Zora, Mode, Fraxtal, Metal, and others. All share the same upgrade path and security model.
Building a Custom OP Chain
Use the OP Stack to launch your own chain:
# Clone the optimism monorepo
git clone https://github.com/ethereum-optimism/optimism.git
cd optimism
# Install dependencies
pnpm install
# Configure your chain (edit deploy-config)
# Deploy L1 contracts
# Start op-node, op-geth, op-batcher, op-proposer
Refer to the OP Stack Getting Started Guide for complete chain deployment.
Governance
The Optimism Collective governs the protocol through a bicameral system:
- Token House — OP token holders vote on protocol upgrades, incentive programs, and treasury allocations
- Citizens' House — Soulbound "citizen" badges vote on retroactive public goods funding (RetroPGF)
OP Token
| Property | Value |
|---|---|
| Address (L2) | 0x4200000000000000000000000000000000000042 |
| Address (L1) | 0x4200000000000000000000000000000000000042 is the L2 predeploy; L1 address is 0x4200000000000000000000000000000000000042 bridged |
| Total supply | 4,294,967,296 (2^32) |
| Type | Governance only (no fee burn or staking yield) |
Delegation
OP token holders delegate voting power to active governance participants:
import { parseAbi } from "viem";
const opTokenAbi = parseAbi([
"function delegate(address delegatee) external",
"function delegates(address account) external view returns (address)",
"function getVotes(address account) external view returns (uint256)",
]);
const OP_TOKEN = "0x4200000000000000000000000000000000000042" as const;
// Delegate voting power
const hash = await walletClient.writeContract({
address: OP_TOKEN,
abi: opTokenAbi,
functionName: "delegate",
args: [delegateAddress],
});
Key Differences from Ethereum
| Feature | Ethereum | OP Mainnet |
|---|---|---|
| Block time | 12 seconds | 2 seconds |
| Gas pricing | Single base fee | L2 execution + L1 data fee |
block.number | L1 block number | L2 block number |
| Finality | ~15 minutes (2 epochs) | 7 days for L2→L1 (challenge period) |
| Sequencing | Decentralized validators | Centralized sequencer (OP Labs) |
PREVRANDAO | Beacon chain randomness | Sequencer-set value (NOT random, do NOT use for randomness) |
PUSH0 | Supported (Shanghai+) | Supported |
block.difficulty | Always 0 post-merge | Always 0 |
Opcodes Differences
PREVRANDAO(formerlyDIFFICULTY) — Returns the sequencer-set value, NOT true randomness. Never use for on-chain randomness. Use Chainlink VRF or a commit-reveal scheme.ORIGIN/CALLER— Work normally for L2 transactions. For L1→L2 deposits, theoriginis aliased (see Sender Aliasing).- All other opcodes behave identically to Ethereum.
Unsupported Features
- No native account abstraction (EIP-4337) — Use third-party bundlers (Pimlico, Alchemy, Stackup).
- No
eth_getProofwith pending block tag — Uselatestinstead.