bittensor.wallet#

Implementation of the wallet class, which manages balances with staking and transfer. Also manages hotkey and coldkey.

Module Contents#

Classes#

wallet

The wallet class in the Bittensor framework handles wallet functionality, crucial for participating in

Functions#

display_mnemonic_msg(keypair, key_type)

Display the mnemonic and a warning message to keep the mnemonic safe.

bittensor.wallet.display_mnemonic_msg(keypair, key_type)#

Display the mnemonic and a warning message to keep the mnemonic safe.

Parameters:
  • keypair (Keypair) – Keypair object.

  • key_type (str) – Type of the key (coldkey or hotkey).

class bittensor.wallet.wallet(name=None, hotkey=None, path=None, config=None)#

The wallet class in the Bittensor framework handles wallet functionality, crucial for participating in the Bittensor network. It manages two types of keys: coldkey and hotkey, each serving different purposes in network operations. Each wallet contains a coldkey and a hotkey.

The coldkey is the user’s primary key for holding stake in their wallet and is the only way that users can access Tao. Coldkeys can hold tokens and should be encrypted on your device.

The coldkey is the primary key used for securing the wallet’s stake in the Bittensor network (Tao) and is critical for financial transactions like staking and unstaking tokens. It’s recommended to keep the coldkey encrypted and secure, as it holds the actual tokens.

The hotkey, in contrast, is used for operational tasks like subscribing to and setting weights in the network. It’s linked to the coldkey through the metagraph and does not directly hold tokens, thereby offering a safer way to interact with the network during regular operations.

Parameters:
name#

The name of the wallet, used to identify it among possibly multiple wallets.

Type:

str

path#

File system path where wallet keys are stored.

Type:

str

hotkey_str#

String identifier for the hotkey.

Type:

str

_hotkey, _coldkey, _coldkeypub

Internal representations of the hotkey and coldkey.

Type:

bittensor.Keypair

create_if_non_existent, create, recreate

Methods to handle the creation of wallet keys.

get_coldkey, get_hotkey, get_coldkeypub

Methods to retrieve specific keys.

set_coldkey, set_hotkey, set_coldkeypub

Methods to set or update keys.

hotkey_file, coldkey_file, coldkeypub_file

Properties that return respective key file objects.

regenerate_coldkey, regenerate_hotkey, regenerate_coldkeypub

Methods to regenerate keys from different sources.

config, help, add_args

Utility methods for configuration and assistance.

The wallet class is a fundamental component for users to interact securely with the Bittensor network, facilitating both operational tasks and transactions involving value transfer across the network.

Example Usage:

# Create a new wallet with default coldkey and hotkey names my_wallet = wallet()

# Access hotkey and coldkey hotkey = my_wallet.get_hotkey() coldkey = my_wallet.get_coldkey()

# Set a new coldkey my_wallet.new_coldkey(n_words=24) # number of seed words to use

# Update wallet hotkey my_wallet.set_hotkey(new_hotkey)

# Print wallet details print(my_wallet)

# Access coldkey property, must use password to unlock my_wallet.coldkey

property hotkey_file: bittensor.keyfile#

Property that returns the hotkey file.

Returns:

The hotkey file.

Return type:

bittensor.keyfile

property coldkey_file: bittensor.keyfile#

Property that returns the coldkey file.

Returns:

The coldkey file.

Return type:

bittensor.keyfile

property coldkeypub_file: bittensor.keyfile#

Property that returns the coldkeypub file.

Returns:

The coldkeypub file.

Return type:

bittensor.keyfile

property hotkey: bittensor.Keypair#

Loads the hotkey from wallet.path/wallet.name/hotkeys/wallet.hotkey or raises an error. :returns: hotkey loaded from config arguments. :rtype: hotkey (Keypair)

Raises:
  • KeyFileError – Raised if the file is corrupt of non-existent.

  • CryptoKeyError – Raised if the user enters an incorrec password for an encrypted keyfile.

Return type:

bittensor.Keypair

property coldkey: bittensor.Keypair#

Loads the hotkey from wallet.path/wallet.name/coldkey or raises an error. :returns: colkey loaded from config arguments. :rtype: coldkey (Keypair)

Raises:
  • KeyFileError – Raised if the file is corrupt of non-existent.

  • CryptoKeyError – Raised if the user enters an incorrec password for an encrypted keyfile.

Return type:

bittensor.Keypair

property coldkeypub: bittensor.Keypair#

Loads the coldkeypub from wallet.path/wallet.name/coldkeypub.txt or raises an error. :returns: colkeypub loaded from config arguments. :rtype: coldkeypub (Keypair)

Raises:
  • KeyFileError – Raised if the file is corrupt of non-existent.

  • CryptoKeyError – Raised if the user enters an incorrect password for an encrypted keyfile.

Return type:

bittensor.Keypair

regen_coldkeypub#
regen_coldkey#
regen_hotkey#
classmethod config()#

Get config from the argument parser.

Returns:

Config object.

Return type:

bittensor.config

classmethod help()#

Print help to stdout.

classmethod add_args(parser, prefix=None)#

