> For the complete documentation index, see [llms.txt](https://uthersunlighter.gitbook.io/uthersunlighter/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://uthersunlighter.gitbook.io/uthersunlighter/0g.md).

# 0G

### 0G Storage KV Node Setup with Code and Explanation

Here's an example of how to set up a 0G Storage KV node with code, along with an explanation of each step:

### 1. Install Dependencies

```
# Update system packages
sudo apt-get update
sudo apt-get upgrade -y

# Install required dependencies
sudo apt-get install -y clang cmake build-essential
```

**Explanation**: Before starting the setup process, it's important to ensure that the system packages are up-to-date and the required dependencies are installed. The `apt-get update` command updates the package lists from the repositories, while `apt-get upgrade` upgrades the installed packages to their latest versions. The `apt-get install` command installs the necessary dependencies for building the 0G Storage KV node, including `clang`, `cmake`, and `build-essential`.

### 2. Install Rust

```
# Install Rust using rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
```

**Explanation**: The 0G Storage KV node is written in Rust, so you need to install the Rust programming language. The `curl` command downloads the `rustup` installer, which is a tool for installing and managing Rust versions. The `sh` command executes the installer script, and the `source` command sets up the Rust environment variables for the current shell session.

### 3. Install Go

```
# Download and install Go
wget https://golang.org/dl/go1.19.5.linux-amd64.tar.gz
sudo tar -C /usr/local -xzf go1.19.5.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
```

**Explanation**: The 0G Storage KV node also requires Go programming language. The `wget` command downloads the Go tarball from the official website. The `tar` command extracts the tarball to the `/usr/local` directory, which is a common location for installing system-wide software. The `export` command adds the Go binary directory to the system's `PATH` environment variable, allowing you to run Go commands from anywhere in the terminal.

### 4. Build zgs\_node Binary

```
# Clone the 0g-storage-node repository
git clone https://github.com/0g-network/0g-storage-node.git
cd 0g-storage-node
git submodule update --init --recursive

# Build the zgs_node binary
cargo build --release
```

**Explanation**: The next step is to build the `zgs_node` binary from the 0G Storage KV node source code. The `git clone` command downloads the repository from GitHub to your local machine. The `cd` command changes the current directory to the cloned repository. The `git submodule update` command initializes and updates the Git submodules, which are dependencies used by the project. Finally, the `cargo build --release` command compiles the Rust code and generates the optimized `zgs_node` binary in the `target/release` directory.

### 5. Configure Storage Node

```
# config.toml
[network]
network_enr_address = "your_node_ip_address"
# Other network settings...

[rpc]
# RPC settings...

[database]
directory = "/path/to/database"

[logging]
# Logging settings...
```

**Explanation**: Before running the storage node, you need to configure it by modifying the `config.toml` file. The `network_enr_address` setting should be set to the IP address of your storage node. You can also customize other network settings, RPC configurations, database directory, and logging options according to your requirements.

### 6. Run Storage Node

```
# Start the storage node service
./target/release/zgs_node --config config.toml
```

**Explanation**: Finally, you can run the storage node service using the `zgs_node` binary and the configured `config.toml` file. The `./target/release/zgs_node` command executes the optimized binary, and the `--config` flag specifies the path to the configuration file.Make sure to replace the `network_enr_address` with your node's IP address and adjust other configuration settings as needed.
