Skip to main content

Ethereum Mainnet Commands

This page provides useful commands for managing your Ethereum node on the mainnet. These commands help you monitor synchronization, troubleshoot issues, and maintain your node effectively.

Node Status and Synchronization

Check Geth (Execution Layer) Sync Status

# Check if Geth is syncing
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":1}' \
http://localhost:8545

# Expected response when synced: {"jsonrpc":"2.0","id":1,"result":false}
# Expected response when syncing: {"jsonrpc":"2.0","id":1,"result":{"startingBlock":"0x0","currentBlock":"0x12345","highestBlock":"0x23456"}}

# Get current block number
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
http://localhost:8545

# Get network peer count
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"net_peerCount","params":[],"id":1}' \
http://localhost:8545

# Check Geth version
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":1}' \
http://localhost:8545

Check Lighthouse (Consensus Layer) Sync Status

# Check beacon chain sync status
curl http://localhost:5052/eth/v1/node/syncing

# Expected response when synced: {"data":{"head_slot":"123456","sync_distance":"0","is_syncing":false}}

# Get node info
curl http://localhost:5052/eth/v1/node/identity

# Check peer connections
curl http://localhost:5052/eth/v1/node/peers | jq '.data | length'

# Get beacon chain head
curl http://localhost:5052/eth/v1/beacon/headers/head

# Check node health
curl http://localhost:5052/eth/v1/node/health

Check Prysm (Alternative Consensus Client) Sync Status

# Check Prysm beacon chain sync
curl http://localhost:3500/eth/v1/node/syncing

# Get Prysm node identity
curl http://localhost:3500/eth/v1/node/identity

# Check Prysm peers
curl http://localhost:3500/eth/v1/node/peers

# Prysm validator status (if running validator)
curl http://localhost:7500/eth/v1/validator/duties/attester/123456

Service Management Commands

Systemd Service Controls

# Check service status
sudo systemctl status geth
sudo systemctl status lighthouse-beacon
sudo systemctl status lighthouse-validator # if running validator
sudo systemctl status prysm-beacon # if using Prysm

# Start services
sudo systemctl start geth
sudo systemctl start lighthouse-beacon

# Stop services
sudo systemctl stop geth
sudo systemctl stop lighthouse-beacon

# Restart services
sudo systemctl restart geth
sudo systemctl restart lighthouse-beacon

# Enable auto-start on boot
sudo systemctl enable geth
sudo systemctl enable lighthouse-beacon

# View service logs
sudo journalctl -u geth -f
sudo journalctl -u lighthouse-beacon -f
sudo journalctl -u geth --since "1 hour ago"
sudo journalctl -u lighthouse-beacon --since "1 hour ago"

Geth HTTP API Configuration

API Modules and CORS Settings

# Geth HTTP API configuration parameters:

# --http.api: Specify which API modules to enable
# Available modules: admin, debug, eth, miner, net, personal, txpool, web3, clique, les

# Basic API setup (recommended for most users)
--http.api "eth,net,web3"

# Extended API setup (for developers and advanced users)
--http.api "eth,net,web3,personal,admin,debug,txpool"

# CORS (Cross-Origin Resource Sharing) configuration
# Allow specific domain
--http.corsdomain "https://yourdomain.com"

# Allow multiple domains
--http.corsdomain "https://yourdomain.com,https://anotherdomain.com"

# Allow all domains (development only - not recommended for production)
--http.corsdomain "*"

# Virtual hosts configuration
--http.vhosts "localhost,yourdomain.com"
--http.vhosts "*" # Allow all hosts (development only)

# WebSocket API configuration
--ws.api "eth,net,web3"
--ws.origins "*" # Allow all origins for WebSocket

# Complete Geth startup command with CORS and API configuration
geth \
--mainnet \
--datadir /data/ethereum/geth \
--http \
--http.addr "0.0.0.0" \
--http.port 8545 \
--http.api "eth,net,web3,personal" \
--http.corsdomain "*" \
--http.vhosts "*" \
--ws \
--ws.addr "0.0.0.0" \
--ws.port 8546 \
--ws.api "eth,net,web3" \
--ws.origins "*" \
--authrpc.addr "127.0.0.1" \
--authrpc.port 8551 \
--authrpc.jwtsecret /data/ethereum/jwt.hex

Test CORS Configuration

# Test CORS from browser console or curl
curl -H "Origin: https://yourdomain.com" \
-H "Access-Control-Request-Method: POST" \
-H "Access-Control-Request-Headers: X-Requested-With" \
-X OPTIONS \
http://localhost:8545

# Test API access from different origin
curl -X POST \
-H "Content-Type: application/json" \
-H "Origin: https://yourdomain.com" \
--data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' \
http://localhost:8545

Network and Connectivity

Check Network Connectivity

# Check if ports are open and listening
sudo ss -tulpn | grep -E ':8545|:8546|:30303|:5052|:9000'

# Test HTTP RPC endpoint
curl -I http://localhost:8545

# Test WebSocket endpoint (requires wscat)
# Install: npm install -g wscat
echo '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' | wscat -c ws://localhost:8546

# Check P2P connections
# For Geth
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"admin_peers","params":[],"id":1}' \
http://localhost:8545

# Test external connectivity
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"net_listening","params":[],"id":1}' \
http://localhost:8545

Network Diagnostics

# Check internet connectivity
ping -c 3 8.8.8.8

# Check DNS resolution
nslookup ethereum.org

# Test connectivity to Ethereum bootnodes
ping -c 3 bootnode.ethereum.org

# Check bandwidth usage
iftop -i eth0 # Replace eth0 with your network interface

# Monitor network connections
sudo netstat -tuln | grep -E ':8545|:8546|:30303|:5052|:9000'