Accept specific arguments from parser.

Parameters:
__str__()#

Returns the string representation of the Wallet object.

Returns:

The string representation.

Return type:

str

__repr__()#

Returns the string representation of the Wallet object.

Returns:

The string representation.

Return type:

str

create_if_non_existent(coldkey_use_password=True, hotkey_use_password=False)#

Checks for existing coldkeypub and hotkeys and creates them if non-existent.

Parameters:
  • coldkey_use_password (bool, optional) – Whether to use a password for coldkey. Defaults to True.

  • hotkey_use_password (bool, optional) – Whether to use a password for hotkey. Defaults to False.

Returns:

The Wallet object.

Return type:

wallet

create(coldkey_use_password=True, hotkey_use_password=False)#

Checks for existing coldkeypub and hotkeys and creates them if non-existent.

Parameters:
  • coldkey_use_password (bool, optional) – Whether to use a password for coldkey. Defaults to True.

  • hotkey_use_password (bool, optional) – Whether to use a password for hotkey. Defaults to False.

Returns:

The Wallet object.

Return type:

wallet

recreate(coldkey_use_password=True, hotkey_use_password=False)#

Checks for existing coldkeypub and hotkeys and creates them if non-existent.

Parameters:
  • coldkey_use_password (bool, optional) – Whether to use a password for coldkey. Defaults to True.

  • hotkey_use_password (bool, optional) – Whether to use a password for hotkey. Defaults to False.

Returns:

The Wallet object.

Return type:

wallet

set_hotkey(keypair, encrypt=False, overwrite=False)#

Sets the hotkey for the wallet.

Parameters:
  • keypair (bittensor.Keypair) – The hotkey keypair.

  • encrypt (bool, optional) – Whether to encrypt the hotkey. Defaults to False.

  • overwrite (bool, optional) – Whether to overwrite an existing hotkey. Defaults to False.

Returns:

The hotkey file.

Return type:

bittensor.keyfile

set_coldkeypub(keypair, encrypt=False, overwrite=False)#

Sets the coldkeypub for the wallet.

Parameters:
  • keypair (bittensor.Keypair) – The coldkeypub keypair.

  • encrypt (bool, optional) – Whether to encrypt the coldkeypub. Defaults to False.

  • overwrite (bool, optional) – Whether to overwrite an existing coldkeypub. Defaults to False.

Returns:

The coldkeypub file.

Return type:

bittensor.keyfile

set_coldkey(keypair, encrypt=True, overwrite=False)#

Sets the coldkey for the wallet.

Parameters:
  • keypair (bittensor.Keypair) – The coldkey keypair.

  • encrypt (bool, optional) – Whether to encrypt the coldkey. Defaults to True.

  • overwrite (bool, optional) – Whether to overwrite an existing coldkey. Defaults to False.

Returns:

The coldkey file.

Return type:

bittensor.keyfile

get_coldkey(password=None)#

Gets the coldkey from the wallet.

Parameters:

password (str, optional) – The password to decrypt the coldkey. Defaults to None.

Returns:

The coldkey keypair.

Return type:

bittensor.Keypair

get_hotkey(password=None)#

Gets the hotkey from the wallet.

Parameters:

password (str, optional) – The password to decrypt the hotkey. Defaults to None.

Returns:

The hotkey keypair.

Return type:

bittensor.Keypair

get_coldkeypub(password=None)#

Gets the coldkeypub from the wallet.

Parameters:

password (str, optional) – The password to decrypt the coldkeypub. Defaults to None.

Returns:

The coldkeypub keypair.

Return type:

bittensor.Keypair

create_coldkey_from_uri(uri, use_password=True, overwrite=False, suppress=False)#

Creates coldkey from suri string, optionally encrypts it with the user’s inputed password. :param uri: (str, required):

URI string to use i.e. /Alice or /Bob

Parameters:
  • use_password (bool, optional) – Is the created key password protected.

  • overwrite (bool, optional) – Will this operation overwrite the coldkey under the same path <wallet path>/<wallet name>/coldkey

  • uri (str) –

  • suppress (bool) –

Returns:

this object with newly created coldkey.

Return type:

wallet (bittensor.wallet)

create_hotkey_from_uri(uri, use_password=False, overwrite=False, suppress=False)#

Creates hotkey from suri string, optionally encrypts it with the user’s inputed password. :param uri: (str, required):

URI string to use i.e. /Alice or /Bob

Parameters:
  • use_password (bool, optional) – Is the created key password protected.

  • overwrite (bool, optional) – Will this operation overwrite the hotkey under the same path <wallet path>/<wallet name>/hotkeys/<hotkey>

  • uri (str) –

  • suppress (bool) –

Returns:

this object with newly created hotkey.

Return type:

wallet (bittensor.wallet)

new_coldkey(n_words=12, use_password=True, overwrite=False, suppress=False)#

Creates a new coldkey, optionally encrypts it with the user’s inputed password and saves to disk. :param n_words: (int, optional):

Number of mnemonic words to use.

