Skip to content

Installation

0G banner”

0G Storage interact with on-chain contracts for blob root confirmation and PoRA mining.. For official deployed contract addresses, visit this page.

Hardware Requirement
1. Install dependencies for building from source
Terminal window
sudo apt-get update
sudo apt-get install clang cmake build-essential openssl pkg-config libssl-dev
2. install go
Terminal window
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
3. install rustup
Terminal window
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Terminal window
. "$HOME/.cargo/env"
4. Download and install binary

If you want remove the node and install from scratch:

Terminal window
cd $HOME
rm -rf 0g-storage-node
git clone https://github.com/0glabs/0g-storage-node.git
cd 0g-storage-node
git checkout v0.8.0
git submodule update --init

Build:

Terminal window
cargo build --release
5. Config:

You can download my sample config
https://josephtran.co/config-testnet-turbo.toml

Terminal window
wget -O $HOME/0g-storage-node/run/config-testnet-turbo.toml https://josephtran.co/config-testnet-turbo.toml
6. Set your miner key:
  • Define varible
Terminal window
# The input will be hidden from the screen for security
printf '\033[34mEnter your private key: \033[0m' && read -s PRIVATE_KEY
  • Set miner_key:
Terminal window
sed -i 's|^\s*#\?\s*miner_key\s*=.*|miner_key = "'"$PRIVATE_KEY"'"|' $HOME/0g-storage-node/run/config-testnet-turbo.toml && echo -e "\033[32mPrivate key has been successfully added to the config file.\033[0m"
7. Verifying Configuration Changes

To check if the configuration has been updated correctly

Terminal window
grep -E "^(network_dir|network_enr_address|network_enr_tcp_port|network_enr_udp_port|network_libp2p_port|network_discovery_port|rpc_listen_address|rpc_enabled|db_dir|log_config_file|log_contract_address|mine_contract_address|reward_contract_address|log_sync_start_block_number|blockchain_rpc_endpoint|auto_sync_enabled|find_peer_timeout)" $HOME/0g-storage-node/run/config-testnet-turbo.toml
banner
8. create service
Terminal window
sudo tee /etc/systemd/system/zgs.service > /dev/null <<EOF
[Unit]
Description=ZGS Node
After=network.target
[Service]
User=$USER
WorkingDirectory=$HOME/0g-storage-node/run
ExecStart=$HOME/0g-storage-node/target/release/zgs_node --config $HOME/0g-storage-node/run/config-testnet-turbo.toml
Restart=on-failure
RestartSec=10
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
9. Start node
Terminal window
sudo systemctl daemon-reload && \
sudo systemctl enable zgs && \
sudo systemctl restart zgs && \
sudo systemctl status zgs
10. Check log
  • Full log:
Terminal window
tail -f ~/0g-storage-node/run/log/zgs.log.$(TZ=UTC date +%Y-%m-%d)
  • tx_seq log:
Terminal window
tail -f ~/0g-storage-node/run/log/zgs.log.$(TZ=UTC date +%Y-%m-%d) | grep tx_seq
banner
  • Monitoring 0g-storage-node Logs without Network and Peer Messages:
Terminal window
tail -f ~/0g-storage-node/run/log/zgs.log.$(date +%Y-%m-%d) | grep -v "discv5\|network\|router\|Peer"
banner
  • logSync & Peers through RPC:
Terminal window
while true; do
response=$(curl -s -X POST http://localhost:5678 -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"zgs_getStatus","params":[],"id":1}')
logSyncHeight=$(echo $response | jq '.result.logSyncHeight')
connectedPeers=$(echo $response | jq '.result.connectedPeers')
echo -e "logSyncHeight: \033[32m$logSyncHeight\033[0m, connectedPeers: \033[34m$connectedPeers\033[0m"
sleep 5;
done
banner
# Use snapshot:

You can use my snapshot to sync faster

# Stop & Delete node
Terminal window
sudo systemctl stop zgs
Terminal window
sudo systemctl disable zgs
sudo rm /etc/systemd/system/zgs.service
rm -rf $HOME/0g-storage-node