Run a Full OP Node

This guide will walk you through the process of building a node from source, focusing on the op-node and op-geth implementations. These steps are essential if you want to run a node on a specific architecture or inspect the source code of the node you're running.

What you're going to Build

  1. Rollup Node (op-node)

    • Responsible for deriving L2 block payloads from L1 data and passing those payloads to the Execution Client.

    • Analogous to a consensus client in Ethereum.

  2. Execution Client (op-geth)

    • Executes the block payloads it receives from the Rollup Node.

    • Exposes the standard JSON-RPC API used by Ethereum developers.

Software Dependencies

git

^2

git --version

go

^1.21

go version

node

^20

node --version

pnpm

^8

pnpm --version

foundry

^0.2.0

forge --version

make

^4

make --version

Folder Structure

This guide supports running nodes for arbitrary Gelato RaaS chains, both testnets, and mainnets. Feel free to use any folder structure that suits your needs. For the purposes of this documentation, we will use the following structure below:

op-full-node/
├── config/
│   ├── testnet/
│   │   ├── genesis.json
│   │   └── rollup.json
│   ├── mainnet/
│   │   ├── genesis.json
│   │   └── rollup.json
├── op-geth/
│   ├── init-geth.sh
│   ├── jwt.txt
│   ├── .env
│   └── ...
├── optimism/
│   ├── jwt.txt
│   ├── .env
│   ├── op-node
│   └── ...
└── jwt.txt

Create a JWT file

To communicate with op-node and enable the Engine API, you'll also need to generate a JWT secret file and enable Geth's authenticated RPC endpoint.

To generate the JWT secret, run the following:

cd /path/to/op-full-node
openssl rand -hex 32 > jwt.txt

Obtain genesis.json and rollup.json

  1. Log in to your Dashboard.

  2. Download rollup.json (rollup config) and genesis.json (genesis config).

  3. Place them in your config/testnet in the op-full-node directory

Build the Rollup Node

  • Clone the Optimism Monorepo:

    git clone https://github.com/ethereum-optimism/optimism.git
    cd optimism
  • Check Out the Required Release Tag:

    git checkout <name of release tag>
    ## We use the latest official release tagged in the GitHub repo https://github.com/ethereum-optimism/optimism/releases
    
    ## final command
    git checkout ddc37daa49558c2fb5c1a92e694eeb7de5942e00
  • Install Node.js Dependencies:

    pnpm install
  • Build Node.js Packages:

    pnpm build
  • Build op-node:

    make op-node

Build the Execution Client

  • Clone op-geth:

    git clone https://github.com/ethereum-optimism/op-geth.git
    cd op-geth
  • Check Out the Required Release Tag:

    git checkout <name of release tag>
    ##We use the latest official release tagged in the GitHub repo https://github.com/ethereum-optimism/op-geth/releases
    git checkout 7c2819836018bfe0ca07c4e4955754834ffad4e0
    
  • Build op-geth:

    make geth

Running op-geth

Create a Data directory in your op-geth

cd /path/to/op-full-node/op-geth
mkdir data-geth

Create a .env File in op-geth Directory

cd /path/to/op-full-node/op-geth
nano .env
# WebSocket configuration
GETH_WS=true
GETH_WS_PORT=8546
GETH_WS_ADDR=localhost
GETH_WS_ORIGINS="*"

# HTTP configuration
GETH_HTTP=true
GETH_HTTP_PORT=8545
GETH_HTTP_ADDR=localhost
GETH_HTTP_VHOSTS="*"
GETH_HTTP_CORSDOMAIN="*"

# Authenticated RPC configuration
GETH_AUTHRPC_ADDR=localhost
GETH_AUTHRPC_JWTSECRET=/var/secrets/jwt.txt
GETH_AUTHRPC_PORT=8551
GETH_AUTHRPC_VHOSTS="*"

# Data directory
GETH_DATADIR=/data

# Logging verbosity
GETH_VERBOSITY=3

# Rollup configuration
GETH_ROLLUP_DISABLETXPOOLGOSSIP=true
GETH_ROLLUP_SEQUENCERHTTP=https://mainnet-sequencer.optimism.io/

# OP network
GETH_OP_NETWORK=op-mainnet

Initialize op-geth with the Genesis File

Feel free to customize the base configurations provided in the Optimism documentation to suit your specific requirements. While we will use the recommended configurations for this guide, you can explore and add additional flags as needed. Detailed information about execution layer configurations can be found here.

Create init-geth.sh:

cd /path/to/op-full-node/op-geth
nano init-geth.sh
#!/bin/bash

# Set environment variables
source .env

# Create data directory if it doesn't exist
mkdir -p $DATADIR_PATH

# Initialize geth with the genesis file
echo "Initializing geth with genesis file..."
./build/bin/geth --datadir=$DATADIR_PATH init $GENESIS_PATH

# Generate JWT secret if it doesn't exist
if [ ! -f "$JWT_SECRET_PATH" ]; then
  echo "Generating JWT secret..."
  openssl rand -hex 32 > $JWT_SECRET_PATH
fi

Run the geth Node

cd /path/to/op-full-node/op-geth

# Load environment variables from the .env file in the root directory
source .env

# Initialize geth
./init-geth.sh

# Run the geth command with the environment variables
./build/bin/geth

Testing the Running Geth Instance

After starting your geth instance, you can use the following bash script to test if geth is running and to confirm the chain ID:

curl -X POST http://127.0.0.1:8545 \
-H "Content-Type: application/json" \
--data '{"method":"eth_chainId","params":[],"id":1,"jsonrpc":"2.0"}'

##You should see a response similar to this
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": "0x2a88" ##This is your chain id in hex, in this case its 10888.
}

Running op-node

We will utilize the base configurations provided in the Optimism documentation for the consensus layer. However, you can adjust and expand these configurations to fit your specific requirements. For a comprehensive understanding of all available configurations, refer to the detailed documentation on consensus layer configurations here.

Create a .env File in optimism Directory

# Ethereum Mainnet RPC URL
OP_NODE_L1_ETH_RPC="<ethereum mainnet RPC url>"

# Authenticated RPC URL for op-geth
OP_NODE_L2_ENGINE_RPC="<op-geth authenticated RPC url>"

# RPC address for the op-node
OP_NODE_RPC_ADDR="0.0.0.0"

# RPC port for the op-node
OP_NODE_RPC_PORT="9545"

# Path to JWT secret file
OP_NODE_L2_ENGINE_AUTH="<path to JWT secret>"

# HTTP endpoint address of L1 Beacon-node
OP_NODE_L1_BEACON="<http endpoint address of L1 Beacon-node>"

# Synchronization mode
OP_NODE_SYNCMODE="execution-layer"

# Engine kind for L2
OP_NODE_L2_ENGINE_KIND="geth"

Run the op-node

cd /path/to/op-full-node/optimism

# Load environment variables from the .env file in the root directory
source .env

# Run the op-node command with the environment variables
./op-node/bin/op-node

Last updated