Bittensor Wallet
The Bittensor Wallet SDK is a Python interface for a powerful Rust-based Bittensor wallet functionality. You do not need to know Rust to use this Wallet SDK. However, if you want to contribute to the Rust components of this Wallet SDK, the Rust source is located in the src directory. You can look at the development history by inspecting the Changelog.md.
Documentation
For a full documentation on how to use btwallet, see the Bittensor Wallet SDK section on the developer documentation site.
Before you proceed
If you installed either Bittensor SDK version 9.x.x or BTCLI version 9.x.x then the Wallet SDK 3.x.x is already installed. The below installation steps are only for a standalone installation of the Wallet SDK 3.x.x package.
Install
Follow the below steps to install the Bittensor Wallet SDK:
From PyPI
Use this option if you want to use the Wallet SDK.
python3 -m venv btwallet-venv
source btwallet-venv/bin/activate
pip install bittensor-wallet
From source
Use this option if you want to develop your application using the Wallet SDK.
python3 -m venv btwallet-venv
source venv/bin/activate
git clone https://github.com/opentensor/btwallet.git
cd btwallet
pip install maturin
maturin develop
After the maturin develop command completes, run the below command:
pip list
You will see bittensor-wallet in the list on installed packages. This means the installation was successful.
Verify your installation
In the python3 interpreter, run the below code to verify that your installation was successful. See an example output below:
import bittensor_wallet
print(bittensor_wallet.__version__)
>>> 3.x.x
The above will print the Wallet SDK version you just installed, i.e., 3.x.x, confirming that the installation was successful.
Usage examples
1. Create a wallet
In the python3 interpreter, run the below code:
from bittensor_wallet import Wallet
wallet = Wallet()
wallet.create()
If a wallet with the name "default" already exists, then you will see a message. If it doesn't exist, then the above code will create both a coldkey and a hotkey and displays the following information, including your mnemonic (mnemonics are replaced with x in the below example for security):
IMPORTANT: Store this mnemonic in a secure (preferable 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:
forward xxxx xxx xxx xxxx xxxx xxxx xxx xx xx xx actress
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 "forward xxxx xxx xxx xxxx xxxx xxxx xxx xx xx xx actress"
Specify password for key encryption:
Retype your password:
IMPORTANT: Store this mnemonic in a secure (preferable 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:
fuel xxxx xxx xxx xxxx xxxx xxxx xxx xx xx xxx bind
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 "fuel xxxx xxx xxx xxxx xxxx xxxx xxx xx xx xxx bind"
name: 'default', hotkey: 'default', path: '~/.bittensor/wallets/'
>>> print(wallet)
Wallet (Name: 'default', Hotkey: 'default', Path: '~/.bittensor/wallets/')
>>>
2. Pass arguments to a class other than the default
name (str): The name of the wallet, used to identify it among possibly multiple wallets.
hotkey (str): String identifier for the hotkey.
path (str): File system path where wallet keys are stored.
config (Config): Bittensor configuration object.
In the python3 interpreter, run the below code. See an example below (only partial is shown):
from bittensor_wallet import Wallet
my_name = "my_wallet_name"
my_path = "path_to_my_wallet"
my_hotkey = "name_of_my_hotkey"
my_wallet = Wallet(name=my_name, path=my_path, hotkey=my_hotkey)
my_wallet.create()
>>> IMPORTANT: Store this mnemonic in a secure (preferable offline place), as anyone who has possession of this mnemonic can use it to regenerate the key and access your tokens.
The above will create a wallet with "my_wallet_name".