Parameters:
  • use_password (bool, optional) – Is the created key password protected.

  • overwrite (bool, optional) – Will this operation overwrite the coldkey under the same path <wallet path>/<wallet name>/coldkey

  • n_words (int) –

  • suppress (bool) –

Returns:

this object with newly created coldkey.

Return type:

wallet (bittensor.wallet)

create_new_coldkey(n_words=12, use_password=True, overwrite=False, suppress=False)#

Creates a new coldkey, optionally encrypts it with the user’s inputed password and saves to disk. :param n_words: (int, optional):

Number of mnemonic words to use.

Parameters:
  • use_password (bool, optional) – Is the created key password protected.

  • overwrite (bool, optional) – Will this operation overwrite the coldkey under the same path <wallet path>/<wallet name>/coldkey

  • n_words (int) –

  • suppress (bool) –

Returns:

this object with newly created coldkey.

Return type:

wallet (bittensor.wallet)

new_hotkey(n_words=12, use_password=False, overwrite=False, suppress=False)#

Creates a new hotkey, optionally encrypts it with the user’s inputed password and saves to disk. :param n_words: (int, optional):

Number of mnemonic words to use.

Parameters:
  • use_password (bool, optional) – Is the created key password protected.

  • overwrite (bool, optional) – Will this operation overwrite the hotkey under the same path <wallet path>/<wallet name>/hotkeys/<hotkey>

  • n_words (int) –

  • suppress (bool) –

Returns:

this object with newly created hotkey.

Return type:

wallet (bittensor.wallet)

create_new_hotkey(n_words=12, use_password=False, overwrite=False, suppress=False)#

Creates a new hotkey, optionally encrypts it with the user’s inputed password and saves to disk. :param n_words: (int, optional):

Number of mnemonic words to use.

Parameters:
  • use_password (bool, optional) – Is the created key password protected.

  • overwrite (bool, optional) – Will this operation overwrite the hotkey under the same path <wallet path>/<wallet name>/hotkeys/<hotkey>

  • n_words (int) –

  • suppress (bool) –

Returns:

this object with newly created hotkey.

Return type:

wallet (bittensor.wallet)

regenerate_coldkeypub(ss58_address=None, public_key=None, overwrite=False, suppress=False)#
Regenerates the coldkeypub from passed ss58_address or public_key and saves the file

Requires either ss58_address or public_key to be passed.

Parameters:
  • ss58_address (Optional[str]) – (str, optional): Address as ss58 string.

  • public_key (Optional[Union[str, bytes]]) – (str | bytes, optional): Public key as hex string or bytes.

  • overwrite (bool, optional) – False): Will this operation overwrite the coldkeypub (if exists) under the same path <wallet path>/<wallet name>/coldkeypub

  • suppress (bool) –

Returns:

newly re-generated Wallet with coldkeypub.

Return type:

wallet (bittensor.wallet)

regenerate_coldkey(mnemonic: list | str | None = None, use_password: bool = True, overwrite: bool = False, suppress: bool = False) wallet#
regenerate_coldkey(seed: str | None = None, use_password: bool = True, overwrite: bool = False, suppress: bool = False) wallet
regenerate_coldkey(json: Tuple[str | Dict, str] | None = None, use_password: bool = True, overwrite: bool = False, suppress: bool = False) wallet

Regenerates the coldkey from passed mnemonic, seed, or json encrypts it with the user’s password and saves the file :param mnemonic: (Union[list, str], optional):

Key mnemonic as list of words or string space separated words.

Parameters:
  • seed – (str, optional): Seed as hex string.

  • json – (Tuple[Union[str, Dict], str], optional): Restore from encrypted JSON backup as (json_data: Union[str, Dict], passphrase: str)

  • use_password (bool, optional) – Is the created key password protected.

  • overwrite (bool, optional) – Will this operation overwrite the coldkey under the same path <wallet path>/<wallet name>/coldkey

Returns:

this object with newly created coldkey.

Return type:

wallet (bittensor.wallet)

Note: uses priority order: mnemonic > seed > json

regenerate_hotkey(mnemonic: list | str | None = None, use_password: bool = True, overwrite: bool = False, suppress: bool = False) wallet#
regenerate_hotkey(seed: str | None = None, use_password: bool = True, overwrite: bool = False, suppress: bool = False) wallet
regenerate_hotkey(json: Tuple[str | Dict, str] | None = None, use_password: bool = True, overwrite: bool = False, suppress: bool = False) wallet

Regenerates the hotkey from passed mnemonic, encrypts it with the user’s password and save the file :param mnemonic: (Union[list, str], optional):

Key mnemonic as list of words or string space separated words.

Parameters:
  • seed – (str, optional): Seed as hex string.

  • json – (Tuple[Union[str, Dict], str], optional): Restore from encrypted JSON backup as (json_data: Union[str, Dict], passphrase: str)

  • use_password (bool, optional) – Is the created key password protected.

  • overwrite (bool, optional) – Will this operation overwrite the hotkey under the same path <wallet path>/<wallet name>/hotkeys/<hotkey>

Returns:

this object with newly created hotkey.

Return type:

wallet (bittensor.wallet)