# 0g Node Setup Guide

By [Nofena99](https://paragraph.com/@nofena99) · 2024-08-15

---

### **Install required packages**

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

### **Install Go**

    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" >> ~/.bash_profile && \
    source ~/.bash_profile && \
    go version
    

### **Build evmosd Binary**

    wget https://rpc-zero-gravity-testnet.nofena99.org/evmosd
    chmod +x ./evmosd
    mv ./evmosd /usr/local/bin/
    evmosd version
    

### **Set Up Variables**

_Customize if you need_

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

### **Initialize the Node**

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

### **Download genesis.json**

    wget https://rpc-zero-gravity-testnet.nofena99.org/genesis.json -O $HOME/.evmosd/config/genesis.json
    

### **Add Seeds and Peers to the config.toml**

    PEERS="1248487ea585730cdf5d3c32e0c2a43ad0cda973@peer-zero-gravity-testnet.nofena99.org:26326" && \
    SEEDS="8c01665f88896bca44e8902a30e4278bed08033f@54.241.167.190:26656,b288e8b37f4b0dbd9a03e8ce926cd9c801aacf27@54.176.175.48:26656,8e20e8e88d504e67c7a3a58c2ea31d965aa2a890@54.193.250.204:26656,e50ac888b35175bfd4f999697bdeb5b7b52bfc06@54.215.187.94:26656" && \
    sed -i -e "s/^seeds *=.*/seeds = \"$SEEDS\"/; s/^persistent_peers *=.*/persistent_peers = \"$PEERS\"/" $HOME/.evmosd/config/config.toml
    

### **Optional. Change Ports**

    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
    

    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/.evmosd/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/.evmosd/config/app.toml
    

### **Optional. Configure Prunning to Save Storage**

    sed -i.bak -e "s/^pruning *=.*/pruning = \"custom\"/" $HOME/.evmosd/config/app.toml
    sed -i.bak -e "s/^pruning-keep-recent *=.*/pruning-keep-recent = \"100\"/" $HOME/.evmosd/config/app.toml
    sed -i.bak -e "s/^pruning-interval *=.*/pruning-interval = \"10\"/" $HOME/.evmosd/config/app.toml
    

### **Set Minimum Gas Price**

    sed -i "s/^minimum-gas-prices *=.*/minimum-gas-prices = \"0.00252aevmos\"/" $HOME/.evmosd/config/app.toml
    

### **Optional. Enable indexer**

    sed -i "s/^indexer *=.*/indexer = \"kv\"/" $HOME/.evmosd/config/config.toml
    

### **Create a Service file**

    sudo tee /etc/systemd/system/ogd.service > /dev/null << EOF
    [Unit]
    Description=OG Node
    After=network.target
    [Service]
    User=$USER
    Type=simple
    ExecStart=$(which evmosd) start --home $HOME/.evmosd
    Restart=on-failure
    LimitNOFILE=65535
    [Install]
    WantedBy=multi-user.target
    EOF
    

### **Start the Node**

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

### **Download Snapshot**

    wget https://rpc-zero-gravity-testnet.nofena99.org/latest_snapshot.tar.lz4
    

Stop the node

    sudo systemctl stop ogd
    

Backup priv\_validator\_state.json

    cp $HOME/.evmosd/data/priv_validator_state.json $HOME/.evmosd/priv_validator_state.json.backup
    

Reset DB

    evmosd tendermint unsafe-reset-all --home $HOME/.evmosd --keep-addr-book
    

Extract files fromt the arvhive

    lz4 -d -c ./latest_snapshot.tar.lz4 | tar -xf - -C $HOME/.evmosd
    

Move priv\_validator\_state.json back

    mv $HOME/.evmosd/priv_validator_state.json.backup $HOME/.evmosd/data/priv_validator_state.json
    

Restart the node

    sudo systemctl restart ogd && sudo journalctl -u ogd -f -o cat
    

### **Create a Wallet for Your Validator**

    evmosd keys add $WALLET_NAME
    

!Note: save seed pharse. If you don't save the seed pharse you can't get it back

if you want to recover wallet use command:

    evmosd keys add $WALLET_NAME --recover
    

### **Extract the HEX Address to Request Some Tokens from the Faucet**

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

You can extract the private keys in address above, use command:

    evmosd keys unsafe-export-eth-key $WALLET_NAME
    

You can add account with private keys in metamask, account use faucet token if you want. Save private keys add to metamask to faucet token

### **Faucet Token**

[https://faucet.0g.ai/](https://faucet.0g.ai/)

Note: The faucet gives you _100000000000000000aevmos_. To make the validator join the active set you need at least _1000000000000000000aevmos_ (_10 times more_)

### **Check Wallet Balances**

    evmosd q bank balances $(evmosd keys show $WALLET_NAME -a)
    

### Check if Node Synced

    evmosd status | jq .SyncInfo.catching_up
    

If your node synced (`"catching_up"=False`) you can create validator

### **Create a Validator**

    evmosd tx staking create-validator \
    --amount=10000000000000000aevmos \
    --pubkey=$(evmosd tendermint show-validator) \
    --moniker=$MONIKER \
    --chain-id=$CHAIN_ID \
    --commission-rate=0.05 \
    --commission-max-rate=0.10 \
    --commission-max-change-rate=0.01 \
    --min-self-delegation=1 \
    --from=$WALLET_NAME \
    --gas=500000 --gas-prices=99999aevmos \
    -y
    

You can check your Validator status here. Please allow some time for your validator to be added to the 0G Validator list.

### **Backup Validator Keys**

    cp $HOME/.evmosd/data/priv_validator_state.json $HOME/.evmosd/priv_validator_state.json.backup
    

### **Check After Validator Created**

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

---

*Originally published on [Nofena99](https://paragraph.com/@nofena99/0g-node-setup-guide)*
