Setting Up a 0G Node: A Step-by-Step Guide

AndreasV
4 min read4 days ago

--

As a cryptocurrency enthusiast, I’m always excited about exploring new blockchain projects. Recently, I decided to dive into the world of 0G, a promising blockchain aiming for robust decentralization and security. Here’s a detailed account of how I set up my 0G node from scratch.

Step 1: Preparation

First things first, I needed to update my server and install necessary packages:

sudo apt update
sudo apt install curl git jq build-essential gcc unzip wget lz4 -y

Step 2: Installing GO

Next, I installed the GO programming language, crucial for building and running the 0G node:

cd $HOME
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

Step 3: Cloning and Installing 0G Chain

Now, I cloned the 0G chain repository and installed the bin

git clone -b v0.1.0 https://github.com/0glabs/0g-chain.git
./0g-chain/networks/testnet/install.sh
source .profile

Step 4: Setting Environment Variables

I customized environment variables in my .bash_profile for personalized node configuration:

echo 'export MONIKER="type_your_moniker_nodebrand"' >> ~/.bash_profile
echo 'export CHAIN_ID="zgtendermint_16600-1"' >> ~/.bash_profile
echo 'export WALLET_NAME="wallet"' >> ~/.bash_profile
echo 'export RPC_PORT="26657"' >> ~/.bash_profile
source $HOME/.bash_profile

Step 5: Initializing and Configuring the Node

With environment variables set, I initialized and configured my 0G node:

cd $HOME
0gchaind config chain-id $CHAIN_ID
0gchaind init $MONIKER --chain-id $CHAIN_ID
0gchaind config node tcp://localhost:$RPC_PORT
0gchaind config keyring-backend os

Step 6: Installing Current Release and Configuring

I downloaded the genesis file and configured config.toml:

wget -P ~/.0gchain/config https://github.com/0glabs/0g-chain/releases/download/v0.1.0/genesis.json
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" && \
sed -i -e "s/^seeds *=.*/seeds = \"$SEEDS\"/; s/^persistent_peers *=.*/persistent_peers = \"$PEERS\"/" $HOME/.0gchain/config/config.toml

Step 7: Setting Ports and Pruning

Configuring ports and pruning settings for optimal performance:

EXTERNAL_IP=$(wget -qO- eth0.me)
PROXY_APP_PORT=26658
P2P_PORT=26656
PPROF_PORT=6060
API_PORT=1317
GRPC_PORT=9090
GRPC_WEB_PORT=9091

Set the port pruning and price:

sed -i \
-e "s/\(proxy_app = \"tcp:\/\/\)\([^:]*\):\([0-9]*\).*/\1\2:$PROXY_APP_PORT\"/" \
-e "s/\(laddr = \"tcp:\/\/\)\([^:]*\):\([0-9]*\).*/\1\2:$RPC_PORT\"/" \
-e "s/\(pprof_laddr = \"\)\([^:]*\):\([0-9]*\).*/\1localhost:$PPROF_PORT\"/" \
-e "/\[p2p\]/,/^\[/{s/\(laddr = \"tcp:\/\/\)\([^:]*\):\([0-9]*\).*/\1\2:$P2P_PORT\"/}" \
-e "/\[p2p\]/,/^\[/{s/\(external_address = \"\)\([^:]*\):\([0-9]*\).*/\1${EXTERNAL_IP}:$P2P_PORT\"/; t; s/\(external_address = \"\).*/\1${EXTERNAL_IP}:$P2P_PORT\"/}" \
$HOME/.0gchain/config/config.toml
sed -i \
-e "/\[api\]/,/^\[/{s/\(address = \"tcp:\/\/\)\([^:]*\):\([0-9]*\)\(\".*\)/\1\2:$API_PORT\4/}" \
-e "/\[grpc\]/,/^\[/{s/\(address = \"\)\([^:]*\):\([0-9]*\)\(\".*\)/\1\2:$GRPC_PORT\4/}" \
-e "/\[grpc-web\]/,/^\[/{s/\(address = \"\)\([^:]*\):\([0-9]*\)\(\".*\)/\1\2:$GRPC_WEB_PORT\4/}" $HOME/.0gchain/config/app.toml
sed -i.bak -e "s/^pruning *=.*/pruning = \"custom\"/" $HOME/.0gchain/config/app.toml
sed -i.bak -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"100\"/" $HOME/.0gchain/config/app.toml
sed -i.bak -e "s/^pruning-interval *=.*/pruning-interval = \"10\"/" $HOME/.0gchain/config/app.toml
sed -i "s/^minimum-gas-prices *=.*/minimum-gas-prices = \"0ua0gi\"/" $HOME/.0gchain/config/app.toml
sed -i "s/^indexer *=.*/indexer = \"kv\"/" $HOME/.0gchain/config/config.toml

