Sitemap

0G Storage Node Guide

4 min readFeb 5, 2025

--

Press enter or click to view image in full size

Hello. In the previous tutorial, we implemented a validator with a light snapshot that took up little space. Now we want to implement a storage node on the same server.

To run the Node Validator, refer to the tutorial below. My suggestion is to run both.

The prerequisites are the same. If you have more hard drives, you have less risk of running out of space.

  • Memory: 16 GB RAM
  • CPU: 4 cores
  • Disk: 500GB / 1T NVME SSD
  • Bandwidth: 500 MBps for Download / Upload

START

sudo apt-get update
sudo apt-get install clang cmake build-essential

If you are asked a question along the way, press the y key.

Press enter or click to view image in full size
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
Press enter or click to view image in full size
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Enter

. "$HOME/.cargo/env"
Press enter or click to view image in full size
git clone https://github.com/0glabs/0g-storage-node.git
cd 0g-storage-node
git checkout v0.8.4
git submodule update --init
Press enter or click to view image in full size
sudo apt install cargo
sudo apt update
sudo apt install -y pkg-config libssl-dev
cargo build --release

It may take a while.

Press enter or click to view image in full size

👾 If you receive a warning, you can use the following codes:

unset OPENSSL_DIR
cargo clean
cargo build --release

..

wget -O $HOME/0g-storage-node/run/config-testnet-turbo.toml https://josephtran.co/config-testnet-turbo.toml
printf '\033[34mEnter your private key: \033[0m' && read -s PRIVATE_KEY

So enter the private key here. I suggest you enter the validator wallet.
To get the private key, you can add 24 words in Metamask or OKX Wallet and then remove the private key.

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"
Press enter or click to view image in full size
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
Press enter or click to view image in full size

Snapshot

We download snapshots to speed up syncing.

sudo systemctl stop zgs
sudo apt-get update
sudo apt-get install wget lz4 aria2 pv -y
cd $HOME
rm storage_0gchain_snapshot.lz4
aria2c -x 16 -s 16 -k 1M https://josephtran.co/storage_0gchain_snapshot.lz4
Press enter or click to view image in full size

Skip this section if you don’t need it.

This process will take some time. If you think your internet might be down, redirect it to screen.

apt install screen 
screen -S snapshot

Now run the snapshot download commands.

Get Fmusicmc’s stories in your inbox

Join Medium for free to get updates from this writer.

And navigate to the background with control+A+D

To see the screen, type the code below.

screen -R snapshot

Extract

rm -rf $HOME/0g-storage-node/run/db
lz4 -c -d storage_0gchain_snapshot.lz4 | pv | tar -x -C $HOME/0g-storage-node/run
Press enter or click to view image in full size

Start Node

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
sudo systemctl daemon-reload && \
sudo systemctl enable zgs && \
sudo systemctl restart zgs && \
sudo systemctl status zgs
Press enter or click to view image in full size

Control +C

Logs

tail -f ~/0g-storage-node/run/log/zgs.log.$(date +%Y-%m-%d) | grep -v "discv5\|network\|router\|Peer"
Press enter or click to view image in full size
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
Press enter or click to view image in full size

is ok Over time, your peer numbers should increase.

END

Pay attention, so far only these tasks were unlocked and we did them. In the future, they may have many tasks to do. I don’t think it’s too hard. This article will be updated if they put hard tasks. We can follow the announcements on Telegram and Twitter

--