# Chain Setup Guide

## SPHX Testnet Setup Guide

### Introduction

This guide provides detailed steps to set up and run a node on the SPHX Testnet. By the end of this guide, you will have your node configured, connected to bootnodes, and running as a systemd service for easy management.

***

### Prerequisites

Before setting up the node, ensure you have:

1. **A server or machine** with the following minimum requirements:
   * 2 CPU cores
   * 4 GB of RAM
   * 100 GB SSD storage
   * A stable internet connection
2. **Basic command-line knowledge** to execute commands and manage configurations.

***

### Step 1: Install SPHX Binaries

Start by downloading and installing the latest version of SPHX binaries. You can find the most recent release [here](https://github.com/sphx-dev/infra-chain/releases/tag/v0.0.5).

For Linux, follow these steps:

```bash
# Download SPHX binary
https://github.com/sphx-dev/infra-chain/releases/download/v0.0.5/sphx

# Move the sphxd binary to a location in your PATH
sudo mv sphx /usr/local/bin/sphxd

# Verify the installation
sphxd version
```

***

### Step 2: Initialize Your Node

Next, initialize the node with your desired moniker (node name):

```bash
sphxd init <Your_Node_Name> --chain-id sphx-testnet
```

This command will create the configuration files needed to run the node. The configuration files will be located in `~/.sphxd`.

***

### Step 3: Configure Bootnodes and Seeds

Edit the `config.toml` file located in `~/.sphxd/config/` to include the provided bootnodes. Use a text editor such as nano:

```bash
nano ~/.sphxd/config/config.toml
```

Find the `persistent_peers` field and add the following bootnodes:

```toml
persistent_peers = "4000c9ae9c849ca02b2a19844265bee8ebf1e0f3@52.91.173.91:26656,9070c993919d31b1f02b872f731f59bb901f0512@54.172.101.52:26656"
```

Make sure to also adjust the `seeds` field if needed (this is optional if the bootnodes are working well).

***

### Step 4: Download Genesis File

Download the latest SPHX Testnet genesis file and place it in the configuration folder:

```bash
wget -O ~/.sphxd/config/genesis.json https://github.com/sphx-dev/infra-chain/releases/download/v0.0.5/genesis.json
```

***

### Step 5: Configure Systemd Service

To ensure your node runs continuously and restarts automatically in case of a reboot or failure, you can create a systemd service file.

#### Create `blockchain.service` File

Create a new systemd service file by running:

```bash
sudo nano /etc/systemd/system/blockchain.service
```

Add the following content to the file:

```ini
[Unit]
Description=SPHX Blockchain Node
After=network.target

[Service]
User=<your_user>
ExecStart=/usr/local/bin/sphxd start
Restart=always
RestartSec=3
LimitNOFILE=4096

[Install]
WantedBy=multi-user.target
```

Make sure to replace `<your_user>` with your actual username.

#### Enable and Start the Service

After creating the service file, reload systemd and enable the service to start automatically:

```bash
# Reload systemd to recognize the new service
sudo systemctl daemon-reload

# Enable the service to start on boot
sudo systemctl enable blockchain.service

# Start the blockchain node service
sudo systemctl start blockchain.service
```

Check the status of the service to ensure it’s running:

```bash
sudo systemctl status blockchain.service
```

***

### Step 6: Verify Node Synchronization

Once your node is running as a service, you can check its synchronization status using:

```bash
sphxd status
```

This will provide you with details about the current block height and whether your node is catching up with the network.

***

### Step 7: Monitoring and Logs

To monitor your node’s logs, use the following command:

```bash
journalctl -u blockchain.service -f
```

This will provide a real-time view of the logs generated by your node. If any issues arise, you can troubleshoot by reviewing these logs.

***

### Final Notes

* **System Security**: Consider securing your server by using SSH key authentication, configuring a firewall, and monitoring resource usage.
* **Community and Support**: Join the SPHX community for updates and assistance in case of issues.
* **Regular Updates**: Make sure to periodically update your node software as new versions of SPHX are released to ensure compatibility with the latest network features.

***

By following these steps, your SPHX Testnet node should be up and running smoothly as a systemd service. If you encounter any issues or need further assistance, don’t hesitate to reach out to the community or consult the official documentation.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sphx.io/chain/chain-setup-guide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
