Resources
Prerequisite
0G Storage and DA services interact with on-chain contracts for blob root confirmation and PoRA mining.
This step is performed after your has been installed and created.
For official deployed contract addresses, visit
Hardware requirements
Installation 💾
Install dependencies
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 Rust
Copy curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
source $HOME/.cargo/env
cargo --version
rustc --version
Install GO 1.22.2
Copy sudo rm -rf /usr/local/go && \
curl -L https://go.dev/dl/go1.22.2.linux-amd64.tar.gz | sudo tar -xzf - -C /usr/local && \
echo 'export PATH=$PATH:/usr/local/go/bin:$HOME/go/bin' >> $HOME/.bash_profile && \
source .bash_profile && \
go version
Build binary from source
Copy git clone -b v1.0.0 https://github.com/0glabs/0g-storage-node.git
cd $HOME/0g-storage-node
git stash
git fetch --all --tags
git checkout 347cd3e
git submodule update --init
cargo build --release
cp $HOME/0g-storage-node/run/config-testnet-turbo.toml $HOME/0g-storage-node/run/config.toml
check zgs version
Copy $HOME/0g-storage-node/target/release/zgs_node --version
Set vars. you found more from official docs
Copy export ZGS_LOG_DIR="$HOME/0g-storage-node/run/log"
export ZGS_LOG_CONFIG_FILE="$HOME/0g-storage-node/run/log_config"
export LOG_CONTRACT_ADDRESS="0x56A565685C9992BF5ACafb940ff68922980DBBC5"
export MINE_CONTRACT="0xB87E0e5657C25b4e132CB6c34134C0cB8A962AD6"
export REWARD_CONTRACT="0x233B2768332e4Bae542824c93cc5c8ad5d44517E"
export ZGS_LOG_SYNC_BLOCK=1
Extract Ethereum private key from your validator (we will need this key in the next step)
Copy 0gchaind keys unsafe-export-eth-key $WALLET_NAME
After entering the next command, a field will appear in which you should enter the key you received in the previous step. Note that the text you enter will not be displayed.
Copy read -sp "Enter your extracted private key: " PRIVATE_KEY && echo
Set the miner_key in the config.toml file
Copy sed -i 's|^miner_key = ""|miner_key = "'"$PRIVATE_KEY"'"|' $HOME/0g-storage-node/run/config.toml
Set var the Storage Node IP address
Copy ZGS_IP=$(wget -qO- eth0.me)
Edit the storage node config
Copy sed -i '
s|# network_dir = "network"|network_dir = "network"|g
s|# network_enr_tcp_port = 1234|network_enr_tcp_port = 1234|g
s|# network_enr_udp_port = 1234|network_enr_udp_port = 1234|g
s|# network_libp2p_port = 1234|network_libp2p_port = 1234|g
s|# network_discovery_port = 1234|network_discovery_port = 1234|g
s|# rpc_enabled = true|rpc_enabled = true|g
s|# db_dir = "db"|db_dir = "db"|g
s|# log_config_file = "log_config"|log_config_file = "log_config"|g
s|# log_directory = "log"|log_directory = "log"|g
s|# network_enr_address = ""|network_enr_address = "'"$ZGS_IP"'"|g
' $HOME/0g-storage-node/run/config.toml
Copy sed -i '
s|^log_sync_start_block_number = .*|log_sync_start_block_number = '"$ZGS_LOG_SYNC_BLOCK"'|g
s|^log_config_file = .*|log_config_file = "'"$ZGS_LOG_CONFIG_FILE"'"|g
s|^log_directory = .*|log_directory = "'"$ZGS_LOG_DIR"'"|g
s|^mine_contract_address = .*|mine_contract_address = "'"$MINE_CONTRACT"'"|g
s|^log_contract_address = .*|log_contract_address = "'"$LOG_CONTRACT_ADDRESS"'"|g
s|^reward_contract_address = .*|reward_contract_address = "'"$REWARD_CONTRACT"'"|g
' $HOME/0g-storage-node/run/config.toml
Update boot nodes addresses
Copy sed -i 's|^network_boot_nodes = .*|network_boot_nodes = ["/ip4/47.251.117.133/udp/1234/p2p/16Uiu2HAmTVDGNhkHD98zDnJxQWu3i1FL1aFYeh9wiQTNu4pDCgps","/ip4/47.76.61.226/udp/1234/p2p/16Uiu2HAm2k6ua2mGgvZ8rTMV8GhpW71aVzkQWy7D37TTDuLCpgmX"]|g' ~/0g-storage-node/run/config.toml
Set blockchain_rpc_endpoint
from your validator's (json-rpc endpoint). To connect your storage node to the validator.
Official 0g rpc endpoint:
Copy BLOCKCHAIN_RPC_ENDPOINT="https://evmrpc-testnet.0g.ai"
sed -i 's|^blockchain_rpc_endpoint = ".*"|blockchain_rpc_endpoint = "'"$BLOCKCHAIN_RPC_ENDPOINT"'"|' $HOME/0g-storage-node/run/config.toml
echo "export BLOCKCHAIN_RPC_ENDPOINT=\"$BLOCKCHAIN_RPC_ENDPOINT\"" >> ~/.bash_profile
Create a service file
Copy 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.toml
Restart=on-failure
RestartSec=10
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
EOF
Download the snapshot
Useful commands ⚙️
Stop the storage node
Copy sudo systemctl stop zgs
Check list of logs
Copy ls ~/0g-storage-node/run/log/
Check logs on a specific date. For example:
Copy tail -f ~/0g-storage-node/run/log/zgs.log.2024-06-04
Check the latest logs file
Copy tail -f ~/0g-storage-node/run/log/zgs.log.$(TZ=UTC date +%Y-%m-%d)
Check sync status
Copy curl -X POST http://localhost:5678 -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"zgs_getStatus","params":[],"id":1}' | jq
Delete node 🗑️
Copy sudo systemctl stop zgs && sudo systemctl disable zgs
sudo rm -rf /etc/systemd/system/zgs.service
sudo rm $(which zgs)
sudo rm -rf $HOME/0g-storage-node