Skip to content

Add Local Development Docs #557

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 25, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions docs/local-build/create-subnet.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
---
title: "Create a Subnet (Locally)"
---

# Create a Subnet (Locally)

## Create it

To access the handy pre-provisioned development "Alice" account on your local chain, use:

```shell
btcli subnet create \
--subnet-name awesome-first-subnet \
--wallet.name sn-creator \
--subtensor.chain_endpoint ws://127.0.0.1:9945
```

However, note that this will fail if you do not have a sufficient $\tau$ balance:

```console
Subnet burn cost: τ 1,000.0000
Your balance of: τ 0.0000 is not enough to burn τ 1,000.0000 to register a subnet.
```

:::tip try it live

Check the burn cost to create a subnet on Bittensor main network and test network:

<link rel="stylesheet" href="https://unpkg.com/@antonz/[email protected]/dist/snippet.css" />
<codapi-settings url="https://bittensor-codex.com/v1">
</codapi-settings>

```shell
btcli subnet burn-cost --network finney
```
<codapi-snippet sandbox="python" editor="basic" init-delay="500">
</codapi-snippet>

```shell
btcli subnet burn-cost --network test
```
<codapi-snippet sandbox="python" editor="basic" init-delay="500">
</codapi-snippet>
:::

## Fund your subnet

To remedy your liquidity shortfall, transfer $\tau$ from the Alice account and try again.

1. First, get the ss58 address for the destination wallet for the transfer:
```shell
btcli w list
```
```shell
...
── Coldkey sn-creator ss58_address 5C9xw4gDyu11ocdpWrmhT1sbi4xEHCpzEMsyMA4jGfAZQofQ
└── Hotkey default ss58_address 5GVsCAY6RuSuoAA1E77xsHJ9PjdZJjJrRkNFDxVtRKPnw7TR
```
1. Execute the transfer from alice to the sn-creator wallet

```console
btcli wallet transfer \
--amount 1001 \
--wallet.name alice \
--destination "5GVsCAY6RuSuoAA1E77xsHJ9PjdZJjJrRkNFDxVtRKPnw7TR" \
--subtensor.chain_endpoint ws://127.0.0.1:9945
```

```shell
Do you want to transfer:
amount: τ 1,001.0000
from: alice : 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY
to: 5GVsCAY6RuSuoAA1E77xsHJ9PjdZJjJrRkNFDxVtRKPnw7TR
for fee: τ 0.0001 [y/n]: y
🌏 📡 Transferring...
```
1. Successfully create the subnet
119 changes: 119 additions & 0 deletions docs/local-build/deploy.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
---
title: "Build and Deploy the Blockchain"
---

# Deploy a Local Bittensor Blockchain Instance

This will will guide the user through deploying a local instance of Subtensor, Bittensor's L1 blockchain. This is useful in general Bittensor develoment, as it gives you more freedom over chain state than when working against mainnet or even testnet. For example, it is much easier to create subnets without having to wait for registration availability.

Each local chain is provisioned with an `alice` account with one million $\tau$.

In the following tutorial, we will also provision several wallets to serve as subnet creator, miner, and validator.

## Prerequisites

- Update your mac or linux workstation using your package manager
- Install [Bittensor SDK] and [BTCLI]


## Build your local Subtensor
### Install Rust/Cargo

To run locally, Substrate requires an up-to-date install of Cargo and Rust

Install from Rust's website:
```shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```
Update your shell's source to include Cargo's path:

```shell
source "$HOME/.cargo/env"
```

### Clone the Subtensor source

This step fetches the subtensor codebase to your local machine.

```bash
git clone https://github.com/opentensor/subtensor.git
```

### Setup Rust

This step ensures that you have the nightly toolchain and the WebAssembly (wasm) compilation target. Note that this step will run the Subtensor chain on your terminal directly, hence we advise that you run this as a background process using PM2 or other software.

Update to the nightly version of Rust:

```bash
./subtensor/scripts/init.sh
```

### Build

These steps initialize your local subtensor chain in development mode. These commands will set up and run a local subtensor.

Build the binary with the faucet feature enabled:

```bash
cd subtensor
cargo build -p node-subtensor --profile release
```

### Run

Next, run the localnet script and turn off the attempt to build the binary (as we have already done this above):

```bash
BUILD_BINARY=0 ./scripts/localnet.sh
```

## Validate

Ensure your local chain is working by checking the list of subnets.

Note the use of the `--chain_endpoint` flag to target the local chain, rather than, say, test network

```shell
btcli subnet list --subtensor.chain_endpoint ws://127.0.0.1:9945
btcli subnet list --network test
```

```console
Subnets
Network: custom


┃ ┃ Price ┃ Market Cap ┃ ┃ ┃ ┃ ┃
Netuid ┃ Name ┃ (τ_in/α_in) ┃ (α * Price) ┃ Emission (τ) ┃ P (τ_in, α_in) ┃ Stake (α_out) ┃ Supply (α) ┃ Tempo (k/n)
━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━
0 │ τ root │ 1.0000 τ/Τ │ τ 0.00 │ τ 0.0000 │ -, - │ Τ 0.00 │ 0.00 Τ /21M │ -/-
1 │ α apex │ 1.0000 τ/α │ τ 11.00 │ τ 0.0000 │ τ 10.00, 10.00 α │ 1.00 α │ 11.00 α /21M │ 77/100
────────┼────────┼─────────────┼─────────────┼──────────────┼────────────────────────┼───────────────┼──────────────┼─────────────
2 │ │ τ 1.0 │ │ τ 0.0 │ τ 10.00/175.00 (5.71%) │ │ │

```


