Bittensor Wallet

4.0.1 · active · verified Thu Apr 16

Bittensor-wallet is a Python SDK that provides an interface for managing cryptographic key-pairs (coldkeys and hotkeys) necessary to interact with the Bittensor decentralized machine learning network. It allows users to prove identity, sign transactions, access TAO tokens, and manage stake in subnets. The library is currently at version 4.0.1 and has a frequent release cadence, with recent updates supporting Python 3.14.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `Wallet` object and create (or load) a coldkey and hotkey pair. The mnemonic (seed phrase) is crucial for recovery and is printed to the console upon creation, requiring secure offline storage. For production use, consider using passwords and robust key management strategies.

import os
from bittensor_wallet import Wallet

# Create a new wallet with a specific name and hotkey
# This will create directories and key files at ~/.bittensor/wallets/<wallet_name>/hotkeys/<hotkey_name>
# Replace with your desired wallet and hotkey names
wallet_name = os.environ.get('BT_WALLET_NAME', 'my_coldkey_wallet')
hotkey_name = os.environ.get('BT_HOTKEY_NAME', 'my_hotkey')

my_wallet = Wallet(name=wallet_name, hotkey=hotkey_name)

try:
    # Attempt to create the wallet. If it already exists, it will load it.
    my_wallet.create(coldkey_use_password=False, hotkey_use_password=False, overwrite=False)
    print(f"Wallet '{wallet_name}' with hotkey '{hotkey_name}' created or loaded successfully.")
    print(f"Coldkey address: {my_wallet.coldkeypub.ss58_address}")
    print(f"Hotkey address: {my_wallet.hotkey.ss58_address}")
    # The mnemonic for a newly created wallet is printed to console upon creation
    # and should be stored securely offline.

except Exception as e:
    print(f"Error creating or loading wallet: {e}")

# Example of retrieving keypairs
coldkey_keypair = my_wallet.coldkey
hotkey_keypair = my_wallet.hotkey

print(f"\nAccessed coldkey public address: {coldkey_keypair.ss58_address}")
print(f"Accessed hotkey public address: {hotkey_keypair.ss58_address}")

view raw JSON →