Performance Monitoring

Resource Usage

# Check disk usage
df -h /data/ethereum
du -sh /data/ethereum/geth/chaindata
du -sh /data/ethereum/lighthouse/beacon

# Monitor real-time disk usage
watch -n 5 'df -h /data/ethereum'

# Check memory usage
free -h
ps aux | grep -E 'geth|lighthouse|prysm' | grep -v grep

# Monitor CPU usage
top -p $(pgrep geth),$(pgrep lighthouse)
htop

# Check I/O usage
sudo iotop -a

Database and State Information

# Get Geth database info
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"debug_dbProperty","params":["leveldb.stats"],"id":1}' \
http://localhost:8545

# Get state trie info
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"debug_traceBlockByNumber","params":["latest", {"tracer": "callTracer"}],"id":1}' \
http://localhost:8545

# Check gas price
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_gasPrice","params":[],"id":1}' \
http://localhost:8545

# Get latest block info
curl -X POST -H "Content-Type: application/json" \
--data '{"jsonrpc":"2.0","method":"eth_getBlockByNumber","params":["latest", false],"id":1}' \
http://localhost:8545

Validator Commands (If Running Validator)

Lighthouse Validator Management

# Check validator status
curl http://localhost:5062/lighthouse/health

# Get validator duties
curl http://localhost:5052/eth/v1/validator/duties/attester/$(curl -s http://localhost:5052/eth/v1/beacon/headers/head | jq -r '.data.header.message.slot')

# Check validator balance
lighthouse account validator list --datadir /data/ethereum/lighthouse

# Import validator keys
lighthouse account validator import \
--directory /path/to/validator/keys \
--datadir /data/ethereum/lighthouse

# Check slashing protection
lighthouse account validator slashing-protection export \
--file /tmp/slashing-protection.json \
--datadir /data/ethereum/lighthouse

Prysm Validator Management

# Check Prysm validator status
curl http://localhost:7500/eth/v1/validator/health

# Get validator performance
curl http://localhost:7500/eth/v1/validator/performance

# Import validator keys to Prysm
prysm validator accounts import \
--keys-dir /path/to/validator/keys \
--wallet-dir /data/ethereum/prysm/wallet

# List validator accounts
prysm validator accounts list \
--wallet-dir /data/ethereum/prysm/wallet

Troubleshooting Commands

Common Issues and Diagnostics

# Check if services are running
systemctl is-active geth lighthouse-beacon

# Check service dependencies
systemctl list-dependencies geth

# Verify configuration files
# For Geth (if using config file)
geth dumpconfig --mainnet

# Check JWT secret file
ls -la /data/ethereum/jwt.hex
cat /data/ethereum/jwt.hex | wc -c # Should be 65 characters

# Verify data directory permissions
ls -la /data/ethereum/
sudo chown -R ethereum:ethereum /data/ethereum/

# Check firewall rules
sudo ufw status numbered
sudo iptables -L -n

# Test localhost connectivity
curl http://127.0.0.1:8545
curl http://127.0.0.1:5052/eth/v1/node/health

Log Analysis

# Search for errors in logs
sudo journalctl -u geth | grep -i error
sudo journalctl -u lighthouse-beacon | grep -i error

# Search for specific patterns
sudo journalctl -u geth | grep -i "sync"
sudo journalctl -u lighthouse-beacon | grep -i "peer"

# Follow logs with filtering
sudo journalctl -u geth -f | grep -E "error|warn|fatal"

# Export logs for analysis
sudo journalctl -u geth --since "24 hours ago" > geth_logs.txt
sudo journalctl -u lighthouse-beacon --since "24 hours ago" > lighthouse_logs.txt

# Check log sizes
sudo journalctl --disk-usage

Database Maintenance

# Stop services before maintenance
sudo systemctl stop lighthouse-beacon geth

# Check database integrity (Geth)
geth removedb --datadir /data/ethereum/geth # WARNING: This removes all data

# Compact database (if supported)
geth snapshot verify-state --datadir /data/ethereum/geth

# Clean up old logs
sudo journalctl --vacuum-time=7d
sudo journalctl --vacuum-size=1G

# Restart services after maintenance
sudo systemctl start geth
sleep 30 # Wait for Geth to start
sudo systemctl start lighthouse-beacon

Quick Reference

Essential Commands

CommandPurpose
curl http://localhost:8545Test Geth HTTP endpoint
curl http://localhost:5052/eth/v1/node/healthTest Lighthouse health
sudo systemctl status geth lighthouse-beaconCheck service status
sudo journalctl -u geth -fFollow Geth logs
df -h /data/ethereumCheck disk usage

Port Reference

ServicePortPurpose
Geth HTTP8545JSON-RPC API
Geth WebSocket8546WebSocket API
Geth P2P30303Peer-to-peer networking
Geth Auth8551Engine API (JWT authenticated)
Lighthouse HTTP5052Beacon API
Lighthouse P2P9000Beacon P2P networking
Lighthouse Validator5062Validator API

Sync Status Indicators

StatusGethLighthouse
Syncingeth_syncing returns objectis_syncing: true
Syncedeth_syncing returns falseis_syncing: false
BehindcurrentBlock < highestBlocksync_distance > 0
CurrentcurrentBlock == highestBlocksync_distance == 0

info

These commands are for the Ethereum mainnet. Monitor your node regularly and ensure it stays synchronized with the network.

tip

Best Practices:

  • Monitor logs regularly for errors or warnings
  • Check sync status before making transactions
  • Ensure adequate disk space for continued operation
  • Keep your clients updated to the latest versions
  • Use monitoring tools like Grafana for better visibility