```shell
```

```console

Subnets
Network: test


┃ ┃ Price ┃ Market Cap ┃ ┃ ┃ ┃ ┃
Netuid ┃ Name ┃ (τ_in/α_in) ┃ (α * Price) ┃ Emission (τ) ┃ P (τ_in, α_in) ┃ Stake (α_out) ┃ Supply (α) ┃ Tempo (k/n)
━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━
0 │ τ root │ 1.0000 τ/Τ │ τ 5.01m │ τ 0.0000 │ -, - │ Τ 3.10m │ 5.01m Τ /21M │ -/-
277 │ इ muv │ 0.4008 τ/इ │ τ 536.06k │ τ 0.4154 │ τ 199.85k, 498.63k इ │ 838.83k इ │ 1.34m इ /21M │ 39/99
3 │ γ templar │ 0.1534 τ/γ │ τ 219.03k │ τ 0.1690 │ τ 110.74k, 722.13k γ │ 706.14k γ │ 1.43m γ /21M │ 65/99
119 │ Ⲃ vida │ 0.0748 τ/Ⲃ │ τ 94.83k │ τ 0.1321 │ τ 44.77k, 598.65k Ⲃ │ 669.45k Ⲃ │ 1.27m Ⲃ /21M │ 81/99
1 │ α apex │ 0.0587 τ/α │ τ 70.03k │ τ 0.0405 │ τ 30.27k, 515.71k α │ 677.20k α │ 1.19m α /21M │ 63/99
13 │ ν dataverse │ 0.0467 τ/ν │ τ 63.12k │ τ 0.0645 │ τ 26.93k, 576.17k ν │ 774.11k ν │ 1.35m ν /21M │ 75/99
255 │ ዉ ethiopic_wu │ 0.0181 τ/ዉ │ τ 21.94k │ τ 0.0133 │ τ 10.72k, 592.40k ዉ │ 619.73k ዉ │ 1.21m ዉ /21M │ 17/99

...
```
76 changes: 76 additions & 0 deletions docs/local-build/provision-wallets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---
title: "Provision Wallets for Local Deploy"
---

This page continues the previous tutorial for local Bittensor development.

Now that your local Subtensor chain is deployed, you can provision wallets to serve the roles of subnet creator, miner and validator, to populate your local Bittensor ecosystem.

Every local blockchain is pre-provisioned with an "Alice" account, which is loaded with one million $\tau$.

## Access the Alice account

To access the handy pre-provisioned development "Alice" account on your local chain, use:
```shell
btcli wallet create --uri alice
```

Confirm Alice's massive $\tau$ bag.

```shell
btcli w balance --wallet.name alice --subtensor.chain_endpoint ws://127.0.0.1:9945
```

```console
Wallet Coldkey Balance
Network: custom

Wallet Name Coldkey Address Free Balance Staked Value Staked (w/slippage) Total Balance Total (w/slippage)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alice 5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY τ 999,999.8999 τ 0.0000 τ 0.0000 τ 999,999.8999 τ 999,999.8999



Total Balance τ 999,999.8999 τ 0.0000 τ 0.0000 τ 999,999.8999 τ 999,999.8999
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
```

## Provision wallets

You will need wallets for the different personas, i.e., subnet owner, subnet validator and subnet miner, in the subnet.

- The owner wallet creates and controls the subnet.
- The validator and miner will be registered to the subnet created by the owner. This ensures that the validator and miner can run the respective validator and miner scripts.

### Create a coldkey-only wallet for the subnet creator role (they do not need a hotkey):

```bash
btcli wallet new_coldkey \
--wallet.name sn-creator
```

### Set up the miner's wallet with a coldkey and hotkey:

```bash
btcli wallet new_coldkey \
--wallet.name miner
```

```bash
btcli wallet new_hotkey \
--wallet.name miner \
--wallet.hotkey default

```

### Set up the validator's wallet with a coldkey and hotkey:

```bash
btcli wallet new_coldkey \
--wallet.name validator
```
```bash
btcli wallet new_hotkey \
--wallet.name validator \
--wallet.hotkey default
```
17 changes: 16 additions & 1 deletion sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const sidebars = {
"subnets/schedule-coldkey-swap",
]
},
{
{
type: "category",
label: "Tools and Special Features",
link: {type: "doc", id: "tools",},
Expand All @@ -150,6 +150,21 @@ const sidebars = {
"utilities",
],
},

{
type: "category",
label: "Local Development",
link: {type: "doc", id: "local-build/deploy",},
collapsible: true,
collapsed: true,
items: [
"local-build/deploy",
"local-build/provision-wallets",
"local-build/create-subnet"
],
},


{
type: "category",
label: "Subtensor Nodes",
Expand Down