Eridian
eridian.xyzx.comGitHub
  • 📖Eridian Docs
  • Ethereum Dev
    • ✏️Ethereum Notes
      • 🎛️Technical Basics
      • 🪧Ethereum Addresses
      • 📚Ethereum State Explained
      • ⛽Gas Fees Explained
    • 🔧Useful Tools
      • ☁️Ethers
      • *️⃣Ethernal
    • 📝Solidity Notes
      • ❔Interview Questions
        • 🟢1. Easy - Interview Questions
        • 🟠2. Medium - Interview Questions
        • 🟡3. Hard - Interview Questions
        • 🔴4. Advanced - Interview Questions
      • 💡Note Ideas
      • ABI
      • abi.encodePacked
      • Abstract Contracts
      • Arrays
      • Casting
      • CEI - Checks, Effects, Interactions
      • Comments (NATSPEC)
      • Constructor
      • Contract Structure & Versions
      • Data - Storage vs Memory
      • Data - Storage Layout
      • Enum
      • Errors (require & revert)
      • Events
      • EVM Opcodes
      • External Contract Interaction
      • 🏗️External Dependencies
      • Functions
      • Function Modifiers
      • If / Else / For / While Loops
      • Inheritance
      • Interfaces
      • Keccak256
      • Library
      • Mappings
      • msg.sender
      • Objects & Types
      • OpenZeppelin
      • Payable
      • Public State Variable vs Function
      • Receive & Fallback
      • Security
      • Self Destruct
      • Send ETH (transfer, send, call)
      • Stack Too Deep
      • Structs
      • Style Guide
      • Time Units
      • Try / Catch
      • Typecasting
      • Using Directive
      • Variables, Consts & Immutable
      • Withdraws
    • ⚒️Foundry Notes
      • 📖Docs & GitHub Pages
      • 🤝Useful Commands
        • 🔨Anvil
        • 🪄Cast
        • 🔥Forge
      • 🧪Tests
        • Cheatcodes
      • 📝Useful Scripts
        • Deploy Contract Using Hex
    • 👾DeFi Challenges
      • 👨‍🚀Ethernaut
        • Ethernaut - Template
        • Level 1 - Fallback ⏺
        • Level 2 - Fallout ⏺
        • Level 3 - Coin Flip ⏺⏺
        • Level 4 - Telephone ⏺
        • Level 5 - Token ⏺⏺
        • Level 6 - Delegation ⏺⏺
        • Level 7 - Force ⏺⏺⏺
        • Level 8 - Vault ⏺⏺
        • Level 9 - King ⏺⏺⏺
        • Level 10 - Re-entrancy ⏺⏺⏺
        • Level 11 - Elevator ⏺⏺
        • Level 12 - Privacy ⏺⏺⏺
        • Level 13 - Gatekeeper 1 ⏺⏺⏺⏺
        • Level 14 - Gatekeeper 2 ⏺⏺⏺
        • Level 15 - Naught Coin ⏺⏺⏺
        • Level 16 - Preservation ⏺⏺⏺⏺
        • Level 17 - Recovery ⏺⏺⏺
        • Level 18 - Magic Number ⏺⏺⏺
        • Level 19 - Alien Codex ⏺⏺⏺⏺
        • Level 20 - Denial ⏺⏺⏺
        • Level 21 - Shop ⏺⏺
        • Level 22 - Dex ⏺⏺
        • Level 23 - Dex Two ⏺⏺
        • Level 24 - Puzzle Wallet ⏺⏺⏺⏺
        • Level 25 - Motorbike ⏺⏺⏺
        • Level 26 - DoubleEntryPoint ⏺⏺
        • Level 27 - Good Samaritan ⏺⏺⏺
        • Level 28 - Gatekeeper 3 ⏺⏺⏺
        • Level 29 - Switch ⏺⏺⏺⏺
        • Level 30 - Higher Order ⏺⏺⏺⏺
        • Level 31 - Stake ⏺⏺⏺
      • 💸Damn Vulnerable DeFi
    • 🔍Auditing
      • 🗞️Exploit Resources
      • 🔧Audit Tools
    • 🤖MEV
  • Infrastructure Docs
    • 💻Hardware
    • 🐧Linux
      • 📖Linux Glossary
      • ⌨️Linux Commands
      • 💾Installation
      • 🏗️Maintenance
      • 🖥️Ubuntu Desktop
      • 🛜ZeroTier
      • 🎞️TMUX
      • 🔵Bluetooth
    • ⛓️Ethereum Clients
      • ⚙️Execution Clients
        • ⛏️Geth
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
        • 🐻Erigon
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
        • 🧶Besu
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • 🤝Beacon Clients
        • 💡Lighthouse
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
        • 🪅Teku
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • 💎Validator Clients
        • 💡Lighthouse
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • ➕L2 Clients
        • 🔵Base
          • 💾Installation
          • ⌨️Useful Commands
          • 🏗️Maintenance
      • 💰MEV Boost
        • 💾Installation
        • 🏗️Maintenance
    • 🚨Alerting and Monitoring
      • 🔥Prometheus
      • 🌡️HealthChecks.io
      • 📟PagerDuty
  • General Dev
    • 💾Git Notes
      • Repos
      • Committing changes
      • Branches
      • Merging & Rebasing
      • PRs
