๐Ÿ’œ0G

Preparations

To continue, we can update the packages by running the following commands in the terminal. The first part of the command (sudo apt update) updates the package lists for upgrades, and the second part (sudo apt upgrade -y) actually performs the upgrades with the โ€œ-yโ€ flag allowing for automatic confirmation of prompts during the upgrade process:

sudo apt-get update && sudo apt-get upgrade -y

Execute .bashrc and .bash_profile files:

source $HOME/.bashrc
source $HOME/.bash_profile

Install packages:

apt install snap unzip wget jq

Install Go:

ver="1.21.3" && \
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" >> $HOME/.bash_profile && \
source $HOME/.bash_profile && \
go version

Installation

Clone GitHub repository:

git clone -b v0.1.0 https://github.com/0glabs/0g-chain.git

Move to 0g-chain folder:

cd 0g-chainba

Switch to testnet branch:

git checkout origin/v0.1.0

Install 0gchaind:

make install

Check version:

0gchaind version

Run:

cd && source .profile

Set Chain ID and node tcp:

0gchaind config chain-id zgtendermint_16600-1
0gchaind config node tcp://localhost:26657

Initialize node: Change <your_moniker> for your node name.

0gchaind init <your_moniker> --chain-id zgtendermint_16600-1

If everything went ok, should look like this:

Download genesis file:

rm ~/.0gchain/config/genesis.json
wget -P ~/.0gchain/config https://github.com/0glabs/0g-chain/releases/download/v0.1.0/genesis.json

Check genesis:

sha256sum $HOME/.0gchain/config/genesis.json

Output should be:

cc862760abd4cebb91935e7506a745a251074cdd44148a5c9ae4ee7539dd8d0a /root/.0gchain/config/genesis.json

Validate genesis:

0gchaind validate-genesis

Output should be:

File at /root/.0gchain/config/genesis.json is a valid genesis file

Check validator state:

cd && cat .0gchain/data/priv_validator_state.json

Should be at the beginning:

{
  "height": "0",
  "round": 0,
  "step": 0
}

Add seeds and peers:

SEEDS="c4d619f6088cb0b24b4ab43a0510bf9251ab5d7f@54.241.167.190:26656,44d11d4ba92a01b520923f51632d2450984d5886@54.176.175.48:26656,f2693dd86766b5bf8fd6ab87e2e970d564d20aff@54.193.250.204:26656,f878d40c538c8c23653a5b70f615f8dccec6fb9f@54.215.187.94:26656"
PEERS="6cdd50ed6e958269c259ffc4db17509e15e381bb@185.209.223.10:16656,3a8a28c734a4d32052065d9f6006c14dfa7a4e4e@37.27.59.176:18456,a4055b828e59832c7a06d61fc51347755a160d0b@157.90.33.62:21656,cd529839591e13f5ed69e9a029c5d7d96de170fe@46.4.55.46:34656"
sed -i -e "s/^seeds *=.*/seeds = \"$SEEDS\"/; s/^persistent_peers *=.*/persistent_peers = \"$PEERS\"/" $HOME/.0gchain/config/config.toml

Add pruning:

pruning="custom" 
pruning_keep_recent="1000" 
pruning_interval="10"
sed -i -e "s/^pruning *=.*/pruning = \"$pruning\"/" $HOME/.0gchain/config/app.toml
sed -i -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"$pruning_keep_recent\"/" $HOME/.0gchain/config/app.toml
sed -i -e "s/^pruning-interval *=.*/pruning-interval = \"$pruning_interval\"/" $HOME/.0gchain/config/app.toml

Downdload addrbook file:

curl -L https://snapshot.validatorvn.com/og/addrbook.json > $HOME/.0gchain/config/addrbook.json

Create service file:

tee /etc/systemd/system/0gd.service > /dev/null <<EOF 
[Unit]
Description=0G Node
After=network.target

