Guide to Setting Up an Ethereum Full Node with Geth

ยท

Ethereum full nodes are essential for interacting directly with the blockchain, enabling activities like verifying transactions, executing smart contracts, and accessing decentralized applications without relying on third-party services. This guide provides a comprehensive walkthrough for setting up a full node using Geth, the most widely used Ethereum execution client.

Running your own node offers enhanced security, privacy, and reliability. It allows you to contribute to the network's decentralization and resilience. The process involves configuring both an execution client (Geth) and a consensus client (Prysm) to work together in sync.

Prerequisites and System Requirements

Before starting the setup, ensure your system meets the necessary hardware and software requirements. A robust setup is crucial for handling the extensive data and continuous operations of an Ethereum node.

Recommended Server Configuration:

This configuration is designed to manage the substantial storage needs and processing power required for initial synchronization and ongoing block validation.

Step 1: Installing the Consensus Client (Prysm)

The Ethereum network relies on a proof-of-stake consensus mechanism. This requires running a consensus client alongside your execution client. We will use Prysm, a popular client implementation.

Updating the System and Installing Screen

First, update your system packages and install screen, a terminal multiplexer that allows you to run long-lived processes remotely.

For CentOS/RHEL-based systems:

yum update && yum upgrade -y
yum -y install screen

For Ubuntu/Debian-based systems:

apt-get update && apt-get upgrade -y
apt-get -y install screen

Downloading and Configuring Prysm

Create the necessary directories and download the Prysm installation script.

cd /data
mkdir -p eth consensus execution
cd consensus
mkdir prysm && cd prysm
curl https://raw.githubusercontent.com/prysmaticlabs/prysm/master/prysm.sh --output prysm.sh
chmod +x prysm.sh

Next, generate a JWT secret, which is used for secure communication between your execution and consensus clients.

./prysm.sh beacon-chain generate-auth-secret

This command will output the location of your jwt.hex file (e.g., /data/consensus/prysm/jwt.hex). Note this path, as it will be needed later.

Launching the Prysm Beacon Chain

Use a screen session to keep the Prysm client running in the background after you disconnect from your server.

screen -S prysm
./prysm.sh beacon-chain --accept-terms-of-use --execution-endpoint=http://localhost:8551 --jwt-secret=/data/consensus/prysm/jwt.hex --checkpoint-sync-url=https://beaconstate.info --genesis-beacon-api-url=https://beaconstate.info --datadir /data/execution

To detach from the screen session and leave Prysm running, press Ctrl+A followed by D. You can reattach to this session anytime with screen -r prysm.

Step 2: Deploying the Execution Client (Geth)

Geth (Go Ethereum) is the software that will actually sync and validate the Ethereum blockchain data.

Downloading and Preparing Geth

Navigate to your working directory and download the latest stable version of Geth for Linux. Always check the official Geth downloads page for the most recent version.

cd /data/eth
wget https://gethstore.blob.core.windows.net/builds/geth-linux-amd64-1.13.14-2bd6bd01.tar.gz
tar -xvf geth-linux-amd64-1.13.14-2bd6bd01.tar.gz
mv geth-linux-amd64-1.13.14-2bd6bd01 bin
mkdir chaindata

Starting the Geth Node

Launch Geth within another screen session. The flags and parameters are critical for proper operation and integration with your consensus client.

screen -S geth
/data/eth/bin/geth --cache 10240 --http --http.api web3,eth,net,personal,txpool,engine,admin --http.addr 0.0.0.0 --http.port 3545 --datadir /data/eth/chaindata --allow-insecure-unlock --rpc.allow-unprotected-txs --authrpc.addr 0.0.0.0 --authrpc.port 8551 --authrpc.vhosts localhost --maxpeers=300 --authrpc.jwtsecret /data/consensus/prysm/jwt.hex

Detach from this screen session using Ctrl+A followed by D.

Step 3: Monitoring Node Synchronization

Initial synchronization can take several days, depending on your hardware and internet speed. You can check the status of your Geth node using its built-in console.

Using the Geth Console

