bittensor_wallet.wallet

Contents

bittensor_wallet.wallet#

display_mnemonic_msg(mnemonic, key_type)

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

Wallet([name, hotkey, path, config])

Module Contents#

Functions Details

bittensor_wallet.wallet.display_mnemonic_msg(mnemonic, key_type)

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

Parameters:
  • mnemonic (str) – The mnemonic phrase to display.

  • key_type (str) – The type of key e.g. “coldkey” or “hotkey”.

Classes Details

class bittensor_wallet.wallet.Wallet(name=None, hotkey=None, path=None, config=None)

Bases: object

classmethod add_args(parser, prefix=None)

Accept specific arguments from parser.

coldkey
coldkey_file

Returns the coldkey file.

coldkeypub
coldkeypub_file

Returns the coldkeypub file.

create(coldkey_use_password=True, hotkey_use_password=False, save_coldkey_to_env=False, save_hotkey_to_env=False, coldkey_password=None, hotkey_password=None, overwrite=False, suppress=False)

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

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

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

  • save_coldkey_to_env (bool) – Whether to save a coldkey password to local env. Defaults to False.

  • save_hotkey_to_env (bool) – Whether to save a hotkey password to local env. Defaults to False.

  • coldkey_password (Optional[str]) – Coldkey password for encryption. Defaults to None. If coldkey_password is passed, then coldkey_use_password is automatically True.

  • hotkey_password (Optional[str]) – Hotkey password for encryption. Defaults to None. If hotkey_password is passed, then hotkey_use_password is automatically True.

  • overwrite (bool) – Whether to overwrite an existing keys. Defaults to False.

  • suppress (bool) – If True, suppresses the display of the keys mnemonic message. Defaults to False.

Returns:

Wallet instance with created keys.

Raises:

WalletError – If key generation or file operations fail.

create_coldkey_from_uri(uri, use_password=False, overwrite=False, suppress=True, save_coldkey_to_env=False, coldkey_password=None)

Creates coldkey from uri string, optionally encrypts it with the user-provided password.

Parameters:
  • uri (str) – The URI string to create the coldkey from.

  • use_password (bool) – Whether to use a password for coldkey. Defaults to False.

  • overwrite (bool) – Whether to overwrite existing keys. Defaults to False.

  • suppress (bool) – Whether to suppress mnemonic display. Defaults to True.

  • save_coldkey_to_env (bool) – Whether to save coldkey password to local env. Defaults to False.

  • coldkey_password (Optional[str]) – Coldkey password for encryption. Defaults to None.

Returns:

Wallet - The wallet instance with created coldkey.

Raises:

KeyFileError – If key creation or file operations fail.

create_hotkey_from_uri(uri, use_password=False, overwrite=False, suppress=True, save_hotkey_to_env=False, hotkey_password=None)

Creates hotkey from uri string, optionally encrypts it with the user-provided password.

Parameters:
  • uri (str) – The URI string to create the hotkey from.

  • use_password (bool) – Whether to use a password for hotkey. Defaults to False.

  • overwrite (bool) – Whether to overwrite existing keys. Defaults to False.

  • suppress (bool) – Whether to suppress mnemonic display. Defaults to True.

  • save_hotkey_to_env (bool) – Whether to save hotkey password to local env. Defaults to False.

  • hotkey_password (Optional[str]) – Hotkey password for encryption. Defaults to None.

Returns:

Wallet - The wallet instance with created hotkey.

Raises:

KeyFileError – If key creation or file operations fail.

create_if_non_existent(coldkey_use_password=Ellipsis, hotkey_use_password=Ellipsis, save_coldkey_to_env=Ellipsis, save_hotkey_to_env=Ellipsis, coldkey_password=None, hotkey_password=None, overwrite=Ellipsis, suppress=Ellipsis)

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

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

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

  • save_coldkey_to_env (bool) – Whether to save a coldkey password to local env. Defaults to False.

  • save_hotkey_to_env (bool) – Whether to save a hotkey password to local env. Defaults to False.

  • coldkey_password (Optional[str]) – Coldkey password for encryption. Defaults to None. If coldkey_password is passed, then coldkey_use_password is automatically True.

  • hotkey_password (Optional[str]) – Hotkey password for encryption. Defaults to None. If hotkey_password is passed, then hotkey_use_password is automatically True.

  • overwrite (bool) – Whether to overwrite an existing keys. Defaults to False.

  • suppress (bool) – If True, suppresses the display of the keys mnemonic message. Defaults to False.

Returns:

Wallet - The wallet instance with created keys.

Raises:

WalletError – If key generation or file operations fail.