Powered by GitBook
On this page
  • Create Aliases
  • Firewall Configuration
  • Go - Install
  • Geth - Install
  • Geth - Configure Service
  • Geth - Command Aliases
  • Geth - Update Scripts
  • Geth - Configure JavaScript Console
Edit on GitHub
  1. Infrastructure Docs
  2. Ethereum Clients
  3. Execution Clients
  4. Geth

Installation

Geth client installation guide.

Create Aliases

These aliases make interacting with Geth on the command line easier.

echo "alias geth-log='journalctl -f -u geth.service -o cat | ccze -A'" >> ~/.bashrc
echo "alias geth-start='sudo systemctl start geth.service'" >> ~/.bashrc
echo "alias geth-stop='sudo systemctl stop geth.service'" >> ~/.bashrc
echo "alias geth-restart='sudo systemctl restart geth.service'" >> ~/.bashrc
echo "alias geth-status='sudo systemctl status geth.service'" >> ~/.bashrc
echo "alias geth-version='sudo /usr/local/bin/geth --version'" >> ~/.bashrc
echo "alias geth-config='sudo vim /etc/systemd/system/geth.service'" >> ~/.bashrc
echo "alias geth-enable='sudo systemctl enable geth.service'" >> ~/.bashrc
echo "alias geth-disable='sudo systemctl disable geth.service'" >> ~/.bashrc
echo "alias geth-delete-data='sudo rm -rf /var/lib/goethereum/geth'" >> ~/.bashrc
echo "alias geth-update='~/geth-update.sh'" >> ~/.bashrc

echo "alias geth-attach='sudo geth attach --preload ~/geth-console-script.js /var/lib/goethereum/geth.ipc'" >> ~/.bashrc
echo "alias geth-blockNumber='sudo geth --exec \"eth.blockNumber\" attach /var/lib/goethereum/geth.ipc'" >> ~/.bashrc
echo "alias geth-peerCount='sudo geth --exec \"net.peerCount\" attach /var/lib/goethereum/geth.ipc'" >> ~/.bashrc
echo "alias geth-nodeInfo='sudo geth --exec \"admin.nodeInfo\" attach /var/lib/goethereum/geth.ipc'" >> ~/.bashrc

source ~/.bashrc

Firewall Configuration

Go - Install

GO_LATEST_VERSION=    # Add the latest Go version here

cd ~/
wget https://go.dev/dl/go${GO_LATEST_VERSION}.linux-amd64.tar.gz
sudo rm -rf /usr/local/go && sudo tar -C /usr/local -xzf go${GO_LATEST_VERSION}.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
echo 'PATH="$PATH:/usr/local/go/bin"' >> ~/.profile

Geth - Install

Build the latest version of Geth.

GETH_VERSION_COMMIT_HASH=        # e.g.3f907d6

cd ~
git clone https://github.com/ethereum/go-ethereum.git
cd go-ethereum
git checkout ${GETH_VERSION_COMMIT_HASH}
make geth

Move the compiled Geth build to a new directory.

sudo cp ~/go-ethereum/build/bin/geth /usr/local/bin

Create Geth user and directory.

sudo useradd --no-create-home --shell /bin/false goeth
sudo mkdir -p /var/lib/goethereum

Geth - Configure Service

Set permissions.

sudo chown -R goeth:goeth /var/lib/goethereum

Configure Geth service using the command line flags.

sudo vim /etc/systemd/system/geth.service
/etc/systemd/system/geth.service
[Unit]
Description=Go Ethereum Client (Geth) - Execution Node
After=network.target
Wants=network.target

[Service]
User=goeth
Group=goeth
Type=simple
Restart=always
RestartSec=5
TimeoutStopSec=1200

EnvironmentFile=/etc/default/execution-variables.env

