# Join Testnet Subnet (New)

{% hint style="info" %}
NOT LIVE. CODEBASE AND SUBNET DEPLOYMENT COMING SOON.
{% endhint %}

## Requirements

* Linux Environment

  <div data-gb-custom-block data-tag="hint" data-style="success" class="hint hint-success"><p>Only tested on Linux.</p></div>

  * If on Windows, follow the [WSL documentation](https://docs.hypertensor.org/troubleshooting#running-on-windows-using-wsl)
* Python 3.10 or higher
* When using VPS providers, use VPS providers with routed public IPs, not NAT-based public IPs like AWS EC2.

  <div data-gb-custom-block data-tag="hint" data-style="info" class="hint hint-info"><p>You can know your server is the right type by running <code>ip a</code> or <code>ipconfig</code>. If you see the public IP, the server can function as a subnet node.</p></div>

***

## Install

```
git clone https://github.com/hypertensor-blockchain/subnet-template.git
cd subnet-template
python -m venv .venv
source .venv/bin/activate
pip install .
cp -a .env.example .env
```

***

## Troubleshooting

Having issues installing?

#### Error

{% code overflow="wrap" %}

```
ERROR: Could not build wheels for fastecdsa, which is required to install pyproject.toml-based projects
```

{% endcode %}

#### Solution

**Apt**

```
sudo apt-get install gcc python3-dev libgmp3-dev
```

**Yum**

```
sudo yum groupinstall "Development Tools" -y && \
sudo yum install python3-devel gmp-devel libffi-devel bzip2 bzip2-devel zlib-devel xz-devel -y
```

***

**Copy and paste the following somewhere:**

Fill this out as you go along each step as a reference for the later steps.

{% hint style="info" %}
You can use a .txt file in the following, but ensure **not to use a .txt file with markdown** because it will produce hidden characters; most command interfaces will include them and break CLI commands.
{% endhint %}

1. **Coldkey**
   1. **Address**: `<address>`
   2. **Private key**: `<private key>`
2. **Hotkey**
   1. **Address**: `<address>`
   2. **Private key**: `<private key>`
3. **Peer ID**
   1. **Address**: `<address>`
   2. **Path of peer ID private key**: `<path>`
4. **Public IP**: `<public ip>`
5. **Port**: `<port>`

***

For each command, you can run `<command> --help` for information.

***

### 1. Generate Coldkey and Hotkey

Once both keys are generated, it will output the mnemonic phrase, private key, and address. Store the information in a safe place.

#### Generate Coldkey

You can also use your coldkey generated by your [wallet](https://docs.hypertensor.org/blockchain/wallet) instead of the CLI.

```bash
python -m subnet.cli.hypertensor.keys.generate_key --words 12
```

Save the coldkey **private key** in a safe space to be used later when registering the node on-chain.

#### Generate Hotkey

```bash
python -m subnet.cli.hypertensor.keys.generate_key --words 12
```

Save the hotkey **private key** in a safe space to be used later when starting the subnet node.

***

### 2. Generate Private Keys

Generate 3 private keys for your peer IDs: the **main peer ID**, the **bootnode peer ID**, and the **client peer ID**. This will automatically generate 3 private key files that you will see in the root directory.

**Save all 3 peer IDs in the logs in a safe place** for later steps.

{% hint style="info" %}
If running multiple nodes on a single server, ensure all paths are unique.
{% endhint %}

```bash
keygen --path main-node01.key
```

***

### 3. Fund Keys

Visit the [Discord faucet](https://docs.hypertensor.org/testnet/faucet) and fund both the coldkey and hotkey.

{% hint style="info" %}
It is suggested to fund the coldkey from the faucet and **send 1 TENSOR to the hotkey from the coldkey** via the [wallet](https://docs.hypertensor.org/blockchain/wallet) on the [explorer](https://docs.hypertensor.org/testnet/explorer). The hotkey is used for consensus, and while running consensus does not have block fees, all wallets are required to have a minimum of 0.0000000000000005 TENSOR to be a live account. By sending the hotkey 1 TENSOR, you will accomplish this requirement.
{% endhint %}

The **coldkey will need at least 100 TENSOR** to stake on registration, plus a dynamic burn fee. The faucet will give 500 TENSOR for each request and should be sufficient. If not, contact us on Discord.

1. Use the [faucet](https://docs.hypertensor.org/testnet/faucet) to fund the coldkey
2. Send 1 TENSOR from the coldkey to the hotkey, or use the [faucet](https://docs.hypertensor.org/testnet/faucet) (faucet may have a cooldown, if so, use the wallet)

***

### 4. Register Subnet Node

Register the subnet node on-chain and retrieve your subnet node ID. **Put the subnet node ID somewhere** to be used for later steps.

Run `register_node --help` or visit `subnet/cli/hypertensor/node/register.py` to view the full list of available arguments.

**Before running:**

* Know what your coldkey and hotkey are
* Know what subnet ID you're registering to
* Know your peer IDs
* Have the coldkey private key ready

```bash
python -m subnet.cli.hypertensor.node.register \
--subnet_id 128001 \
--hotkey HOTKEY ACCOUNT ID \
--peer_id PEER ID \
--delegate_reward_rate 0.125 \
--stake_to_be_added 120.00 \
--max_burn_amount 100.00 \
--private_key COLDKEY PRIVATE KEY
```

***

### 5. Run Node

We suggest using a terminal multiplexer or similar of your choosing, such as [tmux](https://github.com/tmux/tmux/wiki) or [pm2](https://pm2.keymetrics.io/docs/usage/quick-start/).

#### Before running:

* Know public IP (run `curl ifconfig.me`)
* Ensure you have no firewalls blocking connections
* Choose and open a port
  * Replace `31330` with the port of your choosing
* Have your subnet node ID (Logged during registration in the previous step)
* Have your private key generated in the [Generate Private Keys](#generate-private-keys) step
* Ensure your hotkey is funded with at least 0.0000000000000005 TENSOR

{% code overflow="wrap" %}

```bash
python -m subnet.cli.run_node \
--private_key_path main-node01.key \
--ip PUBLIC IP \
--port 31330 \
--bootstrap /ip4/45.55.93.44/tcp/31330/p2p/12D3KooWAuMTLVHpask4HnnYuQd7SGhBuGiScuTCHFaAbuhK8t8q \
--subnet_id 128001 \
--subnet_node_id SUBNET_NODE_ID \
--tensor_private_key HOTKEY_PRIVATE_KEY
```

{% endcode %}

{% hint style="info" %}
If **connecting to a bootnode fails, there is a 20 second cooldown**. For each failed attempt, you cannot connect to the subnet for at least 20 seconds.
{% endhint %}

**Once run, you will see many logs, including:**

```bash
[INFO] [server/1.0.0] Connected to bootstrap node ...
```

**How to resolve network issues:**

* Ensure that your Internet provider gives you a public IP address
* Choose a specific port for the subnet template server, for example, 31330
* If you have a firewall or NAT, configure it to allow incoming connections to the chosen TCP port
* Ensure your node is staked with the correct peer ID on-chain.

**Once running:**

Keep running **forever**.

***

## Run Multiple Nodes

Test the scalability of the Subnet Template by running multiple nodes from a single server.

#### Repeat steps 1-5 for each node, using a separate command prompt and port for each.
