Bittensor CLI
bittensor-cli is the official command-line interface for interacting with the Bittensor network. It allows users to manage wallets, stake TAO, register hotkeys, manage subnets, and perform other on-chain operations. As of version 9.20.1, it provides robust tools for participants in the decentralized AI network, with frequent updates addressing bug fixes and new features.
Common errors
-
Command 'wallet history' is not available
cause The `wallet history` command was disabled in version 9.19.0 due to the deprecation of an external API it relied upon.fixThe command is permanently disabled. There is no CLI replacement; consult blockchain explorers for transaction history. -
JSON output is empty for `btcli subnets list --json-out`
cause A bug in earlier versions caused the `--json-out` flag to return empty output for certain commands, including `subnets list`.fixUpgrade your `bittensor-cli` to version `9.19.0` or newer: `pip install --upgrade bittensor-cli`. -
Error: unrecognized arguments: --coldkey-ss58
cause In `v9.17.0`, the `--coldkey-ss58` argument was deprecated in favor of interacting with coldkeys by their name or through integrated wallet commands.fixRemove the `--coldkey-ss58` argument and instead use `btcli wallet --wallet.name <coldkey_name>` or ensure your command structure aligns with the post-v9.17.0 documentation for wallet interactions. -
Failed to add stake: Operation mapping error for multi-hotkey/netuid.
cause Versions prior to `9.20.2rc1` contained a bug where `stake add` operations could fail or incorrectly map when dealing with multiple hotkeys or netuids.fixUpgrade to `bittensor-cli>=9.20.2rc1` (or the latest stable release after it) to resolve stake mapping issues: `pip install --upgrade bittensor-cli`.
Warnings
- deprecated Old identities were deprecated in `v9.20.1`. Users should ensure they are using the latest identity management practices.
- breaking The `wallet history` command has been disabled due to the deprecation of its external API dependency. This functionality is no longer available via the CLI.
- gotcha The `--coldkey-ss58` parameter was consolidated into a predefined option in `v9.17.0`, leading to 'unknown argument' errors if using the old explicit SS58 address parameter.
- gotcha `stake add` operations for multi-hotkey and multi-netuid scenarios had mapping issues.
Install
-
pip install bittensor-cli
Quickstart
import subprocess
import json
import sys
# Note: bittensor-cli is primarily a command-line tool.
# This quickstart demonstrates how to run a command programmatically.
try:
# Get the installed btcli version
version_process = subprocess.run(
[sys.executable, '-m', 'btcli', 'version'],
capture_output=True, text=True, check=True
)
print(f"Bittensor CLI Version:\n{version_process.stdout}")
# List available subnets in JSON format
# This command requires a connection to the Bittensor network.
# Replace 'finney' with your preferred network, e.g., 'local' for a local setup.
print("\nListing subnets on 'finney' network...")
subnets_process = subprocess.run(
[sys.executable, '-m', 'btcli', 'subnets', 'list', '--netuid', '0', '--json-out', '--no-prompt', '--subtensor.chain_endpoint', 'ws://127.0.0.1:9944'], # Example using local, replace as needed
capture_output=True, text=True, check=False # check=False to catch potential errors gracefully
)
if subnets_process.returncode == 0:
try:
subnets_data = json.loads(subnets_process.stdout)
print("Successfully retrieved subnet information:")
print(json.dumps(subnets_data, indent=2))
except json.JSONDecodeError:
print("Error: Could not decode JSON output.")
print(f"Raw output:\n{subnets_process.stdout}")
else:
print(f"Error running btcli subnets list:\n{subnets_process.stderr}")
except FileNotFoundError:
print("Error: 'btcli' command not found. Ensure bittensor-cli is installed and in your PATH.")
except subprocess.CalledProcessError as e:
print(f"An unexpected error occurred: {e}")
print(f"Stdout: {e.stdout}")
print(f"Stderr: {e.stderr}")