Installation
Installation Install dependencies, if needed
Copy sudo apt update && sudo apt upgrade -y
sudo apt install curl git wget htop tmux build-essential jq make lz4 gcc unzip -y
Install go, if needed
Copy 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
Copy git clone -b v0.2.3 https://github.com/0glabs/0g-chain.git
cd 0g-chain
make install
0gchaind version
Setup your variable settings
Copy 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 RPC_PORT="26657"' >> ~/.bash_profile
source $HOME/.bash_profile
Initialize node & create home directory for .0gchain
Copy cd $HOME
0gchaind config chain-id $CHAIN_ID
0gchaind config node tcp://localhost:$RPC_PORT
0gchaind config keyring-backend file
0gchaind init $MONIKER --chain-id $CHAIN_ID
Download genesis file
Copy wget https://github.com/0glabs/0g-chain/releases/download/v0.2.3/genesis.json -O $HOME/.0gchain/config/genesis.json
Set 0G chain seeds
Copy 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" && \
sed -i.bak -e "s/^seeds *=.*/seeds = \"${SEEDS}\"/" $HOME/.0gchain/config/config.toml
Confirm your ports (These are standard values, feel free to edit port(s) you wish to use)
Copy 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 required variable in config.toml & app.toml for your node
Copy 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
Copy sed -i -e "/\[api\]/,/^\[/{s/\(address = \"tcp:\/\/\)\([^:]*\):\([0-9]*\)\(\".*\)/\1\2:$API_PORT\4/}" $HOME/.0gchain/config/app.toml
sed -i -e "/\[grpc\]/,/^\[/{s/\(address = \"\)\([^:]*\):\([0-9]*\)\(\".*\)/\1\2:$GRPC_PORT\4/}" $HOME/.0gchain/config/app.toml
sed -i -e "/\[grpc-web\]/,/^\[/{s/\(address = \"\)\([^:]*\):\([0-9]*\)\(\".*\)/\1\2:$GRPC_WEB_PORT\4/}" $HOME/.0gchain/config/app.toml
Pruning (Optional to save storage space)
Copy 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
Set min gas price
Copy sed -i "s/^minimum-gas-prices *=.*/minimum-gas-prices = \"0ua0gi\"/" $HOME/.0gchain/config/app.toml
Enable indexer
Copy sed -i "s/^indexer *=.*/indexer = \"kv\"/" $HOME/.0gchain/config/config.toml
Create 0gd service for your node to run in the background
Copy sudo tee /etc/systemd/system/0gd.service > /dev/null <<EOF
[Unit]
Description=OG Node
After=network.target
[Service]
User=$USER
Type=simple
ExecStart=$(which 0gchaind) start --json-rpc.api eth,txpool,personal,net,debug,web3 --home $HOME/.0gchain
Restart=on-failure
RestartSec=10
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
Update peers - powered by NodeCattel
Copy PEERS=$(curl -s -X POST https://rpc.nodecattel.xyz/0gchain/ -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)@\(.remote_ip):\(.node_info.listen_addr | sub("tcp://0.0.0.0:"; ""))"' | tr '\n' ',' | sed 's/,$//' | awk '{print "\"" $0 "\""}'
)
sed -i "s/^persistent_peers *=.*/persistent_peers = $PEERS/" "$HOME/.0gchain/config/config.toml"
echo -e "\n$PEERS\n\nUpdate fresh peers completed by \033[35mNodeCattel\033[0m"
(Optional) - Live peers update script with auto update every 6 hours
Copy # download update_peers.sh
curl -o $HOME/.0gchain/update_peers.sh https://gist.githubusercontent.com/nodecattel/1fe8caf9412dd076d1ee267cc91f7472/raw/9cc89065a7720e744e1d83d611682f6d9293f618/update_peers.sh
chmod +x $HOME/.0gchain/update_peers.sh
# run script for the first time
$HOME/.0gchain/update_peers.sh
(Optional) - Setup crontab for auto-run and logging
Copy # open crontab editor
crontab -e
add the following line to the crontab file 0 */6 * * * /bin/bash $HOME/.0gchain/update_peers.sh >> $HOME/.0gchain/update_peers.log 2>&1
Download snapshot for quick sync
Copy # download snapshot
sudo systemctl stop 0gd
cp $HOME/.0gchain/data/priv_validator_state.json $HOME/.0gchain/priv_validator_state.json.backup
0gchaind tendermint unsafe-reset-all --home $HOME/.0gchain --keep-addr-book
curl -L https://snapshot.dongqn.com/0gchain/zgtendermint_16600-1_latest.tar.lz4 | sudo lz4 -dc - | sudo tar -xf - -C $HOME/.0gchain
mv $HOME/.0gchain/priv_validator_state.json.backup $HOME/.0gchain/data/priv_validator_state.json
Start node
Copy sudo systemctl daemon-reload && \
sudo systemctl enable 0gd && \
sudo systemctl restart 0gd && \
sudo journalctl -u 0gd -f -o cat
You can exit the node's log by using ctrl + c
Stop Validator node - (if you wish to stop the service)
Copy sudo systemctl stop 0gd
Check for your syncing progress
Copy 0gchaind status | jq '{ latest_block_height: .sync_info.latest_block_height, catching_up: .sync_info.catching_up }'
The result should be "catching_up": false
when your node is fully synced
Result example
Copy {
"latest_block_height": "419865",
"catching_up": false
}
NodeGuru's explorer for checking latest block height here
Create wallet
Copy 0gchaind keys add $WALLET_NAME --eth
# DO NOT FORGET TO 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
Copy 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)
Copy 0gchaind q bank balances $(0gchaind keys show $WALLET_NAME -a)
Result example - 1 A0GI = 1,000,000 ua0gi
Copy balances:
- amount: "41694146"
denom: ua0gi
pagination:
next_key: null
total: "0"
Create validator
Copy 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="0g to the moon..." \
--website="https://services.manhcuongsev.xyz" \
--min-self-delegation="1" \
--from="$WALLET_NAME" \
--gas=auto \
--gas-adjustment=1.4 \
-y
Once your validator is created you can look up your validator here . Most likely it will be in inactive
set as you will need enough stake to reach top 125 TVL validator. This is normal ~~~
Run curl test to check for your RPC port if it's works properly
Copy # set EXTERNAL_IP variable
EXTERNAL_IP=$(wget -qO- eth0.me)
# query for current block height (json-rpc)
curl -X POST http://$EXTERNAL_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://$EXTERNAL_IP:8545 -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"net_version","params":[],"id":1}'
Result example
Current block height
Copy {"jsonrpc":"2.0","id":1,"result":"0x66972"}
Net version (evm chain-id)
Copy {"jsonrpc":"2.0","id":1,"result":"16600"}
Congratulation!!
Now you have completed your node for 0gchain and we will move on to creating your storage node next.
Upgrade Node 0.2.5
Copy sudo systemctl stop 0gd.service
cd $HOME
rm -rf 0g-chain
git clone https://github.com/0glabs/0g-chain.git
cd 0g-chain
git checkout v0.2.5
make build
make install
sudo systemctl start 0gd.service
Last updated 8 months ago