How to Securely Setup an Ethereum Node

published 2021-09-06 Β· updated 2022-08-23 #crypto #how_to
This guide will show you exactly how to setup and Ethereum Node. Nodes contribute processing power and resources to the Ethereum network.


sudo add-apt-repository -y ppa:ethereum/ethereum
sudo apt-get update
sudo apt-get install geth

Add ethereum repository and install geth – Link to section in video

sudo useradd --no-create-home --shell /bin/false user_name_goes_here

Create new user – Link to section in video

cat /etc/passwd | grep user_name_goes_here

Verify user was created

pwd

Print current directory

mkdir -p /your/path/chain/data

Create data directory – Link to section in video

sudo chown -R user_name_goes_here:user_name_goes_here /your/path/chain/data

Grant new user access to new folder – Link to section in video

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

Open the service file with gedit – Link to section in video


[Unit]
Description=Go Ethereum Client
After=network.target
Wants=network.target
[Service]
User=user_name_goes_here
Group=group_name_goes_here
Type=simple
Restart=always
RestartSec=5
ExecStart=geth --datadir /your/path/chain/data --port your_port --syncmode "full" --cache=1024 --http --metrics --maxpeers 30
[Install]
WantedBy=default.target

Service file contents – Link to section in video


sudo systemctl daemon-reload

Reload service daemon

sudo systemctl start geth

Start the service – Link to section in video

sudo systemctl status geth

Check the service status – Link to section in video

sudo journalctl -fu geth.service

Show service logs – Link to section in video

sudo systemctl enable geth

Enable service to start at boot – Link to section in video

sudo systemctl disable geth

Disable service to start at boot

sudo geth attach --datadir /your/path/chain/data

Attach to geth service – Link to section in video

eth.syncing

Show ethereum syncing status


var lastPercentage = 0;var lastBlocksToGo = 0;var timeInterval = 10000;
setInterval(function(){
    var percentage = eth.syncing.currentBlock/eth.syncing.highestBlock*100;
    var percentagePerTime = percentage - lastPercentage;
    var blocksToGo = eth.syncing.highestBlock - eth.syncing.currentBlock;
    var bps = (lastBlocksToGo - blocksToGo) / (timeInterval / 1000)
    var etas = 100 / percentagePerTime * (timeInterval / 1000)

    var etaM = parseInt(etas/60,10);
    console.log(parseInt(percentage,10)+'% ETA: '+etaM+' minutes @ '+bps+'bps');

    lastPercentage = percentage;lastBlocksToGo = blocksToGo;
},timeInterval);

Sync status script