Giter Club home page Giter Club logo

run-a-geth-node's Introduction

Run-a-Geth-Node

Guide to setup your machine to join the Goerli/Prater merge testnet

Tech stack

  • Ubuntu 20.04

Prerequisites

Update the Software

# Install prerequisites commonly available.
sudo apt -y install software-properties-common wget curl
# Add the Ethereum PPA and install the Geth package.
sudo sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install ethereum

Installing Geth

Execution node

See : Installing Geth

sudo apt-get update
sudo apt-get install ethereum
#Check installation
geth โ€“-help

Beacon node : Connecting to Consensus Clients

"Geth is an execution client, Historically, an execution client alone was enough to run a full Ethereum node. However, ever since Ethereum swapped from proof-of-work (PoW) to proof-of-stake (PoS) based consensus, Geth has needed to be coupled to another piece of software called a "consensus client"."

See : Connecting to Consensus Clients

Install

Geth users are required to install and run a consensus client. Otherwise, Geth will not be able to track the head of the chain.

Client : Lighthouse

#datadir
cd ~/.ethereum/goerli
mkdir consensus
cd consensus
mkdir lighthouse && cd lighthouse
# Install lighthouse
wget https://github.com/sigp/lighthouse/releases/download/v3.5.1/lighthouse-v3.5.1-x86_64-unknown-linux-gnu.tar.gz
tar xvf lighthouse-v3.5.1-x86_64-unknown-linux-gnu.tar.gz
rm lighthouse-v3.5.1-x86_64-unknown-linux-gnu.tar.gz
#Test the binary
./lighthouse --version
# Generate JWT token file
openssl rand -hex 32 | tr -d "\n" > jwttoken
sudo chmod +r jwttoken

Running Geth & the Consensus Client

# Run Nodes on the terminal
# Run the execution client, by default :  --syncmode snap
geth --goerli --datadir /home/bjeab/.ethereum/goerli/ --http --http.api eth,net,web3,txpool,engine,admin --authrpc.jwtsecret /home/bjeab/.ethereum/goerli/consensus/lighthouse/jwttoken --metrics --metrics.expensive

You can create a Bash execute file, once done (Ctrl + X, Y, Enter)

cd ~
mkdir run
nano ~/run/geth.sh  
#[geth]
#!/bin/bash
geth --goerli --datadir /home/bjeab/.ethereum/goerli/ --http --http.api eth,net,web3,txpool,engine,admin --authrpc.jwtsecret /home/bjeab/.ethereum/goerli/consensus/lighthouse/jwttoken --metrics --metrics.expensive
# Run the beacon node using lighthouse
cd ~/.ethereum/goerli/consensus/lighthouse

./lighthouse bn --network goerli --execution-endpoint http://localhost:8551 --metrics --validator-monitor-auto --checkpoint-sync-url https://checkpoint-sync.goerli.ethpandaops.io --execution-jwt /home/bjeab/.ethereum/goerli/consensus/lighthouse/jwttoken --http --disable-deposit-contract-sync

You can also create a Bash execute file, once done (Ctrl + X, Y, Enter)

 nano ~/run/lighthouse.sh  
#[lighthouse]
#!/bin/bash
/home/bjeab/.ethereum/goerli/consensus/lighthouse/lighthouse bn --network goerli --execution-endpoint http://localhost:8551 --metrics --validator-monitor-auto --checkpoint-sync-url https://checkpoint-sync.goerli.ethpandaops.io --execution-jwt /home/bjeab/.ethereum/goerli/consensus/lighthouse/jwttoken --http --disable-deposit-contract-sync

Start with :

/bin/bash /home/bjeab/run/geth.sh
/bin/bash /home/bjeab/run/lighthouse.sh

Connect to the Geth console and extract last block number

Execution node sync status

geth version
geth --goerli attach

Watch the last block with this command:

> eth.getBlock('latest').number
8659221

If the value is 0, it's just charging blocks then use:

#To watch the current charged block
eth.syncing
#if false => it's updated

gethStatus

Connect to the Geth console and show events data from a specific transaction

Watch a specific transaction with this command:

# Tx is the transaction
eth.getTransaction("#Tx")

getTransaction

Create a quick Smart Contract and Interact with it

Configure hardhat to deploy a smart contract through your node

