# 💡BITTENSOR

Bittensor is a mining network, similar to Bitcoin, that includes built-in incentives designed to encourage computers to provide access to machine learning models in an efficient and censorship-resistant manner. These models can be queried by users seeking outputs from the network, for instance; generating text, audio, and images, or for extracting numerical representations of these input types. Under the hood, Bittensor’s *economic market*, is facilitated by a blockchain token mechanism, through which producers (***miners***) and the verification of the work done by those miners (***validators***) are rewarded. Miners host, train or otherwise procure machine learning systems into the network as a means of fulfilling the verification problems defined by the validators, like the ability to generate responses from prompts i.e. “What is the capital of Texas?.

The token based mechanism under which the miners are incentivized ensures that they are constantly driven to make their knowledge output more useful, in terms of speed, intelligence and diversity. The value generated by the network is distributed directly to the individuals producing that value, without intermediaries. Anyone can participate in this endeavour, extract value from the network, and govern Bittensor. The network is open to all participants, and no individual or group has full control over what is learned, who can profit from it, or who can access it.

To learn more about Bittensor, please read our [paper](https://bittensor.com/whitepaper).

# **🛠️ INSTALL**

There are three ways to install Bittensor

1. Through the installer:

```
$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/opentensor/bittensor/master/scripts/install.sh)"
```

1. With pip:

```
$ pip3 install bittensor
```

1. From source:

```
$ git clone https://github.com/opentensor/bittensor.git
$ python3 -m pip install -e bittensor/
```

1. Using Conda (recommended for **Apple M1**):

```
$ conda env create -f ~/.bittensor/bittensor/scripts/environments/apple_m1_environment.yml
$ conda activate bittensor
```

To test your installation, type:

```
$ btcli --help
```

or using python

```
import bittensor
```

**CUDA**

If you anticipate using PoW registration for subnets or the faucet (only available on staging), please install `cubit` as well for your version of python. You can find the Opentensor cubit implementation and instructions [here](https://github.com/opentensor/cubit).

For example with python 3.10:

```
pip install https://github.com/opentensor/cubit/releases/download/v1.1.2/cubit-1.1.2-cp310-cp310-linux_x86_64.whl
```

# **👛 WALLETS**

Wallets are the core ownership and identity technology around which all functions on Bittensor are carried out. Bittensor wallets consists of a coldkey and hotkey where the coldkey may contain many hotkeys, while each hotkey can only belong to a single coldkey. Coldkeys store funds securely, and operate functions such as transfers and staking, while hotkeys are used for all online operations such as signing queries, running miners and validating.

Wallets can be created in two ways.

1. Using the python-api

```
import bittensor
wallet = bittensor.wallet()
wallet.create_new_coldkey()
wallet.create_new_hotkey()
print (wallet)
"Wallet (default, default, ~/.bittensor/wallets/)"
```

1. Or using btcli

> Use the subcommand wallet or it's alias w:
> 

```
$ btcli wallet new_coldkey
    Enter wallet name (default):

    IMPORTANT: Store this mnemonic in a secure (preferably offline place), as anyone who has possession of this mnemonic can use it to regenerate the key and access your tokens.
    The mnemonic to the new coldkey is:
    **** *** **** **** ***** **** *** **** **** **** ***** *****
    You can use the mnemonic to recreate the key in case it gets lost. The command to use to regenerate the key using this mnemonic is:
    btcli w regen_coldkey --mnemonic post maid erode shy captain verify scan shoulder brisk mountain pelican elbow

$ btcli wallet new_hotkey
    Enter wallet name (default): d1
    Enter hotkey name (default):

    IMPORTANT: Store this mnemonic in a secure (preferably offline place), as anyone who has possession of this mnemonic can use it to regenerate the key and access your tokens.
    The mnemonic to the new hotkey is:
    **** *** **** **** ***** **** *** **** **** **** ***** *****
    You can use the mnemonic to recreate the key in case it gets lost. The command to use to regenerate the key using this mnemonic is:
    btcli w regen_hotkey --mnemonic total steak hour bird hedgehog trim timber can friend dry worry text
```

In both cases you should be able to view your keys by navigating to ~/.bittensor/wallets or viewed by running `btcli wallet list`

```
$ tree ~/.bittensor/
    .bittensor/                 # Bittensor, root directory.
        wallets/                # The folder containing all bittensor wallets.
            default/            # The name of your wallet, "default"
                coldkey         # You encrypted coldkey.
                coldkeypub.txt  # Your coldkey public address
                hotkeys/        # The folder containing all of your hotkeys.
                    default     # You unencrypted hotkey information.
```

Your default wallet `Wallet (default, default, ~/.bittensor/wallets/)` is always used unless you specify otherwise. Be sure to store your mnemonics safely. If you lose your password to your wallet, or the access to the machine where the wallet is stored, you can always regenerate the coldkey using the mnemonic you saved from above.

```
$ btcli wallet regen_coldkey --mnemonic **** *** **** **** ***** **** *** **** **** **** ***** *****
```

**Using the cli**

The Bittensor command line interface (`btcli`) is the primary command line tool for interacting with the Bittensor network. It can be used to deploy nodes, manage wallets, stake/unstake, nominate, transfer tokens, and more.

**Basic Usage**

To get the list of all the available commands and their descriptions, you can use:

```
btcli --help

usage: btcli <command> <command args>

bittensor cli v{bittensor.__version__}

commands:
  subnets (s, subnet) - Commands for managing and viewing subnetworks.
  root (r, roots) - Commands for managing and viewing the root network.
  wallet (w, wallets) - Commands for managing and viewing wallets.
  stake (st, stakes) - Commands for staking and removing stake from hotkey accounts.
  sudo (su, sudos) - Commands for subnet management.
  legacy (l) - Miscellaneous commands.
```

**Example Commands**

**Viewing Senate Proposals**

```
btcli root proposals
```

**Viewing Senate Members**

```
btcli root list_delegates
```

**Viewing Proposal Votes**

```
btcli root senate_vote --proposal=[PROPOSAL_HASH]
```

**Registering for Senate**

```
btcli root register
```

**Leaving Senate**

```
btcli root undelegate
```

**Voting in Senate**

```
btcli root senate_vote --proposal=[PROPOSAL_HASH]
```

**Miscellaneous Commands**

```
btcli legacy update
btcli legacy faucet
```

**Managing Subnets**

```
btcli subnets list
btcli subnets create
```

**Managing Wallets**

```
btcli wallet list
btcli wallet transfer
```

**Note**

Please replace the subcommands and arguments as necessary to suit your needs, and always refer to `btcli --help` or `btcli <command> --help` for the most up-to-date and accurate information.

For example:

```
btcli subnets --help

usage: btcli <command> <command args> subnets [-h] {list,metagraph,lock_cost,create,register,pow_register,hyperparameters} ...

positional arguments:
  {list,metagraph,lock_cost,create,register,pow_register,hyperparameters}
                        Commands for managing and viewing subnetworks.
    list                List all subnets on the network.
    metagraph           View a subnet metagraph information.
    lock_cost           Return the lock cost to register a subnet.
    create              Create a new bittensor subnetwork on this chain.
    register            Register a wallet to a network.
    pow_register        Register a wallet to a network using PoW.
    hyperparameters     View subnet hyperparameters.

options:
  -h, --help            show this help message and exit
```

**Post-Installation Steps**

To enable autocompletion for Bittensor CLI, run the following commands:

```
btcli --print-completion bash >> ~/.bashrc  # For Bash
btcli --print-completion zsh >> ~/.zshrc    # For Zsh
source ~/.bashrc  # Reload Bash configuration to take effect
```

#