Step 8: Creating Systemd Service

I created a systemd service for my 0G node to ensure it runs persistently:

sudo tee /etc/systemd/system/ogd.service > /dev/null <<EOF
[Unit]
Description=OG Node
After=network.target

[Service]
User=$USER
Type=simple
ExecStart=$(which 0gchaind) start --home $HOME/.0gchain
Restart=10
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
EOF

Start node:

sudo systemctl daemon-reload && \
sudo systemctl enable ogd && \
sudo systemctl restart ogd && sudo journalctl -u ogd -f -o cat

Step 9: Node Synchronization and Validator Setup

After I made sure everything was working, it was time to install Snapshot, addrbook and update peers:

curl -Ls https://snapshots.liveraven.net/snapshots/testnet/zero-gravity/addrbook.json > $HOME/.0gchain/config/addrbook.json
PEERS=$(curl -s --max-time 3 --retry 2 --retry-connrefused "https://snapshots.liveraven.net/snapshots/testnet/zero-gravity/peers.txt")
if [ -z "$PEERS" ]; then
echo "No peers were retrieved from the URL."
else
echo -e "\nPEERS: "$PEERS""
sed -i "s/^persistent_peers *=.*/persistent_peers = "$PEERS"/" "$HOME/.0gchain/config/config.toml"
echo -e "\nConfiguration file updated successfully.\n"
fi
sudo systemctl stop ogd
cp $HOME/.0gchain/data/priv_validator_state.json $HOME/.0gchain/priv_validator_state.json.backup
rm -rf $HOME/.0gchain/data
curl -L http://snapshots.liveraven.net/snapshots/testnet/zero-gravity/zgtendermint_16600-1_latest.tar.lz4 | tar -Ilz4 -xf - -C $HOME/.0gchain
mv $HOME/.0gchain/priv_validator_state.json.backup $HOME/.0gchain/data/priv_validator_state.json
sudo systemctl restart ogd && sudo journalctl -u ogd -f -o cat

Check node synchronization:

# If you get false, you can install the validator.
# If it is true, you have to wait.

0gchaind status | jq .sync_info

Step 10: Creating a Wallet

To begin, I needed a wallet for my validator. I used the following commands to create a new wallet:

0gchaind keys add $WALLET_NAME --eth

Alternatively, you can import an existing wallet:

0gchaind keys add --recover $WALLET_NAME --eth

After entering the password (copied beforehand for security), I received my wallet with a seed phrase. It’s crucial to store this securely as it’s the key to my funds and validator operations.

Step 11: Requesting Test Tokens from the Faucet

Next, I headed to the 0G faucet to request test tokens. This step is essential for funding my validator operations during testing and initial setup.

To check my balance after receiving tokens, I used

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

The faucet provided me with 1000000000000000000aevmos, but to join the active set as a validator, I needed at least 10000000000000000000aevmos (10 times more :| ).

Step 12: Creating the Validator

With tokens in hand, I proceeded to create my validator using the following command:

0gchaind tx staking create-validator \
--amount=1000000ua0gi \
--pubkey=$(0gchaind tendermint show-validator) \
--moniker="$MONIKER" \
--chain-id=zgtendermint_16600-1 \
--commission-rate="0.10" \
--commission-max-rate="0.20" \
--commission-max-change-rate="0.01" \
--details="<type your details here>" \
--min-self-delegation="1" \
--from=$WALLET_NAME \
--gas=auto \
--gas-adjustment=1.4

This command registers my validator with specific details like moniker (name), commission rates, and other parameters crucial for participating in the network.

Step 13: Delegating Tokens

As a validator, I also have the option to delegate tokens to myself or to other validators. To delegate tokens to myself, I checked my validator address:

0gchaind q staking validator $(0gchaind keys show $WALLET_NAME --bech val -a)

For delegating tokens to another validator, I would use a similar command structure with appropriate parameters.

Conclusion

That’s all, it wasn’t very difficult, despite the fact that I ran into some problems along the way. Good luck!

--

--

AndreasV
0 Followers

Crypto Enthusiast. Validator. Fistbump *explosion 💥 | I'm on X: https://x.com/VorobeyAnd | GitHub: https://github.com/AndreassaV