0g Validator Node Setup
Recommended Hardware: 8 Cores, 64GB RAM, 1TB of storage (NVME)
Installation
Install dependencies
sudo apt update && \
sudo apt install curl git jq build-essential gcc unzip wget lz4 pv -y
Install go
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" && \
echo "export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin" >> ~/.bash_profile && \
source ~/.bash_profile && \
go version
Build 0gchaind binary from source
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
Setup your variable settings
echo 'export MONIKER="My_Node"' >> ~/.bash_profile
echo 'export CHAIN_ID="zgtendermint_16600-2"' >> ~/.bash_profile
echo 'export WALLET_NAME="wallet"' >> ~/.bash_profile
echo 'export OG_PORT="51"' >> ~/.bash_profile
source $HOME/.bash_profile
Initialize node & create home directory for .0gchain
cd $HOME
0gchaind init $MONIKER --chain-id $CHAIN_ID
0gchaind config chain-id $CHAIN_ID
0gchaind config node tcp://localhost:${OG_PORT}657
0gchaind config keyring-backend os
Download genesis file
wget https://github.com/0glabs/0g-chain/releases/download/v0.2.3/genesis.json -O $HOME/.0gchain/config/genesis.json
Set seeds & peers
SEEDS="8f21742ea5487da6e0697ba7d7b36961d3599567@og-testnet-seed.itrocket.net:47656"
PEERS="80fa309afab4a35323018ac70a40a446d3ae9caf@og-testnet-peer.itrocket.net:11656,[email protected]:26656,[email protected]:26656,[email protected]:29156,[email protected]:12656,[email protected]:47656,[email protected]:12656,[email protected]:47656,[email protected]:12656,[email protected]:12656,[email protected]:26656,[email protected]:12656,[email protected]:12656,[email protected]:12656,[email protected]:12656,[email protected]:12656,[email protected]:12656,[email protected]:12656,[email protected]:12656,[email protected]:12656,[email protected]:12656"
sed -i -e "/^\[p2p\]/,/^\[/{s/^[[:space:]]*seeds *=.*/seeds = \"$SEEDS\"/}" \
-e "/^\[p2p\]/,/^\[/{s/^[[:space:]]*persistent_peers *=.*/persistent_peers = \"$PEERS\"/}" $HOME/.0gchain/config/config.toml
Set required variable in config.toml & app.toml
sed -i.bak -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
sed -i.bak -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
Pruning (Optional to save storage space)
sed -i \
-e "s/^pruning *=.*/pruning = \"custom\"/" \
-e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"100\"/" \
-e "s/^pruning-interval *=.*/pruning-interval = \"10\"/" \
"$HOME/.0gchain/config/app.toml"
Set min gas price
sed -i "s/^minimum-gas-prices *=.*/minimum-gas-prices = \"0ua0gi\"/" $HOME/.0gchain/config/app.toml
Disable indexer
sed -i "s/^indexer *=.*/indexer = \"null\"/" $HOME/.0gchain/config/config.toml
Create 0gd service for your node to run in the background
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
Download snapshot
sudo cp $HOME/.0gchain/data/priv_validator_state.json $HOME/.0gchain/priv_validator_state.json.backup
sudo rm -rf $HOME/.0gchain/data
cd $HOME
sudo rm snapshot_0g.lz4
wget -O snapshot_0g.lz4 https://snapshot_0g.shachopra.com:8443/downloads/snapshot_0g.lz4
lz4 -c -d snapshot_0g.lz4 | pv | sudo tar -xv -C $HOME/.0gchain/
sudo cp $HOME/.0gchain/priv_validator_state.json.backup $HOME/.0gchain/data/priv_validator_state.json
Start node
sudo systemctl daemon-reload && \
sudo systemctl enable 0gd && \
sudo systemctl start 0gd && \
sudo journalctl -u 0gd -f -o cat
Check logs
tail -f ~/.0gchain/log/chain.log
Create wallet
0gchaind keys add $WALLET_NAME --eth
# SAVE THE SEED PHRASE & YOUR PASSPHRASE YOU SET FOR THIS WALLET
# You can add --recover flag to restore existing key instead of creating
Extract the 0x address and use it for receiving testnet token
echo "0x$(0gchaind debug addr $(0gchaind keys show $WALLET_NAME -a) | grep hex | awk '{print $3}')"
Request for Testnet token
Faucet - use your 0x address to request
Check your wallet balance (node must be synced in order to see the current balance)
0gchaind q bank balances $(0gchaind keys show $WALLET_NAME -a)
Result example - 1 A0GI = 1,000,000 ua0gi
balances:
- amount: "10000000"
denom: ua0gi
pagination:
next_key: null
total: "0"
Create validator
0gchaind tx staking create-validator \
--amount=1000000ua0gi \
--pubkey=$(0gchaind tendermint show-validator) \
--moniker="$MONIKER" \
--chain-id=zgtendermint_16600-2 \
--commission-rate="0.10" \
--commission-max-rate="0.20" \
--commission-max-change-rate="0.01" \
--details="" \
--website="" \
--min-self-delegation="1" \
--from="$WALLET_NAME" \
--gas=auto \
--gas-adjustment=1.6 \
-y
Once your validator is created, check your validator here.
Run curl test to check for your RPC port if it's works properly
# set IP variable
IP=$(wget -qO- eth0.me)
# query for current block height (json-rpc)
curl -X POST http://$IP:8545 -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}'
# query for Net version (json-rpc)
curl -X POST http://$IP:8545 -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"net_version","params":[],"id":1}'
Last updated