create_new_coldkey(n_words=Ellipsis, use_password=None, overwrite=None, suppress=None, save_coldkey_to_env=None, coldkey_password=None)
create_new_hotkey(n_words=Ellipsis, use_password=None, overwrite=None, suppress=None, save_hotkey_to_env=None, hotkey_password=None)

Creates a new hotkey, optionally encrypts it with the user-provided password and saves to disk.

Parameters:
  • n_words (int) – The number of words in the mnemonic. Defaults to 12.

  • use_password (bool) – Whether to use a password for hotkey. Defaults to False.

  • overwrite (bool) – Whether to overwrite existing keys. Defaults to False.

  • suppress (bool) – Whether to suppress mnemonic display. Defaults to False.

  • save_hotkey_to_env (bool) – Whether to save hotkey password to local env. Defaults to False.

  • hotkey_password (Optional[str]) – Hotkey password for encryption. Defaults to None. If hotkey_password is passed, then use_password is automatically True.

Returns:

Wallet - The wallet instance with created hotkey.

Raises:

WalletError – If key generation or file operations fail.

debug_string()
get_coldkey(password=None)

Gets the coldkey from the wallet.

Parameters:

password (Optional[str]) – Password for decryption. Defaults to None. If not provided, asks for user input.

Returns:

Keypair - The coldkey keypair.

Raises:

KeyFileError – If the coldkey file doesn’t exist or decryption fails.

get_coldkeypub(password=None)

Gets the coldkeypub from the wallet.

Parameters:

password (Optional[str]) – Password for decryption. Defaults to None. If not provided, asks for user input.

Returns:

Keypair - The coldkeypub keypair.

Raises:

KeyFileError – If the coldkeypub file doesn’t exist or decryption fails.

get_hotkey(password=None)

Gets the hotkey from the wallet.

Parameters:

password (Optional[str]) – Password for decryption. Defaults to None. If not provided, asks for user input.

Returns:

Keypair - The hotkey keypair.

Raises:

KeyFileError – If the hotkey file doesn’t exist or decryption fails.

get_hotkeypub(password=None)

Gets the hotkeypub from the wallet.

Parameters:

password (Optional[str]) – Password for decryption. Defaults to None. If not provided, asks for user input.

Returns:

Keypair - The hotkeypub keypair.

Raises:

KeyFileError – If the hotkeypub file doesn’t exist or decryption fails.

hotkey

Returns the hotkey name.

hotkey_file

Returns the hotkey file.

hotkey_str
hotkeypub
hotkeypub_file

Returns the hotkeypub file.

name

Returns the wallet name.

path

Returns the wallet path.

recreate(coldkey_use_password=Ellipsis, hotkey_use_password=Ellipsis, save_coldkey_to_env=Ellipsis, save_hotkey_to_env=Ellipsis, coldkey_password=None, hotkey_password=None, overwrite=Ellipsis, suppress=Ellipsis)

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

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

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

  • save_coldkey_to_env (bool) – Whether to save a coldkey password to local env. Defaults to False.

  • save_hotkey_to_env (bool) – Whether to save a hotkey password to local env. Defaults to False.

  • coldkey_password (Optional[str]) – Coldkey password for encryption. Defaults to None. If coldkey_password is passed, then coldkey_use_password is automatically True.

  • hotkey_password (Optional[str]) – Hotkey password for encryption. Defaults to None. If hotkey_password is passed, then hotkey_use_password is automatically True.

  • overwrite (bool) – Whether to overwrite an existing keys. Defaults to False.

  • suppress (bool) – If True, suppresses the display of the keys mnemonic message. Defaults to False.

Returns:

Wallet instance with created keys.

Raises:

WalletError – If key generation or file operations fail.

regenerate_coldkey(mnemonic=None, seed=None, json=None, use_password=True, overwrite=False, suppress=False, save_coldkey_to_env=False, coldkey_password=None)

Regenerates the coldkey from the passed mnemonic or seed, or JSON encrypts it with the user’s password and saves the file.

Parameters:
  • mnemonic (Optional[str]) – Mnemonic phrase to regenerate the coldkey from. Defaults to None.

  • seed (Optional[str]) – Seed hex to regenerate the coldkey from. Defaults to None.

  • json (Optional[tuple]) – Tuple of (JSON data, passphrase) to regenerate the coldkey from. Defaults to None.

  • use_password (bool) – Whether to use a password for coldkey. Defaults to True.

  • overwrite (bool) – Whether to overwrite existing keys. Defaults to False.

  • suppress (bool) – Whether to suppress mnemonic display. Defaults to False.

  • save_coldkey_to_env (bool) – Whether to save coldkey password to local env. Defaults to False.

  • coldkey_password (Optional[str]) – Coldkey password for encryption. Defaults to None.

