Skip to content

0G validator node

0G banner”

# Hardware requirements

We recommend the following hardware specifications:

CharacteristicSpecification
Operating SystemUbuntu 18.04 or later LTS
Number of CPUs8
RAM64GB
Storage1TB NVMe SSD
Bandwidth100mps for Download / Upload
System updates
Terminal window
sudo apt update
sudo apt install curl git make jq build-essential gcc unzip wget lz4 aria2 -y
Install Go
Terminal window
cd $HOME && \
ver="1.22.0" && \
wget "https://golang.org/dl/go$ver.linux-amd64.tar.gz" && \
sudo rm -rf /usr/local/go && \
sudo tar -C /usr/local -xzf "go$ver.linux-amd64.tar.gz" && \
rm "go$ver.linux-amd64.tar.gz" && \
[ ! -f ~/.bash_profile ] && touch ~/.bash_profile && \
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> ~/.bash_profile && \
source ~/.bash_profile && \
go version
Git clone
Terminal window
cd $HOME
rm -rf 0g-chain
git clone https://github.com/0glabs/0g-chain.git
cd 0g-chain
git checkout v0.4.0
git submodule update --init
make install
0gchaind version
Variable settings
Terminal window
echo "export WALLET='josephtran'" >> $HOME/.bash_profile
echo "export MONIKER='JosephTran'" >> $HOME/.bash_profile
echo "export OG_CHAIN_ID='zgtendermint_16600-2'" >> $HOME/.bash_profile
echo "export OG_PORT='26'" >> $HOME/.bash_profile
source $HOME/.bash_profile
Node init
Terminal window
0gchaind config keyring-backend os
0gchaind config chain-id $OG_CHAIN_ID
0gchaind init $MONIKER --chain-id $OG_CHAIN_ID
0gchaind config node tcp://localhost:${OG_PORT}657
Download genesis.json file
Terminal window
rm ~/.0gchain/config/genesis.json
wget -P ~/.0gchain/config https://github.com/0glabs/0g-chain/releases/download/v0.2.3/genesis.json
Custom port setting (Optional)
Terminal window
sed -i -e "
s%:1317%:${OG_PORT}317%g;
s%:8080%:${OG_PORT}080%g;
s%:9090%:${OG_PORT}090%g;
s%:9091%:${OG_PORT}091%g;
s%:8545%:${OG_PORT}545%g;
s%:8546%:${OG_PORT}546%g;
s%:6065%:${OG_PORT}065%g
" $HOME/.0gchain/config/app.toml
Terminal window
sed -i -e "
s%:26658%:${OG_PORT}658%g;
s%:26657%:${OG_PORT}657%g;
s%:6060%:${OG_PORT}060%g;
s%:26656%:${OG_PORT}656%g;
s%^external_address = \"\"%external_address = \"$(wget -qO- eth0.me):${OG_PORT}656\"%;
s%:26660%:${OG_PORT}660%g
" $HOME/.0gchain/config/config.toml
PEERS, SEED setting
Terminal window
SEEDS="81987895a11f6689ada254c6b57932ab7ed909b6@54.241.167.190:26656,010fb4de28667725a4fef26cdc7f9452cc34b16d@54.176.175.48:26656,e9b4bc203197b62cc7e6a80a64742e752f4210d5@54.193.250.204:26656,68b9145889e7576b652ca68d985826abd46ad660@18.166.164.232:26656,8f21742ea5487da6e0697ba7d7b36961d3599567@og-testnet-seed.itrocket.net:47656"
PEERS="90490155eb1e28a00cb9000657ef53cf9822e9e2@185.245.182.248:12656,6d0e4af8b817dbb81266d6c6710033896f1d65cb@158.220.103.216:12656,881b2297ac90fdf6803136101c1b33eeb52a0bcc@213.199.37.74:12656,2de20431412255201b960a0713c3a3f6fdbeb7e7@173.249.19.219:12656,9b6346424a9b1357bae659a51dbbb8d1c4d1366f@173.249.58.134:12656,055e3e65fd72102f389372564e0107e3ee5022fa@167.86.95.218:12656,0ada3d654c01607d585793943b37335a97a56691@213.239.195.210:12656,3f4ee55632cbd8694c7e5d173f10d7d7b23a5ec1@138.201.185.45:12656,2d780e7cae16cf25dfb992e294d5f672ae8a65ac@185.190.140.189:12656,85eec3750270e50ea73c46b1caa72e7110fa7b1b@156.67.81.129:12656,d619b3c8a0cc49b52ce68b45d8ebe2b9060a3f0a@149.50.111.193:12656,6ea4a3942152a33a50c54cc60aa311fd43cc71d7@144.91.93.99:12656,d7c847d92cf2714d3018cecd6476b6ef86b4240b@66.94.113.206:12656,85f1a5c5e62bbe59d9764453bf4624dc261a53f7@38.242.237.56:12656,1754dac0846c42ebe21fe1935eda0311d567d6a9@45.14.194.144:12656,7e49c7c5d8cf1a4f79d3a2c4a2c3597d144e638e@156.67.81.135:12656,80fa309afab4a35323018ac70a40a446d3ae9caf@og-testnet-peer.itrocket.net:11656"
sed -i -e "/^\[p2p\]/,/^\[/{s/^[[:space:]]*seeds *=.*/seeds = \"$SEEDS\"/}" \
-e "/^\[p2p\]/,/^\[/{s/^[[:space:]]*persistent_peers *=.*/persistent_peers = \"$PEERS\"/}" $HOME/.0gchain/config/config.toml
Update live peers:
Terminal window
PEERS=$(curl -s -X POST https://0gchain.josephtran.xyz -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"net_info","params":[],"id":1}' | jq -r '.result.peers[] | select(.connection_status.SendMonitor.Active == true) | "\(.node_info.id)@\(if .node_info.listen_addr | contains("0.0.0.0") then .remote_ip + ":" + (.node_info.listen_addr | sub("tcp://0.0.0.0:"; "")) else .node_info.listen_addr | sub("tcp://"; "") end)"' | tr '\n' ',' | sed 's/,$//' | awk '{print "\"" $0 "\""}')
sed -i "s/^persistent_peers *=.*/persistent_peers = $PEERS/" "$HOME/.0gchain/config/config.toml"
if [ $? -eq 0 ]; then
echo -e "Configuration file updated successfully with new peers"
else
echo "Failed to update configuration file."
fi
Config pruning, set gas price, enable prometheus, disable indexer
Terminal window
sed -i -e "s/^pruning *=.*/pruning = \"custom\"/" $HOME/.0gchain/config/app.toml
sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"100\"/" $HOME/.0gchain/config/app.toml
sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"50\"/" $HOME/.0gchain/config/app.toml
Terminal window
sed -i 's|minimum-gas-prices =.*|minimum-gas-prices = "0.00025ua0gi"|g' $HOME/.0gchain/config/app.toml
sed -i -e "s/prometheus = false/prometheus = true/" $HOME/.0gchain/config/config.toml
sed -i -e "s/^indexer *=.*/indexer = \"null\"/" $HOME/.0gchain/config/config.toml
Create service file
Terminal window
sudo tee /etc/systemd/system/0gd.service > /dev/null <<EOF
[Unit]
Description=0G Node
After=network.target
[Service]
User=$USER
Type=simple
ExecStart=$(which 0gchaind) start --home $HOME/.0gchain
Restart=on-failure
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
Reload daemon
Terminal window
sudo systemctl daemon-reload && \
sudo systemctl enable 0gd
Download snapshot
Terminal window
cp ~/.0gchain/data/priv_validator_state.json ~/.0gchain/priv_validator_state.json.backup && \
0gchaind tendermint unsafe-reset-all --home $HOME/.0gchain --keep-addr-book
Terminal window
#install tools
sudo apt-get install wget lz4 aria2 pv -y
#download snapshot
cd $HOME
rm -f 0gchain_snapshot.lz4
aria2c -x 16 -s 16 -k 1M https://josephtran.co/0gchain_snapshot.lz4
Terminal window
#decompress snapshot
lz4 -dc 0gchain_snapshot.lz4 | pv | tar -xf - -C $HOME/.0gchain
Terminal window
cp ~/.0gchain/priv_validator_state.json.backup ~/.0gchain/data/priv_validator_state.json
Start node
Terminal window
sudo systemctl start 0gd && sudo systemctl status 0gd

Check log

Terminal window
tail -f ~/.0gchain/log/chain.log

0G logs”

Check Latest Block Height
Terminal window
0gchaind status | jq '{ latest_block_height: .sync_info.latest_block_height, catching_up: .sync_info.catching_up }'
Block sync left
Terminal window
while true; do
local_height=$(0gchaind status | jq -r .sync_info.latest_block_height);
network_height=$(curl -s https://0gchain.josephtran.xyz/status | jq -r '.result.sync_info.latest_block_height')
blocks_left=$((network_height - local_height));
echo -e "\033[1;38mYour node height:\033[0m \033[1;34m$local_height\033[0m | \033[1;35mNetwork height:\033[0m \033[1;36m$network_height\033[0m | \033[1;29mBlocks left:\033[0m \033[1;31m$blocks_left\033[0m";
sleep 5;
done
Wallet config
Terminal window
0gchaind keys add "wallet_name" --eth
Faucet token
Check Balance | Create Validator | Check Validator
  • Check balances
Terminal window
0gchaind q bank balances $(0gchaind keys show "wallet_name" -a)
  • Create validator
Terminal window
0gchaind tx staking create-validator \
--amount=100ua0gi \
--pubkey=$(0gchaind tendermint show-validator) \
--moniker="Your_node_name" \
--chain-id=zgtendermint_16600-2 \
--commission-rate="0.10" \
--commission-max-rate="0.20" \
--commission-max-change-rate="0.01" \
--details="0G to the moon" \
--min-self-delegation="1" \
--from="wallet_name" \
--gas=auto \
--gas-adjustment=1.4 \
--gas-prices 0.00252ua0gi \
-y
  • Check validator
Terminal window
0gchaind q staking validator $(0gchaind keys show "wallet_name" --bech val -a)
Delegation
Terminal window
0gchaind tx staking delegate $(0gchaind keys show "your_wallet" --bech val -a) 1000000ua0gi \
--from "your_wallet" \
--chain-id=zgtendermint_16600-2 \
--gas=auto \
--gas-adjustment=1.4 \
--gas-prices 0.00252ua0gi \
-y
Remove node:
Terminal window
cd $HOME
sudo systemctl stop 0gd
sudo systemctl disable 0gd
sudo rm /etc/systemd/system/0gd.service
sudo systemctl daemon-reload
sudo rm -f $(which 0gchaind)
sudo rm -rf $HOME/.0gchain
sudo rm -rf $HOME/0g-chain