# Guide - Miner

Note: URLs are different for devnet, testnet and mainnet, always check the [Official Links](/tensorplex-docs/tensorplex-dojo-bittensor-subnet/official-links.md)!

To get started as a miner or validator, these are the common steps both a miner and validator have to go through.

***

## Getting Started

{% hint style="info" %}
Important

This setup guide uses specific tools to ensure a smooth installation process:

* [fnm](https://github.com/Schniz/fnm) for managing Node.js & npm versions (required for PM2)
* [Docker](https://docs.docker.com/engine/install/) and [Docker Compose](https://docs.docker.com/compose/)
  {% endhint %}

> Please ensure these prerequisites are installed on your system before proceeding with the installation steps, these are needed by both **validators and miners**.

1. Clone the project,

```bash
# In this guide, we will utilize the ~/opt directory as our preferred location.
cd ~/opt

# Clone the project
git clone https://github.com/tensorplex-labs/dojo.git
cd dojo/
```

2. Install PM2, one way is through fnm

```bash
# for linux, a convenience script is available
./scripts/setup/install_pm2.sh

# for mac/linux (if you do not trust the bash script)
curl -fsSL https://fnm.vercel.app/install | bash
# for windows, choose 1 of the following,
# based on https://github.com/Schniz/fnm?#manually
cargo install fnm
choco install fnm
scoop install fnm
winget install Schniz.fnm

# run any post-install shell setup scripts
# based on https://github.com/Schniz/fnm?#shell-setup

# assuming we are using zsh
echo 'eval "$(fnm env --use-on-cd --shell zsh)"' >> ~/.zshrc
# you can tell what shell you're using by running:
echo $0

# verify fnm installation
fnm --version

# get npm & node, and verify npm installation
fnm install lst/iron && npm --version

# install pm2 and verify installation
npm install -g pm2 && pm2 --version
```

3. Install Docker & Docker Compose

For Docker installation, see <https://docs.docker.com/engine/install/> for instructions

For Docker Compose installation, see <https://docs.docker.com/compose/install/linux> for instructions

```bash
# for linux, a convenience script is available
./dojo/scripts/setup/install_docker.sh

# verify both docker and docker compose are installed
docker --version
docker compose version
```

4. Create your wallets if they aren't created yet

```bash
# run btcli
make btcli
# create your wallets
btcli wallet new_coldkey
btcli wallet new_hotkey
```

5. Get some TAO and ensure you have enough TAO to cover the registration cost

```bash
# for mainnet, check netuid 52
btcli s list 
# for testnet, check netuid 98
btcli s list --subtensor.network test
# output from the `btcli s list ...` command
NETUID    N    MAX_N   EMISSION  TEMPO  RECYCLE        POW       SUDO
 0      128   128.00   0.00%     10    τ1.00000     10.00 M     5C4hrfjw9DjXZTzV3MwzrrAr9P1MJhSrvWGWqi1eSuyUpnhM
...
 98     17    256.00   0.00%     360   τ0.00001  18446744.07 T  5GTAfh3YTcokxWdGc3DgLV5y3hHB4Bs5PQGqw9fEn1WrcwWP
...
```

Note

the "RECYCLE" column represents the subnet registration cost

7. Register to our subnet

```bash
# run the dockerized btcli
make btcli
# register your wallet to our subnet
# for mainnet
btcli s register --wallet.name coldkey --wallet.hotkey hotkey --netuid 52 --subtensor.network finney
# for testnet
btcli s register --wallet.name coldkey --wallet.hotkey hotkey --netuid 98 --subtensor.network test
```

***

### Mining

There are currently 2 options when mining, where Option 1 is to connect to our centralized backend, and Option 2 is to self-host the full-stack worker platform application.

#### Option 1: Centralised Method

1. Create .env file with the following values first.

```bash
# copy .env.miner.example
cp .env.miner.example .env

# ENV's that needs to be filled for miners:

# for mainnet
DOJO_API_BASE_URL="https://dojo-api.tensorplex.ai"

# for testnet - uncomment below line if you are using testnet
#DOJO_API_BASE_URL="https://dojo-api-testnet.tensorplex.ai"

DOJO_API_KEY= # blank for now
WALLET_COLDKEY=# the name of the coldkey
WALLET_HOTKEY=# the name of the hotkey
AXON_PORT=8888 # port to serve requests over the public network for validators to call
```

2. Run the CLI to retrieve API Key and Subscription Key, see [Dojo CLI](https://github.com/tensorplex-labs/dojo#dojo-cli) for usage.

```bash
make dojo-cli

# remember to use tab completions to see list of commands
# authenticate and generate keys
authenticate
api_key generate
subscription_key generate

# list all keys
api_key list
subscription_key list
```

3. Complete the .env file with the variables below:

```bash
DOJO_API_KEY=# api key from step 2.
```

4. Start the miner by running the following commands:

```bash
# for mainnet
make miner-centralised network=mainnet
# for testnet
make miner-centralised network=testnet
```

#### Option 2: Decentralised Method

1. Create .env file with the following values first.

```bash
# copy .env.miner.example
cp .env.miner.example .env

# env vars that needs to be filled for miners:
DOJO_API_BASE_URL="http://worker-api:8080" # use this value
DOJO_API_KEY=# blank for now
WALLET_COLDKEY=# the name of the coldkey
WALLET_HOTKEY=# the name of the hotkey
AXON_PORT=8888 # port to serve requests over the public network for validators to call

# for dojo-ui
NEXT_PUBLIC_BACKEND_URL=http://localhost:3000

# for dojo-worker-api
REDIS_USERNAME=
REDIS_PASSWORD=

# postgres details
DB_HOST=postgres-miner:5432 # use this value
DB_NAME=db
DB_USERNAME=
DB_PASSWORD=
DATABASE_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}/${DB_NAME}

# aws credentials for S3
AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_S3_BUCKET_NAME=
S3_PUBLIC_URL=

JWT_SECRET=# generate a random JWT key
ETHEREUM_NODE=# get an ethereum endpoint URL from Infura
```

2. Start the worker api which will be connected to the CLI later.

```bash
make miner-worker-api
```

3. Run the CLI to retrieve API Key and Subscription Key, see [Dojo CLI](https://github.com/tensorplex-labs/dojo#dojo-cli) for usage.

```bash
make dojo-cli
```

4. Grab the API key and add it to your .env file

```bash
DOJO_API_KEY=# api key from earlier
```

5. Now, run the full miner service.

```bash
# for mainnet
make miner-decentralised network=mainnet
# for testnet
make miner-decentralised network=testnet

# read miner logs using the following:
# for mainnet
make miner-decentralised-logs network=mainnet
# for testnet
make miner-decentralised-logs network=testnet
```


---

# 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.tensorplex.ai/tensorplex-docs/tensorplex-dojo-bittensor-subnet/guide-miner.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.
