Skip to content

Commit a2fbdfa

Browse files
committed
feat(create-l2-rollup): example code and enhanced docs
1 parent db0cd3a commit a2fbdfa

File tree

15 files changed

+1603
-138
lines changed

15 files changed

+1603
-138
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# OP Stack L2 Rollup Environment Configuration
2+
# Copy this file to .env and fill in your actual values
3+
# This uses direnv for automatic environment loading
4+
5+
# ==========================================
6+
# REQUIRED: L1 Configuration (Sepolia testnet)
7+
# ==========================================
8+
# Option 1: Public endpoint (no API key required - recommended for testing)
9+
L1_RPC_URL="https://ethereum-sepolia-rpc.publicnode.com"
10+
L1_BEACON_URL="https://ethereum-sepolia-beacon-api.publicnode.com"
11+
12+
# Option 2: Private endpoint (requires API key from Infura/Alchemy)
13+
# L1_RPC_URL="https://eth-sepolia.g.alchemy.com/v2/YOUR_API_KEY"
14+
# L1_BEACON_URL="https://ethereum-sepolia-beacon-api.publicnode.com"
15+
16+
# ==========================================
17+
# REQUIRED: Private Key for Deployment & Operations
18+
# ==========================================
19+
# IMPORTANT: Never commit this to version control!
20+
# Get this from your MetaMask or other self-custody wallet
21+
# Remove the 0x prefix if present
22+
PRIVATE_KEY="YOUR_PRIVATE_KEY_WITHOUT_0X_PREFIX"
23+
24+
# ==========================================
25+
# OPTIONAL: Public IP for P2P Networking
26+
# ==========================================
27+
# For local testing, defaults to 127.0.0.1
28+
# For production/testnet, run `curl ifconfig.me` to get your public IP
29+
P2P_ADVERTISE_IP="127.0.0.1"
30+
31+
# ==========================================
32+
# OPTIONAL: Custom Configuration
33+
# ==========================================
34+
# Default L2 Chain ID (can be any number between 10000-99999 for testing)
35+
L2_CHAIN_ID="16584"
36+
37+
# L1 Beacon API URL for op-node (usually same provider as L1_RPC_URL)
38+
L1_BEACON_URL="https://ethereum-sepolia-beacon-api.publicnode.com"
39+
40+
# ==========================================
41+
# ADVANCED: Component Environment Variables
42+
# ==========================================
43+
# These follow OP Stack conventions and can be overridden in the main .env file
44+
# The setup script creates service-specific .env files with these OP_* prefixed variables
45+
46+
# Batcher Environment Variables
47+
OP_BATCHER_POLL_INTERVAL="1s"
48+
OP_BATCHER_SUB_SAFETY_MARGIN="6"
49+
OP_BATCHER_NUM_CONFIRMATIONS="1"
50+
OP_BATCHER_SAFE_ABORT_NONCE_TOO_LOW_COUNT="3"
51+
52+
# Proposer Environment Variables
53+
OP_PROPOSER_PROPOSAL_INTERVAL="3600s"
54+
OP_PROPOSER_GAME_TYPE="0"
55+
OP_PROPOSER_POLL_INTERVAL="20s"
56+
57+
# ==========================================
58+
# DEVELOPMENT: Local Network (Alternative to Sepolia)
59+
# ==========================================
60+
# Uncomment these for local development with a local L1 network
61+
# L1_RPC_URL="http://host.docker.internal:8545"
62+
# L1_BEACON_URL="http://host.docker.internal:5052"
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Environment files
2+
.env
3+
.env.local
4+
**/.env
5+
6+
# Deployment artifacts
7+
deployer/
8+
9+
# Generated service directories
10+
sequencer/
11+
batcher/
12+
proposer/
13+
challenger/
14+
15+
# Optimism monorepo
16+
optimism/
17+
18+
# Downloaded binaries
19+
op-deployer
20+
21+
# Logs
22+
*.log
23+
logs/
24+
25+
# OS generated files
26+
.DS_Store
27+
.DS_Store?
28+
._*
29+
.Spotlight-V100
30+
.Trashes
31+
ehthumbs.db
32+
Thumbs.db
33+
34+
# IDE files
35+
.vscode/
36+
.idea/
37+
*.swp
38+
*.swo
39+
40+
# Node modules (if any)
41+
node_modules/
42+
43+
# Temporary files
44+
tmp/
45+
temp/