require("@nomicfoundation/hardhat-toolbox");
require("dotenv").config();
var API_KEY = process.env.API_KEY;
var PRIVATE_KEY = process.env.PRIVATE_KEY;
module.exports = {
  solidity: {
    version: "0.8.17",
    settings : {
      optimizer : {
        enabled: true,
        runs: 200
      }
    },
  },
  networks: {
    goerli: {
      url:`https://goerli.infura.io/v3/${API_KEY}`,
      //url: `https://eth-goerli.g.alchemy.com/v2/${API_KEY}`,
      chainId: 5,
      accounts :[`${PRIVATE_KEY}`],
    },
    goerliPvNode: {
      url:`http://localhost:8545`,
      //url: `https://eth-goerli.g.alchemy.com/v2/${API_KEY}`,
      chainId: 5,
      accounts :[`${PRIVATE_KEY}`],
    },
    mumbai: {
      url:`https://polygon-mumbai.infura.io/v3/${API_KEY}`,
      //url:`https://polygon-mumbai.g.alchemy.com/v2/${API_KEY}`,
      chainId: 80001,
      accounts :[`${PRIVATE_KEY}`],
    },
  },
  gasReporter: {
    enabled: true,
    currency: 'USD',
    gasPrice: 21
  }
};
# Deploy contract
npx hardhat run scripts/deploy.js --network goerliPvNode
#response
network goerliPvNode
0x0591F951415Dc471Aa948A49E9Fe752ACB028E9B
Tokenization address: 0x10E0640875817EeFe75F3414522Ae9faa334BFca

Smart Contract addresse 0x10E0640875817EeFe75F3414522Ae9faa334BFca

Configuring Geth

See : Configuring Geth

Turning Geth into a service

Create a systemd service config file to configure the Geth node service

sudo nano /etc/systemd/system/geth.service

Paste this configuration file into it and save once done (Ctrl + X, Y, Enter):

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

[Service]
Type=simple
Restart=always
RestartSec=5
TimeoutStopSec=180
ExecStart=geth \
    --goerli \
    --http \
    --http.api eth,net,web3,txpool,engine,admin \
    --datadir /home/bjeab/.ethereum/goerli/ \
    --metrics \
    --metrics.expensive \
    --pprof \
    --authrpc.jwtsecret=/home/bjeab/.ethereum/goerli/consensus/lighthouse/jwttoken

[Install]
WantedBy=default.target
#(reload to reflect the changes)
sudo systemctl daemon-reload
#(lauch)
sudo systemctl start geth.service
#(check)
sudo systemctl status geth.service
#(to stop/restart)
sudo systemctl stop geth.service
sudo systemctl restart geth.service
#(You can enable/disable the geth service to automatically start on reboot)
sudo systemctl enable geth.service
sudo systemctl disable geth.service

To monitor you can check the geth.service status with :

systemctl status geth
#Or
journalctl -fu geth
sudo journalctl -f -u geth.service -o cat | ccze -A
#Press Ctrl + C to stop showing those messages.

gethService

Turning Lighthouse into a service

Create a systemd service config file to configure the Lighthouse consensus node service

sudo nano /etc/systemd/system/lighthouse.service

Paste this configuration file into it and save once done (Ctrl + X, Y, Enter):

[Unit]
Description=Lighthouse Ethereum Client Beacon Node (Prater)
Wants=network-online.target
After=network-online.target

[Service]
Type=simple
Restart=always
RestartSec=5
ExecStart=/home/bjeab/.ethereum/goerli/consensus/lighthouse/lighthouse bn \
    --network goerli \
    --datadir /home/bjeab/.ethereum/goerli/ \
    --http \
    --execution-endpoint http://localhost:8551 \
    --checkpoint-sync-url https://checkpoint-sync.goerli.ethpandaops.io \
    --execution-jwt /home/bjeab/.ethereum/goerli/consensus/lighthouse/jwttoken \
    --metrics \
    --validator-monitor-auto \
    --disable-deposit-contract-sync

[Install]
WantedBy=multi-user.target
#(reload to reflect the changes)
sudo systemctl daemon-reload
#(lauch)
sudo systemctl start lighthouse.service
#(check)
sudo systemctl status lighthouse.service
#(to stop/restart)
sudo systemctl stop lighthouse.service
sudo systemctl restart lighthouse.service
#(You can enable/disable the lighthouse service to automatically start on reboot)
sudo systemctl enable lighthouse.service
sudo systemctl disable lighthouse.service

To monitor you can check the lighthouse.service status with :

systemctl status lighthouse
#Or
journalctl -fu lighthouse
sudo journalctl -f -u lighthouse.service -o cat | ccze -A 
#Press Ctrl + C to stop showing those messages.

lighthouseService

Documentation

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.