[Service]
User=$USER
Type=simple
ExecStart=/root/go/bin/0gchaind start --home /root/.0gchain
Restart=on-failure
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
EOF

Reload daemon:

systemctl daemon-reload

Enable 0gd.service:

systemctl enable 0gd

Start ogd.service:

systemctl start 0gd

Check status:

systemctl status 0gd

If everything went ok, should look like this:

Wait for synchronization.

Check sync status:

0gchaind status | jq .SyncInfo

or just catching up:

0gchaind status | jq .SyncInfo.catching_up

When fully synced should be false.

Create wallet: Change <key_name> with Your wallet name.

0gchaind keys add <key_name> --eth

Enter password (passphrase). Save mnemonic and wallet address.

Check and save your HEX address: Change <WALLET_NAME> to what youโ€™ve chosen in previous step.

echo "0x$(0gchaind debug addr $(0gchaind keys show <WALLET_NAME> -a) | grep hex | awk '{print $3}')"

Save it.

Go to faucet and claim test tokens. It gives only 0.1evmos per day, you can claim only once per day.

Check balance: Change <WALLET_NAME> to what youโ€™ve chosen in step 25.

0gchaind q bank balances $(0gchaind keys show <WALLET_NAME> -a)

Create validator:

Change: YOUR_MONIKER with the name of you validator; WALLET_NAME to what youโ€™ve chosen in step 25.

0gchaind tx staking create-validator \
  --amount=1000000ua0gi \
  --pubkey=$(0gchaind tendermint show-validator) \
  --moniker="YOUR_MONIKER" \
  --chain-id=zgtendermint_16600-1 \
  --commission-rate=0.05 \
  --commission-max-rate=0.20 \
  --commission-max-change-rate=0.01\
  --details "psi.crypto community" \
  --min-self-delegation="1" \
  --from=WALLET_NAME \
  --gas=auto \
  --gas-adjustment=1.4
  -y

Delegate to your validator: Change <WALLET_NAME> with your wallet name, Change <MONIKER> with moniker from previous step.

0gchaind tx staking delegate $(0gchaind keys show <MONIKER> --bech val -a) 1000000ua0gi --from <WALLET_NAME> --gas=auto --gas-adjustment=1.4 -y

Update Node

Stop service file:

sudo systemctl stop 0gd

Remove the outdated files:

rm $HOME/.0gchain/config/addrbook.json $HOME/.0gchain/config/genesis.json

Reset the data:

0gchaind tendermint unsafe-reset-all --home $HOME/.0gchain

Your node is now in a pristine state while keeping the original priv_validator.json and config.toml.

Restart service file:

sudo systemctl restart 0gd

Useful commands

Unjail:

0gchaind tx slashing unjail --from <key_name> --gas=500000 --gas-prices=7ua0gi โ€“y

Check list of active validators:

0gchaind q staking validators -o json --limit=1000 | jq '.validators[] | select(.status=="BOND_STATUS_BONDED")' | jq -r '.tokens + " - " + .description.moniker' | sort -gr | nl

Check list of inactive validators:

0gchaind q staking validators -o json --limit=1000 | jq '.validators[] | select(.status=="BOND_STATUS_UNBONDED")' | jq -r '.tokens + " - " + .description.moniker' | sort -gr | nl

Delegate to validator:

0gchaind tx staking delegate $(0gchaind keys show <MONIKER> --bech val -a) AMOUNTua0gi --from <WALLET_NAME> --gas=auto --gas-adjustment=1.4 -y

Send transaction: Change <SENDER_WALLET>, <RECEIVER_WALLET>, AMOUNT.

0gchaind tx bank send <SENDER_WALLET> <RECEIVER_WALLET> AMOUNTua0gi --gas=95000  --gas-prices=7ua0gi -y

Delete node

sudo systemctl stop 0gd
sudo systemctl disable 0gd
rm /etc/systemd/system/0gd.service
rm -rf 0g-chain
rm -rf .0gchain

Last updated