create-l2-rollup-example/Makefile

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# OP Stack L2 Rollup Makefile
2+
3+
.PHONY: help setup up down logs clean reset
4+
5+
# Default target
6+
help: ## Show this help message
7+
@echo "OP Stack L2 Rollup Management Commands:"
8+
@grep -E '^[a-zA-Z0-9_-]+:.*?## .*' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
9+
10+
setup: ## Deploy L1 contracts and configure rollup components
11+
mkdir -p deployer
12+
@if [ ! -f op-deployer ]; then \
13+
echo "❌ Error: op-deployer not found. Run 'make download' first."; \
14+
exit 1; \
15+
fi
16+
@if [ ! -f .env ]; then \
17+
echo "❌ Error: .env file not found. Copy .example.env to .env and configure it."; \
18+
exit 1; \
19+
fi
20+
@echo "Running setup script..."
21+
@./scripts/setup-rollup.sh
22+
23+
up: ## Start all services
24+
docker-compose up -d --wait
25+
@make test-l2
26+
27+
down: ## Stop all services
28+
docker-compose down
29+
30+
logs: ## View logs from all services
31+
docker-compose logs -f
32+
33+
logs-%: ## View logs from a specific service (e.g., make logs-sequencer)
34+
docker-compose logs -f $*
35+
36+
status: ## Show status of all services
37+
docker-compose ps
38+
39+
restart: ## Restart all services
40+
docker-compose restart
41+
42+
restart-%: ## Restart a specific service (e.g., make restart-batcher)
43+
docker-compose restart $*
44+
45+
clean: ## Remove all containers and volumes
46+
@# Create minimal env files if they don't exist to avoid docker-compose errors
47+
@mkdir -p batcher proposer challenger sequencer
48+
@echo "# Minimal env for cleanup" > batcher/.env 2>/dev/null || true
49+
@echo "# Minimal env for cleanup" > proposer/.env 2>/dev/null || true
50+
@echo "# Minimal env for cleanup" > challenger/.env 2>/dev/null || true
51+
docker-compose down -v --remove-orphans 2>/dev/null || true
52+
53+
reset: ## Complete reset - removes all data and redeploys
54+
@echo "This will completely reset your L2 rollup deployment!"
55+
@read -p "Are you sure? (y/N) " confirm && [ "$$confirm" = "y" ] || exit 1
56+
make clean
57+
rm -rf deployer sequencer batcher proposer challenger
58+
@echo "Reset complete. Run 'make setup' to redeploy."
59+
60+
test-l2: ## Test L2 connectivity
61+
@echo "Testing L2 RPC connection..."
62+
@curl -s -X POST -H "Content-Type: application/json" \
63+
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
64+
http://localhost:8545 | jq -r '.result' 2>/dev/null && echo "✅ L2 connection successful" || echo "❌ L2 connection failed"
65+
66+
test-l1: ## Test L1 connectivity
67+
@echo "Testing L1 RPC connection..."
68+
@if [ -f .env ]; then \
69+
set -a; source .env; set +a; \
70+
fi; \
71+
curl -s -X POST -H "Content-Type: application/json" \
72+
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
73+
"$$L1_RPC_URL" | jq -r '.result' 2>/dev/null && echo "✅ L1 connection successful" || echo "❌ L1 connection failed"
74+
75+
deps: ## Install development dependencies with mise (optional)
76+
mise install
77+
78+
download: ## Download op-deployer binary
79+
./scripts/download-op-deployer.sh
80+
81+
init: ## Initialize the project
82+
./scripts/download-op-deployer.sh
83+
@if [ ! -f .env ]; then \
84+
cp .example.env .env; \
85+
echo "Please edit .env with your actual configuration values"; \
86+
else \
87+
echo ".env already exists, skipping copy"; \
88+
fi
89+
@echo "Then run: make setup"

0 commit comments

Comments
 (0)