ExecStart=/usr/local/bin/geth \
    --${NETWORK} \
    --syncmode=snap \
    --port ${EXECUTION_P2P_PORT} \
    --discovery.port ${EXECUTION_P2P_PORT} \
    --datadir /var/lib/goethereum \
    \
    --pprof \
    --metrics \
    --metrics.expensive \
    --metrics.addr ${EXECUTION_METRICS_ADDR} \
    --metrics.port ${EXECUTION_METRICS_PORT} \
    \
    --authrpc.jwtsecret=/var/lib/jwtsecret \
    --maxpeers ${EXECUTION_MAX_PEERS} \
    \
    --ws \
    --ws.origins '*' \
    --ws.port ${EXECUTION_WS_PORT} \
    --ws.addr ${EXECUTION_WS_ADDR} \
    \
    --http \
    --http.api "db,eth,net,engine,rpc,web3" \
    --http.vhosts "*" \
    --http.corsdomain "*" \
    --http.addr ${EXECUTION_RPC_ADDR} \
    --http.port ${EXECUTION_RPC_PORT}

[Install]
WantedBy=default.target

/usr/local/bin/geth

Starts Geth.

--mainnet

Specifies mainnet as the target network.

--syncmode

  • full very/impossibly slow on Mainnet due to Shanghai DDOS attacks.

  • fast used to be the best option, but is now slower than snap.

  • snap the current fastest way to sync.

--port

Network listening port (TCP).

--discovery.port

UDP port for P2P discovery.

--http

Enable the HTTP-RPC server.

--datadir

Data directory for the databases and keystore.

--metrics

Enable metrics collection and reporting.

--metrics.expensive

Enable expensive metrics collection and reporting.

--pprof

Enable the pprof HTTP server.

Required for metrics to work properly.

--http.api

API's offered over the HTTP-RPC interface.

--authrpc.jwtsecret

--maxpeers

Maximum number of network peers.

  • Network disabled if set to 0.

  • Default: 50.

--cache

Megabytes of memory allocated to internal caching.

  • Default = 4096 mainnet full node and 128 light mode.

--bootnodes

Comma separated enode URLs for P2P discovery bootstrap.

Start the service and check it's working as expected.

Geth - Command Aliases

daemon-reload   # Reload any changes made to the geth.service
geth-enable     # Enable the geth.service
geth-start      # Start the geth.service
geth-status     # View the status of the geth.service

geth-log        # View the geth.service logs

Geth - Update Scripts

Create Geth update script.

vim ~/geth-update.sh
~/geth-update.sh
#!/bin/bash
set -e

while true; do
    read -p "Are you sure you want to update Geth? (Y/N) " yn
    case $yn in
        [Yy]* ) break;;
        [Nn]* ) exit;;
        * ) echo "Please answer Y or N.";;
    esac
done

cd ~/go-ethereum

read -p "Enter the commit hash you want to checkout: " commit_hash

git fetch
git checkout $commit_hash

echo
echo "**************"
echo "Making Geth..."
echo "**************"
make geth

# Check if geth.service is running
service_was_running=0
if sudo systemctl is-active --quiet geth.service; then
    service_was_running=1
    echo "****************"
    echo "Stopping Geth..."
    sudo systemctl stop geth.service
fi

echo "Replacing previous version..."
sudo rm -rf /usr/local/bin/geth
sudo cp ~/go-ethereum/build/bin/geth /usr/local/bin

# Only start geth.service if it was running originally
if [ $service_was_running -eq 1 ]; then
    echo "Restarting Geth..."
    echo "******************"
    sudo systemctl start geth.service
fi

Make the script executable.

chmod u+x ~/geth-update.sh

Geth - Configure JavaScript Console

Use --preload to load pre-written commands and functions stored in a script file.

vim ~/geth-console-script.js
~/geth-console-script.js
function blockInfo() {
    var blockInfo;
    web3.eth.getBlock(eth.blockNumber, function(e, r) { blockInfo = r; });
    return blockInfo;
}

Check Geth details by attaching to the JavaScript console

geth-attach

Geth JavaScript console commands.

eth.syncing
net.peerCount

Last updated 7 months ago

Configure the firewall using generic Execution client UFW settings:

Find the latest version of Go here:

JWT Secret is now shared between all clients on the same machine:

Configure .

⛓️
⚙️
⛏️
💾
https://go.dev/doc/install
https://github.com/ethereum/go-ethereum/blob/master/params/bootnodes.go
#ufw
Create JWT Secret
Execution Service Environment Variables