Returns:

Wallet - The wallet instance with regenerated coldkey.

Raises:

WalletError – If key generation or file operations fail.

regenerate_coldkeypub(ss58_address=None, public_key=None, overwrite=None)

Regenerates the coldkeypub from the 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]) – SS58 address to regenerate the coldkeypub from. Defaults to None.

  • public_key (Optional[str]) – Public key hex to regenerate the coldkeypub from. Defaults to None.

  • overwrite (bool) – Whether to overwrite existing keys. Defaults to False.

Returns:

Wallet - The wallet instance with regenerated coldkeypub.

Raises:

WalletError – If key generation or file operations fail.

regenerate_hotkey(mnemonic=None, seed=None, json=None, use_password=False, overwrite=False, suppress=False, save_hotkey_to_env=False, hotkey_password=None)

Regenerates the hotkey from passed mnemonic or seed, encrypts it with the user’s password and saves the file.

Parameters:
  • mnemonic (Optional[str]) – Mnemonic phrase to regenerate the hotkey from. Defaults to None.

  • seed (Optional[str]) – Seed hex to regenerate the hotkey from. Defaults to None.

  • json (Optional[tuple]) – Tuple of (JSON data, passphrase) to regenerate the hotkey from. Defaults to None.

  • use_password (bool) – Whether to use a password for hotkey. Defaults to False.

  • overwrite (bool) – Whether to overwrite existing keys. Defaults to False.

  • suppress (bool) – Whether to suppress mnemonic display. Defaults to False.

  • save_hotkey_to_env (bool) – Whether to save hotkey password to local env. Defaults to False.

  • hotkey_password (Optional[str]) – Hotkey password for encryption. Defaults to None.

Returns:

Wallet - The wallet instance with regenerated hotkey.

Raises:

KeyFileError – If key generation or file operations fail.

regenerate_hotkeypub(ss58_address=None, public_key=None, overwrite=None)

Regenerates the hotkeypub from the 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]) – SS58 address to regenerate the hotkeypub from. Defaults to None.

  • public_key (Optional[str]) – Public key hex to regenerate the hotkeypub from. Defaults to None.

  • overwrite (bool) – Whether to overwrite existing keys. Defaults to False.

Returns:

Wallet - The wallet instance with regenerated hotkeypub.

Raises:

WalletError – If key generation or file operations fail.

set_coldkey(keypair, encrypt=True, overwrite=False, save_coldkey_to_env=False, coldkey_password=None)

Sets the coldkey for the wallet.

Parameters:
  • keypair (Keypair) – The keypair to set as coldkey.

  • encrypt (bool) – Whether to encrypt the key. Defaults to True.

  • overwrite (bool) – Whether to overwrite if key exists. Defaults to False.

  • save_coldkey_to_env (bool) – Whether to save coldkey password to local env. Defaults to False.

  • coldkey_password (Optional[str]) – Coldkey password for encryption. Defaults to None.

Raises:

KeyFileError – If file operations fail.

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

Sets the coldkeypub for the wallet.

Parameters:
  • keypair (Keypair) – The keypair to set as coldkeypub.

  • encrypt (bool) – Whether to encrypt the key. Defaults to False.

  • overwrite (bool) – Whether to overwrite if key exists. Defaults to False.

Raises:

KeyFileError – If file operations fail.

set_hotkey(keypair, encrypt=False, overwrite=False, save_hotkey_to_env=False, hotkey_password=None)

Sets the hotkey for the wallet.

Parameters:
  • keypair (Keypair) – The keypair to set as hotkey.

  • encrypt (bool) – Whether to encrypt the key. Defaults to False.

  • overwrite (bool) – Whether to overwrite if key exists. Defaults to False.

  • save_hotkey_to_env (bool) – Whether to save hotkey password to local env. Defaults to False.

  • hotkey_password (Optional[str]) – Hotkey password for encryption. Defaults to None.

Raises:

KeyFileError – If file operations fail.

set_hotkeypub(keypair, encrypt=False, overwrite=False)

Sets the hotkeypub for the wallet.

Parameters:
  • keypair (Keypair) – The keypair to set as hotkeypub.

  • encrypt (bool) – Whether to encrypt the key. Defaults to False.

  • overwrite (bool) – Whether to overwrite if key exists. Defaults to False.

Raises:

KeyFileError – If file operations fail.

to_string()
unlock_coldkey()

Unlocks the coldkey.

unlock_coldkeypub()

Unlocks the coldkeypub.

unlock_hotkey()

Unlocks the hotkey.

unlock_hotkeypub()

Unlocks the hotkeypub.