Skip to content

Storage Node

In the 0G network, storage nodes play a vital role in maintaining the system’s decentralized storage layer. They are responsible for storing and serving data, ensuring data availability and reliability across the network. By running a storage node, you actively contribute to the network and earn rewards for your participation. This guide details the process of running a storage node, including hardware specifications and interaction with on-chain contracts.

ComponentStorage KV
Memory32 GB RAM
CPU8 cores
DiskSize matches the KV streams it maintains
Bandwidth-

1. Install Dependencies for Building from Source

Section titled “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
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
Terminal window
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Terminal window
. "$HOME/.cargo/env"
Terminal window
rm -rf 0g-storage-kv
git clone -b v1.4.0 https://github.com/0glabs/0g-storage-kv.git
Terminal window
cd 0g-storage-kv
git submodule update --init --recursive
cargo build --release

6. Copy the config_example.toml to config.toml and update the parameters

Section titled “6. Copy the config_example.toml to config.toml and update the parameters”
Terminal window
cp ~/0g-storage-kv/run/config_example.toml ~/0g-storage-kv/run/config.toml
nano ~/0g-storage-kv/run/config.toml

Paste this content:

Terminal window
#######################################################################
### Key-Value Stream Options ###
#######################################################################
# Streams to monitor.
stream_ids = ["000000000000000000000000000000000000000000000000000000000000f2bd", "000000000000000000000000000000000000000000000000000000000000f009", "0000000000000000000000000000000000000000000000000000000000016879", "0000000000000000000000000000000000000000000000000000000000002e3d"]
#######################################################################
### DB Config Options ###
#######################################################################
# Directory to store data.
db_dir = "db"
# Directory to store KV Metadata.
kv_db_dir = "kv.DB"
#######################################################################
### Log Sync Config Options ###
#######################################################################
blockchain_rpc_endpoint = "BLOCKCHAIN_RPC_ENDPOINT" #rpc endpoint, see testnet information
log_contract_address = "LOG_CONTRACT_ADDRESS" #flow contract address, see testnet information
# log_sync_start_block_number should be earlier than the block number of the first transaction that writes to the stream being monitored.
log_sync_start_block_number = 0
#######################################################################
### RPC Config Options ###
#######################################################################
# Whether to provide RPC service.
rpc_enabled = true
# HTTP server address to bind for public RPC.
rpc_listen_address = "0.0.0.0:6789"
# Zerog storage nodes to download data from.
zgs_node_urls = "http://127.0.0.1:5678,http://127.0.0.1:5679"
#######################################################################
### Misc Config Options ###
#######################################################################
log_config_file = "log_config"
Terminal window
sudo tee /etc/systemd/system/0gkv.service > /dev/null <<EOF
[Unit]
Description=0G-KV Node
After=network.target
[Service]
User=root
WorkingDirectory=/root/0g-storage-kv/run
ExecStart=/root/0g-storage-kv/target/release/zgs_kv --config /root/0g-storage-kv/run/config.toml
Restart=always
RestartSec=10
LimitNOFILE=65535
StandardOutput=journal
StandardError=journal
SyslogIdentifier=zgs_kv
[Install]
WantedBy=multi-user.target
EOF
Terminal window
sudo systemctl daemon-reload && \
sudo systemctl enable 0gkv && \
sudo systemctl start 0gkv && \
sudo systemctl status 0gkv

Check log:

Terminal window
sudo journalctl -u 0gkv -f -o cat
Terminal window
sudo systemctl stop 0gkv
Terminal window
sudo systemctl disable 0gkv
sudo rm /etc/systemd/system/0gkv.service
rm -rf $HOME/0g-storage-kv