Attach to the Geth console to run diagnostic commands.

geth attach /data/eth/chaindata/geth.ipc

Once in the console, you can check the sync status and current block number.

> eth.syncing
false
> eth.blockNumber
19331520

If eth.syncing returns false, your node is fully synchronized. The eth.blockNumber shows the latest block your node has processed. Compare this number to the current block height on a public ETH block explorer to gauge your progress.

Checking Sync Status via HTTP-RPC

You can also query the node's status using a direct HTTP-RPC call.

curl --url http://localhost:3545 -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'

The response will include a result field with a hexadecimal value (e.g., "0x126f9ca"). Convert this hex value to a decimal number to see the block height.

Step 4: Creating a Systemd Service (Optional)

For a production environment, running Geth as a system service is more reliable than using screen. It allows for automatic restarts on failure and easier management.

Creating the Service File

Create a new service file with a text editor.

vim /usr/lib/systemd/system/geth.service

Add the following configuration to the file. Adjust flags and paths to match your setup.

[Unit]
Description=Go Ethereum Client - Geth
After=network.target
Wants=network.target

[Service]
User=root
Group=root
Type=simple
Restart=always
RestartSec=5
TimeoutStopSec=180
ExecStart=/data/eth/bin/geth \
        --snapshot=true \
        --http \
        --http.addr "0.0.0.0" \
        --http.port 9545 \
        --http.corsdomain "*" \
        --datadir /data/eth/chaindata \
        --http.api "personal,eth,net,web3,txpool,debug" \
        --maxpeers 100 \
        --cache 4096 \
        --txpool.globalslots 10000 \
        --txpool.globalqueue 2000 \
        --allow-insecure-unlock \
        --rpc.allow-unprotected-txs \
        --metrics \
        --metrics.expensive \
        --authrpc.jwtsecret /data/consensus/prysm/jwt.hex

[Install]
WantedBy=multi-user.target

Enabling and Starting the Service

Reload the systemd manager configuration, enable the service to start on boot, and then start it immediately.

systemctl daemon-reload
systemctl enable geth
systemctl start geth

You can check the status of the service and view logs using:

systemctl status geth
journalctl -u geth -f

Frequently Asked Questions

What is the difference between an archive node and a full node?

A full node only stores the most recent 128 blocks of state data, which is sufficient for validating new blocks and transactions. An archive node retains the entire history of all states since the genesis block, which is necessary for services like block explorers but requires significantly more storage (over 12 TB).

Why is my node syncing so slowly?

Slow sync times are often due to insufficient hardware, especially disk I/O. Using a slow HDD instead of an SSD is a common bottleneck. Additionally, a low number of peers or limited upload bandwidth can also slow down the process. Ensure your firewall allows incoming connections on the discovery ports (30303 by default for Geth).

How can I reduce Geth's disk space usage?

While you cannot reduce the space needed for a full node, you can enable garbage collection and pruning to manage growth. Using the --snapshot=false flag can save some space but will significantly impair performance. The best long-term solution is to ensure you have adequate storage capacity.

Is it safe to expose the HTTP-RPC port to the internet?

Exposing ports like 8545 or 9545 to the public internet is a significant security risk unless properly secured. It could allow attackers to access your node's functions. It is highly recommended to use a firewall to restrict access to these ports only to trusted IP addresses or to use reverse proxies with authentication. For most users, keeping them bound to 127.0.0.1 (localhost) is the safest practice.

What should I do if my node stops syncing or gets stuck?

First, check the logs for both Geth and Prysm using journalctl or by attaching to their screen sessions. Common fixes include restarting the clients, checking for available disk space, and ensuring you are using the latest stable client versions. Sometimes, adding more peer nodes manually can help. ๐Ÿ‘‰ Explore more strategies for troubleshooting common node issues.

Can I run a node on a different operating system like Windows or macOS?

Yes, Geth and Prysm have versions for Windows and macOS. The core concepts remain the same, but the installation process, directory paths, and service management will differ from this Linux-based guide. Always refer to the official documentation for instructions specific to your operating system.