bittensor.wallet
#
Implementation of the wallet class, which manages balances with staking and transfer. Also manages hotkey and coldkey.
Module Contents#
Classes#
The wallet class in the Bittensor framework handles wallet functionality, crucial for participating in the Bittensor network. |
Functions#
|
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 (str) – The name of the wallet, used to identify it among possibly multiple wallets.
path (str) – File system path where wallet keys are stored.
hotkey_str (str) – String identifier for the hotkey.
_hotkey (bittensor.Keypair) – Internal representations of the hotkey and coldkey.
_coldkey (bittensor.Keypair) – Internal representations of the hotkey and coldkey.
_coldkeypub (bittensor.Keypair) – Internal representations of the hotkey and coldkey.
hotkey (str) –
config (bittensor.config) –
- 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 coldkey: bittensor.Keypair#
Loads the hotkey from wallet.path/wallet.name/coldkey or raises an error.
- Returns:
coldkey loaded from config arguments.
- Return type:
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.
- property coldkey_file: bittensor.keyfile#
Property that returns the coldkey file.
- Returns:
The coldkey file.
- Return type:
bittensor.keyfile
- property coldkeypub: bittensor.Keypair#
Loads the coldkeypub from wallet.path/wallet.name/coldkeypub.txt or raises an error.
- Returns:
coldkeypub loaded from config arguments.
- Return type:
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.
- 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.
- Return type:
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.
- property hotkey_file: bittensor.keyfile#
Property that returns the hotkey file.
- Returns:
The hotkey file.
- Return type:
bittensor.keyfile
- regen_coldkey#
- regen_coldkeypub#
- regen_hotkey#
- __repr__()#
Returns the string representation of the wallet object.
- Returns:
The string representation.
- Return type:
- __str__()#
Returns the string representation of the Wallet object.
- Returns:
The string representation.
- Return type:
- classmethod add_args(parser, prefix=None)#
Accept specific arguments from parser.
- Parameters:
parser (argparse.ArgumentParser) – Argument parser object.
prefix (str) – Argument prefix.
- classmethod config()#
Get config from the argument parser.
- Returns:
Config object.
- Return type:
- create(coldkey_use_password=True, hotkey_use_password=False)#
Checks for existing coldkeypub and hotkeys, and creates them if non-existent.
- create_coldkey_from_uri(uri, use_password=True, overwrite=False, suppress=False)#
Creates coldkey from suri string, optionally encrypts it with the user-provided password.
- Parameters:
- 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-provided password.
- Parameters:
uri (str) – (str, required): URI string to use i.e.,
/Alice
or/Bob
use_password (bool, optional) – Is the created key password protected.
overwrite (bool, optional) – Determines if this operation overwrites the hotkey under the same path
<wallet path>/<wallet name>/hotkeys/<hotkey>
.suppress (bool) –
- Returns:
This object with newly created hotkey.
- Return type:
wallet (bittensor.wallet)
- create_if_non_existent(coldkey_use_password=True, hotkey_use_password=False)#
Checks for existing coldkeypub and hotkeys, and creates them if non-existent.
- create_new_coldkey(n_words=12, use_password=True, overwrite=False, suppress=False)#
Creates a new coldkey, optionally encrypts it with the user-provided password and saves to disk.
- Parameters:
- Returns:
This object with newly created coldkey.
- 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-provided password and saves to disk.
- Parameters:
- Returns:
This object with newly created hotkey.
- Return type:
wallet (bittensor.wallet)
- 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_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
- 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
- classmethod help()#
Print help to stdout.
- new_coldkey(n_words=12, use_password=True, overwrite=False, suppress=False)#
Creates a new coldkey, optionally encrypts it with the user-provided password and saves to disk.
- Parameters:
- 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-provided password and saves to disk.
- Parameters:
n_words (int) – (int, optional): Number of mnemonic words to use.
use_password (bool, optional) – Is the created key password protected.
overwrite (bool, optional) – Determines if this operation overwrites the hotkey under the same path
<wallet path>/<wallet name>/hotkeys/<hotkey>
.suppress (bool) –
- Returns:
This object with newly created hotkey.
- Return type:
wallet (bittensor.wallet)
- recreate(coldkey_use_password=True, hotkey_use_password=False)#
Checks for existing coldkeypub and hotkeys and creates them if non-existent.
- 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 the passed mnemonic or seed, or JSON encrypts it with the user’s password and saves the file.
- Parameters:
mnemonic – (Union[list, str], optional): Key mnemonic as list of words or string space separated words.
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) – Determines if this operation overwrites 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_coldkeypub(ss58_address=None, public_key=None, overwrite=False, suppress=False)#
Regenerates the coldkeypub from the passed
ss58_address
or public_key and saves the file. Requires eitherss58_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): Determins if this operation overwrites 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_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 or seed, encrypts it with the user’s password and saves the file.
- Parameters:
mnemonic – (Union[list, str], optional): Key mnemonic as list of words or string space separated words.
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) – Determies if this operation overwrites the hotkey under the same path
<wallet path>/<wallet name>/hotkeys/<hotkey>
.
- Returns:
This object with newly created hotkey.
- Return type:
wallet (bittensor.wallet)
- set_coldkey(keypair, encrypt=True, overwrite=False)#
Sets the coldkey for the wallet.
- set_coldkeypub(keypair, encrypt=False, overwrite=False)#
Sets the coldkeypub for the wallet.
- Parameters:
- Returns:
The coldkeypub file.
- Return type:
bittensor.keyfile
- set_hotkey(keypair, encrypt=False, overwrite=False)#
Sets the hotkey for the wallet.