### View Commands Examples Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md Examples of commands to view network information. ```bash btcli view metagraph # Display subnet metagraph ``` ```bash btcli view hotkeys # List hotkeys ``` ```bash btcli view delegates # Display delegate list ``` -------------------------------- ### Wallet Commands Examples Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md Examples of common wallet operations using the btcli. ```bash btcli wallet create # Create new wallet ``` ```bash btcli wallet list # List all wallets ``` ```bash btcli wallet unlock # Unlock a wallet ``` ```bash btcli wallet balance # Check balance ``` -------------------------------- ### InfoBase Usage Example Source: https://github.com/latent-to/btcli/blob/main/_autodocs/02-chain-data.md Demonstrates how to use the `list_from_any` class method to construct a list of objects from chain data and access their fields using dictionary-like syntax or the `get` method. ```python # Assuming NeuronInfo is a subclass of InfoBase and chain_data is available # neurons = NeuronInfo.list_from_any(chain_data) # for neuron in neurons: # print(neuron["uid"]) # print(neuron.get("nonexistent", "N/A")) ``` -------------------------------- ### Create and Activate Virtual Environment for Source Install Source: https://github.com/latent-to/btcli/blob/main/README.md Set up a Python virtual environment before installing from source. ```bash python3 -m venv btcli_venv source btcli_venv/bin/activate ``` -------------------------------- ### Stake Commands Examples Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md Examples of common stake operations using the btcli. ```bash btcli stake add # Add stake to a hotkey ``` ```bash btcli stake remove # Remove stake ``` ```bash btcli stake list # List all stakes ``` ```bash btcli stake move # Move stake between hotkeys ``` -------------------------------- ### Configuration File Example Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Example of a typical configuration file for btcli. This file specifies network settings, caching options, and wallet details. ```yaml network: finney use_cache: true disk_cache: true wallet_name: default wallet_hotkey: default wallet_path: ~/.bittensor/wallets rate_tolerance: null safe_staking: true ``` -------------------------------- ### Save Configuration Example Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md Examples of how to save configuration changes using the 'btcli config set' command. CLI arguments take precedence over config file settings. ```bash btcli config set network finney ``` ```bash btcli config set wallet_name my_wallet ``` -------------------------------- ### Install Bittensor CLI from Source Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Clone the repository and install the bittensor-cli package locally. ```bash # From source git clone https://github.com/opentensor/btcli.git cd btcli pip install . ``` -------------------------------- ### Subnet Commands Examples Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md Examples of common subnet management operations using the btcli. ```bash btcli subnets create # Create a new subnet ``` ```bash btcli subnets list # List all subnets ``` ```bash btcli subnets register # Register neuron to subnet ``` ```bash btcli subnets info # Get subnet information ``` -------------------------------- ### Install Bittensor CLI using uv Source: https://github.com/latent-to/btcli/blob/main/README.md Install the bittensor-cli package using the uv package installer. ```bash uv pip install bittensor-cli ``` -------------------------------- ### Get General Help using btcli Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Display general help information for the btcli. ```bash btcli --help ``` -------------------------------- ### Governance Commands Examples Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md Examples of governance operations, including root and sudo commands. ```bash btcli sudo set-param # Set hyperparameter (root only) ``` ```bash btcli root weights # Set weights on root network ``` ```bash btcli root stake # Stake on root network ``` -------------------------------- ### Install Bittensor SDK with CLI Source: https://github.com/latent-to/btcli/blob/main/README.md Install the bittensor SDK and the CLI together in a single command. ```bash pip install -U bittensor[cli] ``` -------------------------------- ### Get Wallet Create Command Help using btcli Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Display help information for the 'wallet create' command. ```bash btcli wallet create --help ``` -------------------------------- ### Hyperparameter Configuration Examples Source: https://github.com/latent-to/btcli/blob/main/_autodocs/07-hyperparameters.md Illustrative Python code snippets showing how to configure hyperparameters for different subnet types. These examples demonstrate setting values for tempo, validator counts, burn rates, and more. ```python # Gradually increase cost to maintain constant registration rate min_burn = 100_000_000 # 0.1 TAO minimum burn_increase_mult = 1.1 # 10% increase per registration burn_half_life = 10_000 # Decay over 10k blocks ``` ```python # Encourage validators to set weights max_validators = 32 # Increase to 64 kappa = 0.8 # Increase validator influence consensus_scaling = 2.0 # Increase scale of consensus ``` ```python # Reduce registration churn by raising barriers immunity_period = 10_000 # 2x protection min_burn = 500_000_000 # 0.5 TAO (5x increase) registration_allowed = false # Pause registrations temporarily ``` ```python tempo = 50 # Very frequent updates max_validators = 64 # Many validators min_burn = 100_000_000 # Low entry barrier immunity_period = 2_000 # Short protection ``` ```python tempo = 360 # Slow updates max_validators = 8 # Few validators min_burn = 1_000_000_000 # High barrier immunity_period = 10_000 # Long protection ``` ```python serving_rate_limit = 1000 # High serving rate max_regs_per_block = 32 # Fast registration weights_rate_limit = 128 # Frequent weight updates ``` -------------------------------- ### Balance Object Methods Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Provides examples of using Balance object methods to get the current unit, set a unit, and convert the balance to a dictionary. ```python # Methods balance.get_unit() -> str balance.set_unit(netuid: int) -> Balance balance.to_dict() -> dict[str, int | float] ``` -------------------------------- ### Install Bittensor CLI from Source Source: https://github.com/latent-to/btcli/blob/main/README.md Install the Bittensor CLI using pip after cloning the repository. ```bash pip3 install . ``` -------------------------------- ### Get Wallet Command Help using btcli Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Display help information specific to the 'wallet' subcommand. ```bash btcli wallet --help ``` -------------------------------- ### Install Bittensor CLI from Homebrew Source: https://github.com/latent-to/btcli/blob/main/README.md Install the btcli package using the Homebrew package manager. ```shell brew install btcli ``` -------------------------------- ### Initialize CLI and Run a Wallet Command Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Shows the basic setup for using the Bittensor CLI by initializing the CLIManager and executing a wallet creation command. This is the entry point for most CLI operations. ```python from bittensor_cli.cli import CLIManager cli = CLIManager() cli.run(["wallet", "create", "--name", "my_wallet"]) ``` -------------------------------- ### Verify Bittensor CLI Installation Source: https://github.com/latent-to/btcli/blob/main/README.md Check the installed version of the Bittensor CLI to confirm successful installation. ```bash btcli --version ``` -------------------------------- ### Install Bittensor CLI from PyPI Source: https://github.com/latent-to/btcli/blob/main/README.md Use pip to install or upgrade the bittensor-cli package. ```bash pip install -U bittensor-cli ``` -------------------------------- ### Install Bittensor CLI with Development Dependencies Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Install the bittensor-cli package with development dependencies for local development. ```bash # With development dependencies pip install -e ".[dev]" ``` -------------------------------- ### Query Delegate Information Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Examples for retrieving delegate information, including a lite list and detailed info for a specific delegate. ```python # Delegate queries await si.get_delegates_lite(block_hash: str | None) -> list[DelegateInfoLite] await si.get_delegate_info(hotkey_ss58: str, block_hash: str | None) -> DelegateInfo | None ``` -------------------------------- ### Create NeuronInfo and StakeInfo Objects Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Example of creating lists of NeuronInfo objects from chain data. ```python from bittensor_cli.src.bittensor.chain_data import NeuronInfo, StakeInfo neurons = NeuronInfo.list_from_any(chain_data) ``` -------------------------------- ### Markdown Code Block Example Source: https://github.com/latent-to/btcli/blob/main/CONTRIBUTING.md When providing code examples in GitHub issues, use Markdown code blocks for clarity and proper formatting. This ensures that code is easily readable and copy-pasteable. ```markdown ``` [Your code snippet here] ``` ``` -------------------------------- ### CLIManager Command Execution Source: https://github.com/latent-to/btcli/blob/main/_autodocs/GENERATION_SUMMARY.txt Shows the basic structure for initializing and running commands with the CLIManager. This is a conceptual example. ```python from bittensor.cli import CLIManager # Conceptual example of CLIManager usage # cli = CLIManager() # cli.run_main() # print("CLI Manager executed.") ``` -------------------------------- ### SubtensorInterface Transaction Method Source: https://github.com/latent-to/btcli/blob/main/_autodocs/GENERATION_SUMMARY.txt Demonstrates how to sign and send an extrinsic transaction using the SubtensorInterface. Requires proper setup and keys. ```python import asyncio from bittensor.subtensor import SubtensorInterface async def send_transaction(): async with SubtensorInterface() as subtensor: # Example: Sending a dummy extrinsic (replace with actual call) # extrinsic = subtensor.compose_call( # call_module='Subtensor', # call_function='some_function', # call_params={{...}} # ) # signed_extrinsic = await subtensor.sign_and_send_extrinsic(extrinsic=extrinsic) # print(f"Signed Extrinsic: {signed_extrinsic}") pass # Placeholder for actual transaction logic # asyncio.run(send_transaction()) # Uncomment to run ``` -------------------------------- ### Query Neurons and Display Stake Information Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md An asynchronous example demonstrating how to fetch and display the top 5 neurons with their total stake in TAO. Requires running within an asyncio event loop. ```python from bittensor_cli.src.bittensor.subtensor_interface import SubtensorInterface import asyncio async def list_neurons(): async with SubtensorInterface("finney") as si: neurons = await si.get_neurons_lite(netuid=1) for neuron in neurons[:5]: print(f"UID {neuron.uid}: {neuron.total_stake.tao} TAO") asyncio.run(list_neurons()) ``` -------------------------------- ### Example btcli Config File Source: https://github.com/latent-to/btcli/blob/main/README.md This YAML configuration file sets various parameters for btcli, including network settings, caching behavior, and metagraph display columns. It is typically located at ~/.bittensor/config.yml. ```yaml network: local use_cache: true dashboard_path: null disk_cache: true rate_tolerance: null safe_staking: true wallet_hotkey: default wallet_name: coldkey-user1 wallet_path: ~/.bittensor/wallets metagraph_cols: ACTIVE: true AXON: true COLDKEY: true CONSENSUS: true DIVIDENDS: true EMISSION: true HOTKEY: true INCENTIVE: true RANK: true STAKE: true TRUST: true UID: true UPDATED: true VAL: true VTRUST: true ``` -------------------------------- ### Get Lightweight Delegate Information Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Fetches essential information for all delegates on the network, such as their hotkey and commission rate. Ideal for a quick overview of available delegates. ```python delegates = await si.get_delegates_lite() for d in delegates: print(f"{d.hotkey}: {d.take:.1%} commission") ``` -------------------------------- ### Query Subnet Hyperparameters via SubtensorInterface Source: https://github.com/latent-to/btcli/blob/main/_autodocs/07-hyperparameters.md Programmatically fetch subnet hyperparameters using the `SubtensorInterface`. This example demonstrates accessing 'tempo' and 'min_burn' for a specific subnet. ```python from bittensor_cli.src.bittensor.subtensor_interface import SubtensorInterface async with SubtensorInterface("finney") as si: params = await si.get_subnet_hyperparams(netuid=1) print(f"Tempo: {params['tempo']}") print(f"Min burn: {params['min_burn']}") print(f"Kappa: {params['kappa']}") ``` -------------------------------- ### Get Bittensor Version Information Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Prints the current Bittensor CLI version and its integer representation. Useful for verifying installation and compatibility. ```python from bittensor_cli import __version__, __version_as_int__ print(__version__) # "9.22.2" print(__version_as_int__) # Version as integer format ``` -------------------------------- ### Get Stake for Coldkey Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Fetches all stake associated with a given coldkey across all subnets and delegates. This provides a consolidated view of a user's stake. ```python stakes = await si.get_stake_for_coldkey("5ABC...XYZ") total = sum(s.stake for s in stakes) print(f"Total stake: {total.tao} TAO") ``` -------------------------------- ### Initialize and Use CLIManager Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Illustrates how to instantiate the CLIManager and execute a CLI command to list wallets. ```python from bittensor_cli.cli import CLIManager cli = CLIManager() cli.run(["wallet", "list"]) ``` -------------------------------- ### Display Help for Config Command Source: https://github.com/latent-to/btcli/blob/main/README.md Use this command to view the help documentation for the btcli config command, which outlines available configuration options. ```bash btcli config --help ``` -------------------------------- ### Create and Convert Balances Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Demonstrates creating Balance objects from raw units (rao) and fractional units (tao), and accessing their properties. Use this to manage and display token amounts. ```python from bittensor_cli.src.bittensor.balances import Balance # Create and convert balances b1 = Balance(1000000000) # From rao b2 = Balance(1.5) # From tao b3 = Balance.from_tao(2.75) print(b1.tao) # 1.0 print(b1.rao) # 1000000000 print(str(b1)) # "τ 1.0000" ``` -------------------------------- ### Initialize SubtensorInterface Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Shows how to initialize the SubtensorInterface for blockchain interaction, including context management with 'async with'. ```python # Initialization and context SubtensorInterface(network: str, use_disk_cache: bool = True) async with SubtensorInterface(...) as si: # ... use si ``` -------------------------------- ### Get Metagraph Information Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Fetches the complete metagraph for a given subnet, including all neuron data. Use this to get a full overview of a subnet's network. ```python metagraph = await si.get_metagraph(netuid=1) print(f"Total neurons: {len(metagraph.neurons)}") print(f"Total stake: {metagraph.total_stake}") ``` -------------------------------- ### Initialize and Use SubtensorInterface Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Shows how to establish an asynchronous connection to the Bittensor chain and retrieve lite neuron data. ```python from bittensor_cli.src.bittensor.subtensor_interface import SubtensorInterface async with SubtensorInterface("finney") as si: neurons = await si.get_neurons_lite(netuid=1) ``` -------------------------------- ### Use Console Instances for Output Source: https://github.com/latent-to/btcli/blob/main/_autodocs/06-utilities.md Demonstrates how to use the imported console instances for standard and error output, applying color and formatting. ```python from bittensor_cli.src.bittensor.utils import console, err_console # Normal output console.print("[green]Success:[/green] Operation completed") # Error output err_console.print("[red]Error:[/red] Invalid argument") ``` -------------------------------- ### Query Stake Information Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Demonstrates how to retrieve stake details for a coldkey, including stake for a specific hotkey and network. ```python # Stake queries await si.get_stake_for_coldkey(coldkey_ss58: str, block_hash: str | None) -> list[StakeInfo] await si.get_stake_for_coldkey_and_hotkey(hotkey: str, coldkey: str, netuid: int, block_hash: str | None) -> Balance ``` -------------------------------- ### Clone Bittensor CLI Repository Source: https://github.com/latent-to/btcli/blob/main/README.md Clone the official Bittensor CLI repository from GitHub to install from source. ```bash git clone https://github.com/opentensor/btcli.git ``` -------------------------------- ### Accessing Default Configuration Values Source: https://github.com/latent-to/btcli/blob/main/_autodocs/03-constants-config.md Shows how to import and access default configuration values for network, wallet, and other settings using the 'defaults' module. ```python from bittensor_cli.src import defaults print(defaults.netuid) # 1 print(defaults.subtensor.network) # "finney" print(defaults.wallet.name) # "default" print(defaults.wallet.path) # "~/.bittensor/wallets/" ``` -------------------------------- ### Balance Class Constructor and Methods Source: https://github.com/latent-to/btcli/blob/main/_autodocs/GENERATION_SUMMARY.txt Demonstrates the initialization and usage of the Balance class for handling Tao and Rao values. Includes conversion methods. ```python from bittensor.balance import Balance # Example usage of Balance class balance_tao = Balance.from_tao(1000) balance_rao = Balance.from_rao(500000000000000000) print(f"Balance in Tao: {balance_tao.tao}") print(f"Balance in Rao: {balance_rao.rao}") print(f"Tao from Rao: {balance_rao.tao}") print(f"Rao from Tao: {balance_tao.rao}") ``` -------------------------------- ### List Wallets using btcli Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Command to list all available wallets managed by btcli. ```bash btcli wallet list ``` -------------------------------- ### Get Account Balance Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Fetches the free balance of an account. Provide the SS58 address to retrieve the balance in rao. ```python async def get_balance( self, address: str, block_hash: Optional[str] = None, ) -> Balance: pass ``` ```python balance = await si.get_balance("5ABC...") print(f"Balance: {balance.tao} TAO") ``` -------------------------------- ### Get Bittensor CLI Version Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Prints the current version of the Bittensor CLI. Supports both string and integer representations. ```python # Version information print(__version__) # "9.22.2" print(__version_as_int__) # Version as integer ``` -------------------------------- ### Initialize SubtensorInterface Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Connect to a Bittensor network using the SubtensorInterface. Disk caching is enabled by default. Use within an async context manager. ```python from bittensor_cli.src.bittensor.subtensor_interface import SubtensorInterface async with SubtensorInterface("finney") as si: # Connection established metagraph = await si.get_metagraph(netuid=1) ``` -------------------------------- ### Display Help Information Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md Display help for the CLI or a specific command. ```bash btcli --help ``` ```bash btcli --help ``` -------------------------------- ### Help Panel Organization Source: https://github.com/latent-to/btcli/blob/main/_autodocs/03-constants-config.md A dictionary structure for organizing CLI help commands into logical sections such as WALLET, ROOT, STAKE, SUDO, and more. ```python HELP_PANELS = { "WALLET": { ... }, "ROOT": { ... }, "STAKE": { ... }, "SUDO": { ... }, "MECHANISMS": { ... }, "SUBNETS": { ... }, "WEIGHTS": { ... }, "VIEW": { ... }, "LIQUIDITY": { ... }, "CROWD": { ... }, "PROXY": { ... }, } ``` -------------------------------- ### Validate Bittensor Inputs Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Provides examples of using utility functions to validate SS58 addresses, netuids, and chain endpoints. ```python from bittensor_cli.src.bittensor.utils import ( is_valid_ss58_address, validate_netuid, validate_chain_endpoint, ) is_valid_ss58 = is_valid_ss58_address("5ABC...") is_valid_id, error = validate_netuid("1") is_valid_endpoint, error = validate_chain_endpoint("wss://...") ``` -------------------------------- ### Get Subnet Hyperparameters Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Fetches only the hyperparameters for a subnet using a lightweight query. Use this for a quick retrieval of dynamic parameters. ```python async def get_subnet_hyperparams( self, netuid: int, block_hash: Optional[str] = None, ) -> SubnetHyperparameters: pass ``` ```python params = await si.get_subnet_hyperparams(netuid=1) print(f"Tempo: {params['tempo']}") print(f"Min burn: {params['min_burn']}") ``` -------------------------------- ### Initialize and Use Balance Class Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Demonstrates how to create a Balance object from TAO units and access its value in rao units. ```python from bittensor_cli.src.bittensor.balances import Balance b = Balance(5.5) # From TAO print(b.rao) # In rao units ``` -------------------------------- ### Create and Convert Balance Units Source: https://github.com/latent-to/btcli/blob/main/_autodocs/01-balance.md Demonstrates creating Balance objects from TAO and RAO values and converting between these units. Use this for all basic balance manipulations. ```python from bittensor_cli.src.bittensor.balances import Balance # Create from different inputs b1 = Balance(1000000000) # From rao b2 = Balance(1.0) # From tao b3 = Balance.from_tao(2.5) b4 = Balance.from_rao(3000000000) # Convert between units print(f"TAO: {b1.tao}") # TAO: 1.0 print(f"RAO: {b2.rao}") # RAO: 1000000000 # Display with unit print(str(b1)) # τ 1.0000 print(int(b1)) # 1000000000 print(float(b1)) # 1.0 ``` -------------------------------- ### Get Subnet Information Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Fetches complete subnet information, including hyperparameters and statistics. Use this when you need detailed data about a specific subnet. ```python async def get_subnet_info( self, netuid: int, block_hash: Optional[str] = None, ) -> SubnetInfo | None: pass ``` ```python subnet = await si.get_subnet_info(netuid=1) if subnet: print(f"Network: {subnet.network_name}") print(f"Owner: {subnet.owner_hotkey}") print(f"Tempo: {subnet.hyperparameters['tempo']}") ``` -------------------------------- ### Create a New Wallet using btcli Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Command to create a new wallet with a specified name. ```bash btcli wallet create --name my_wallet ``` -------------------------------- ### Get All Subnet Netuids Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Retrieves a list of all active subnet IDs on the network. This is useful for iterating through all available subnets or checking network status. ```python netuids = await si.get_all_subnet_netuids() print(f"Total subnets: {len(netuids)}") for netuid in netuids: print(f" Subnet {netuid}") ``` -------------------------------- ### Get Subtensor Interface Endpoint Source: https://github.com/latent-to/btcli/blob/main/_autodocs/03-constants-config.md Demonstrates how to retrieve the network endpoint for a specific Bittensor network (e.g., 'finney') using the Constants module. ```python from bittensor_cli.src import Constants # Get endpoint for a network endpoint = Constants.network_map["finney"] # endpoint = "wss://entrypoint-finney.opentensor.ai:443" # List all available networks for network in Constants.networks: print(f"{network}: {Constants.network_map[network]}") ``` -------------------------------- ### Table Creation Utility Source: https://github.com/latent-to/btcli/blob/main/_autodocs/GENERATION_SUMMARY.txt Demonstrates the create_table() function for generating formatted text-based tables from data. ```python from bittensor.utilities.table import create_table # Example usage of create_table headers = ['Name', 'Value'] rows = [ ['Item A', 100], ['Item B', 250] ] table_string = create_table(rows=rows, header=headers) print(table_string) ``` -------------------------------- ### Query Neuron Information Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Examples of querying neuron data, including lite versions and specific neuron details, with optional block hash filtering. ```python # Neuron queries await si.get_neurons_lite(netuid: int, block_hash: str | None) -> list[NeuronInfoLite] await si.get_metagraph(netuid: int, block_hash: str | None) -> MetagraphInfo await si.get_neuron(netuid: int, uid: int, block_hash: str | None) -> NeuronInfo | None ``` -------------------------------- ### Display Command Tree Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md View a comprehensive tree structure of all available commands within the BTCLI. ```bash btcli --commands ``` -------------------------------- ### Async Context Manager Entry Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Enters the async context manager for SubtensorInterface, initializing the substrate connection. Use within an 'async with' statement. ```python async with SubtensorInterface("finney") as si: neurons = await si.get_neurons_lite(netuid=1) ``` -------------------------------- ### Get Wallet Public Key (SS58) Source: https://github.com/latent-to/btcli/blob/main/_autodocs/06-utilities.md Retrieves the public SS58 address for a given Bittensor wallet. This is essential for on-chain operations and identifying wallets. ```python from bittensor_cli.src.bittensor.utils import get_hotkey_pub_ss58, CryptoType from bittensor_wallet import Wallet # Get wallet key wallet = Wallet(name="my_wallet") pub_key = get_hotkey_pub_ss58(wallet) ``` -------------------------------- ### Get Hotkey Public Key (SS58) Source: https://github.com/latent-to/btcli/blob/main/_autodocs/06-utilities.md Extracts the SS58-encoded public key from a Bittensor wallet's hotkey. This is essential for identifying wallets on the network. ```python from bittensor_cli.src.bittensor.utils import get_hotkey_pub_ss58 from bittensor_wallet import Wallet wallet = Wallet(name="my_wallet") pub_key = get_hotkey_pub_ss58(wallet) print(f"Public key: {pub_key}") ``` -------------------------------- ### Create Bittensor Wallet via CLI Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md Use the `btcli wallet create` command to create a new wallet. This can be done interactively or with specific options like `--name` and `--hotkey`. ```bash # Interactive creation btcli wallet create # With options btcli wallet create --name my_wallet --hotkey validator_1 ``` -------------------------------- ### Get Balance Unit Symbol Source: https://github.com/latent-to/btcli/blob/main/_autodocs/01-balance.md Retrieves the Unicode symbol representing the current display unit of the balance, either 'τ' for tao or 'ρ' for rao. ```python b = Balance(1.0) unit = b.get_unit() # Returns "τ" (tao symbol) ``` -------------------------------- ### Run Multiple CLI Commands Programmatically Source: https://github.com/latent-to/btcli/blob/main/_autodocs/README.md Demonstrates executing different Bittensor CLI commands, including creating a wallet and listing stakes. ```python from bittensor_cli.cli import CLIManager cli = CLIManager() cli.run(["wallet", "create", "--name", "validator"]) cli.run(["stake", "list"]) ``` -------------------------------- ### Initialize CLIManager Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md Instantiate the CLIManager to set up the main Typer app and all sub-apps for different command groups. This is the primary entry point for the CLI. ```python from bittensor_cli.cli import CLIManager cli = CLIManager() # CLI is now ready to process commands ``` -------------------------------- ### Get Full Delegate Information Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Retrieves comprehensive details for a specific delegate, including profile links and other extended information. Use this for in-depth delegate analysis. ```python delegate = await si.get_delegate_info("5ABC...") if delegate: print(f"Take: {delegate.take:.1%}") print(f"Description: {delegate.description}") ``` -------------------------------- ### Perform Balance Arithmetic and Formatting Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Illustrates creating balances from different units, performing arithmetic operations, and formatting the output. Useful for financial calculations within the Bittensor ecosystem. ```python from bittensor_cli.src.bittensor.balances import Balance # Create from different units b1 = Balance(1000000000) # From rao b2 = Balance(1.0) # From tao # Convert and display print(f"Balance: {b1.tao} TAO") print(f"Display: {str(b1)}") # Arithmetic total = b1 + b2 ``` -------------------------------- ### Get Single Neuron Information Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Retrieves detailed information for a specific neuron identified by its UID within a subnet. Useful for inspecting individual node data. ```python neuron = await si.get_neuron(netuid=1, uid=5) if neuron: print(f"Stake: {neuron.total_stake.tao} TAO") ``` -------------------------------- ### Initialize Balance from Rao and Tao Source: https://github.com/latent-to/btcli/blob/main/_autodocs/01-balance.md Demonstrates creating Balance objects from both integer (rao) and float (tao) inputs. The constructor automatically interprets the input type to set the correct internal representation. ```python from bittensor_cli.src.bittensor.balances import Balance # Create balance from rao (int) balance_rao = Balance(1000000000) print(balance_rao.tao) # 1.0 # Create balance from tao (float) balance_tao = Balance(5.5) print(balance_tao.rao) # 5500000000 ``` -------------------------------- ### Enable Verbose Output for Debugging Source: https://github.com/latent-to/btcli/blob/main/README.md Rerun a failing command with the --verbose flag to get more detailed error output, which is helpful for diagnosing issues before reporting them. ```bash btcli st remove --verbose ``` -------------------------------- ### Subnet Hyperparameter Modification Command Source: https://github.com/latent-to/btcli/blob/main/_autodocs/GENERATION_SUMMARY.txt Conceptual example of a CLI command used to modify subnet hyperparameters. Actual implementation would involve specific arguments and logic. ```python # Conceptual CLI command for modifying hyperparameters # Example: bt subnet set-hyperparam --netuid 1 --param 'min_stake' --value 1000 # This is not executable code but represents a CLI interaction pattern. ``` -------------------------------- ### Main Entry Point Function Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md The main entry point for the btcli. This function instantiates the CLIManager and runs the CLI. It is called automatically when running 'btcli'. ```python from bittensor_cli.cli import main main() ``` -------------------------------- ### Get Stake for Coldkey and Hotkey Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Retrieves the specific amount of stake a coldkey has delegated to a particular hotkey on a given subnet. Use this to check direct delegation amounts. ```python stake = await si.get_stake_for_coldkey_and_hotkey( hotkey_ss58="5ABC...", coldkey_ss58="5XYZ...", netuid=1 ) print(f"Stake: {stake.tao} TAO") ``` -------------------------------- ### Btcli Documentation Overview Source: https://github.com/latent-to/btcli/blob/main/_autodocs/GENERATION_SUMMARY.txt This section provides an overview of the generated documentation for the btcli project, including its organization, features, and quality assurance. ```APIDOC ## Project: /latent-to/btcli ### Content Standards - Markdown with code fence syntax highlighting - Language tags (python, yaml, bash) - Tables for structured data - Consistent heading hierarchy - Cross-references between documents using [[filename.md]] - Technical precision (no marketing copy) - Exact type names from source code - Complete signature documentation - Practical usage examples - Real-world patterns demonstrated ### ORGANIZATION Logical grouping: - Core types and data (Balance, ChainData) - Configuration and constants - Chain interface layer - CLI application layer - Utilities and helpers - Domain-specific (hyperparameters) Cross-references form a knowledge graph: - Index links to all detail pages - Each page links to related pages - Examples link to referenced classes - Types link to their usage locations ### FEATURES - Complete public API coverage - 4,500+ lines of documentation - 9 well-organized markdown files - Parameter tables for all functions - Working code examples throughout - Environment variables documented - Configuration file format shown - Network endpoints reference - Error types documented - Dependencies listed - License information - Quick reference sections - Common usage patterns - Type reference tables ### USAGE Start reading at: /workspace/home/output/README.md Master index: /workspace/home/output/00-index.md For specific topics: - Balance operations → 01-balance.md - Chain data types → 02-chain-data.md - Network configuration → 03-constants-config.md - Blockchain queries → 04-subtensor-interface.md - CLI commands → 05-cli-manager.md - Validation/utilities → 06-utilities.md - Subnet configuration → 07-hyperparameters.md ### FILES GENERATED Location: /workspace/home/output/ - 00-index.md (508 lines) - Master index and quick reference - 01-balance.md (291 lines) - Balance class API - 02-chain-data.md (556 lines) - Data types and structures - 03-constants-config.md (404 lines) - Configuration and constants - 04-subtensor-interface.md (651 lines) - Chain interface API - 05-cli-manager.md (545 lines) - CLI manager and commands - 06-utilities.md (567 lines) - Helper functions and validation - 07-hyperparameters.md (665 lines) - Subnet hyperparameters - README.md (356 lines) - Navigation and quick start Total: 4,543 lines across 9 files Size: ~136 KB ### QUALITY CHECKLIST - [✓] All exported classes documented - [✓] All public methods documented - [✓] All constructor parameters documented - [✓] All return types documented - [✓] All exceptions documented - [✓] All enumerations documented - [✓] All constants documented - [✓] Example code for each major function - [✓] Parameter tables with types - [✓] Default values shown - [✓] Required/optional flags - [✓] Type annotations exact from source - [✓] No invented content - [✓] Cross-references present - [✓] Consistent formatting - [✓] Clear structure and navigation - [✓] Searchable content - [✓] Network endpoints accurate - [✓] Configuration examples valid - [✓] Environment variables documented ### STATUS: COMPLETE All exported functions, classes, methods, types, endpoints, and configuration have been documented. No assumptions or invented content. Every item references the source file and line number. The documentation is ready for immediate use as a technical reference. ``` -------------------------------- ### Run Wallet List Command Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Instantiates the CLIManager and runs the 'wallet list' command. This is a primary way to interact with wallet functionalities via the CLI. ```python from bittensor_cli import CLIManager, __version__, __version_as_int__ # Main CLI application manager cli = CLIManager() cli.run(["wallet", "list"]) ``` -------------------------------- ### Create New Wallet with Crypto Type Source: https://github.com/latent-to/btcli/blob/main/_autodocs/06-utilities.md Demonstrates creating a new wallet and specifying the cryptographic signature type to be used. This is important for security and network compatibility. ```python import random from bittensor_cli.src.bittensor.utils import crypto_type_to_int sig_type = crypto_type_to_int(CryptoType.SR25519) ``` -------------------------------- ### Use CLIManager with Script Arguments Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md This example shows how to use the CLIManager within a Python script to execute commands based on the script's command-line arguments. It can run the current arguments or specific ones. ```python from bittensor_cli.cli import CLIManager import sys cli = CLIManager() # Run with current command-line arguments cli.run() # Or run specific command if len(sys.argv) > 1: cli.run(sys.argv[1:]) ``` -------------------------------- ### Console Output Formatting Source: https://github.com/latent-to/btcli/blob/main/_autodocs/GENERATION_SUMMARY.txt Illustrates using different console output instances for formatted text, tables, and user interaction. ```python from bittensor.utilities.console_output import ConsoleOutput, TableOutput, LoggingOutput # Example usage of ConsoleOutput console = ConsoleOutput() console.info("This is an informational message.") console.warning("This is a warning message.") console.error("This is an error message.") # Example usage of TableOutput headers = ['Col1', 'Col2'] rows = [['Data1', 'Data2'], ['Data3', 'Data4']] table = TableOutput(headers=headers) table.add_rows(rows) table.print_table() # Example usage of LoggingOutput (conceptual) # logger = LoggingOutput() # logger.info("Log message.") ``` -------------------------------- ### Display CLI Version Source: https://github.com/latent-to/btcli/blob/main/_autodocs/05-cli-manager.md Check the version of the BTCLI, including the version number, branch name, and commit hash. ```bash btcli --version ``` -------------------------------- ### Balance Constructor Source: https://github.com/latent-to/btcli/blob/main/_autodocs/01-balance.md Initializes a Balance object. Integer input is interpreted as rao, and float input as tao. ```APIDOC ## Balance Constructor ### Description Initializes a Balance object. Interpreting the input depends on its type: - Integer input: interpreted as rao (smallest unit) - Float input: interpreted as tao (larger unit) ### Parameters #### Path Parameters - **balance** (int | float) - Required - Value in rao if int, tao if float ### Returns `Balance` — A new Balance instance ### Raises `TypeError` — If balance is neither int nor float ### Example ```python from bittensor_cli.src.bittensor.balances import Balance # Create balance from rao (int) balance_rao = Balance(1000000000) print(balance_rao.tao) # 1.0 # Create balance from tao (float) balance_tao = Balance(5.5) print(balance_tao.rao) # 5500000000 ``` ``` -------------------------------- ### Validate Inputs and Confirm Actions Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Illustrates using utility functions for input validation and user confirmation. Use these to ensure data integrity and user consent before critical operations. ```python from bittensor_cli.src.bittensor.utils import ( console, err_console, json_console, verbose_console, confirm_action, is_valid_ss58_address, validate_netuid, validate_chain_endpoint, validate_rate_tolerance, CryptoType, crypto_type_to_int, get_hotkey_pub_ss58, u16_normalized_float, u64_normalized_float, print_error, format_error_message, create_table, ) # Validate inputs is_valid, error = validate_netuid("1") # Get user confirmation if confirm_action("Proceed?"): do_something() # Display output console.print("[green]Success![/green]") ``` -------------------------------- ### Construct Balance Object Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Shows different ways to create a Balance object, including from integer/float values, Tao, and Rao units. ```python # Construction Balance(balance: int | float) Balance.from_tao(amount: float) -> Balance Balance.from_rao(amount: int) -> Balance ``` -------------------------------- ### query() Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md A low-level pass-through method to query the substrate interface for chain data. It allows direct access to module storage functions with optional parameters and subscription handlers. ```APIDOC ## query() ### Description A low-level pass-through method to query the substrate interface for chain data. It allows direct access to module storage functions with optional parameters and subscription handlers. ### Signature ```python async def query( self, module: str, storage_function: str, params: Optional[list] = None, block_hash: Optional[str] = None, raw_storage_key: Optional[bytes] = None, subscription_handler=None, ) -> ScaleValue ``` ### Parameters #### Parameters - **module** (str) - Required - Pallet name (e.g., "SubtensorModule") - **storage_function** (str) - Required - Storage function name - **params** (list | None) - Optional - Query parameters - **block_hash** (str | None) - Optional - Block hash for historical queries - **raw_storage_key** (bytes | None) - Optional - Raw storage key bytes - **subscription_handler** (callable | None) - Optional - Callback for subscriptions ### Returns - `ScaleValue` — Decoded chain value ### Example ```python # Query the total issuance total_issuance = await si.query( module="Balances", storage_function="TotalIssuance" ) ``` ``` -------------------------------- ### Default Configuration Settings Source: https://github.com/latent-to/btcli/blob/main/_autodocs/03-constants-config.md Provides default values for various CLI settings, including subnet ID, rate tolerance, file paths for configuration and logging, and network settings for the subtensor. Includes nested configurations for wallet and dashboard. ```python class Defaults: netuid = 1 # Default subnet ID rate_tolerance = 0.005 # Default rate tolerance (0.5%) class config: base_path = "~/.bittensor" path = "~/.bittensor/config.yml" debug_file_path = "~/.bittensor/debug.txt" dictionary = { ... } class proxies: base_path = "~/.bittensor" path = "~/.bittensor/bittensor.db" dictionary = {} class subtensor: network = "finney" chain_endpoint = None _mock = False class wallet: name = "default" hotkey = "default" path = "~/.bittensor/wallets/" class logging: debug = False trace = False record_log = False logging_dir = "~/.bittensor/miners" class dashboard: path = "~/.bittensor/dashboard/" ``` -------------------------------- ### SubtensorInterface Context Manager Source: https://github.com/latent-to/btcli/blob/main/_autodocs/04-subtensor-interface.md Provides asynchronous context management for the SubtensorInterface, handling the initialization and graceful closure of the substrate connection. ```APIDOC ## SubtensorInterface Context Manager ### Description Provides asynchronous context management for the SubtensorInterface, handling the initialization and graceful closure of the substrate connection. ### `__aenter__()` #### Signature ```python async def __aenter__(self) -> SubtensorInterface ``` #### Description Async context manager entry. Initializes the substrate connection. #### Returns - Self for use in `async with` statement #### Raises - `typer.Exit(1)` on timeout #### Example ```python async with SubtensorInterface("finney") as si: neurons = await si.get_neurons_lite(netuid=1) ``` ### `__aexit__()` #### Signature ```python async def __aexit__(self, exc_type, exc_val, exc_tb) -> None ``` #### Description Async context manager exit. Closes the substrate connection gracefully. ``` -------------------------------- ### Access and Convert Balance Source: https://github.com/latent-to/btcli/blob/main/_autodocs/00-index.md Illustrates how to access Tao and Rao values from a Balance object, and how to convert it to integers, floats, or strings. ```python # Access balance.tao -> float balance.rao -> int int(balance) -> int float(balance) -> float str(balance) -> str ``` -------------------------------- ### SubtensorInterface Query Methods Source: https://github.com/latent-to/btcli/blob/main/_autodocs/GENERATION_SUMMARY.txt Illustrates querying neuron, stake, and delegate information using the SubtensorInterface class. Requires an active connection. ```python import asyncio from bittensor.subtensor import SubtensorInterface async def query_subtensor_data(): async with SubtensorInterface() as subtensor: # Example: Get neuron info neuron_info = await subtensor.get_neuron(uid=0) print(f"Neuron Info (UID 0): {neuron_info}") # Example: Get stake for a coldkey stake_info = await subtensor.get_stake_for_coldkey(coldkey_ss58='YOUR_COLDKEY_ADDRESS') print(f"Stake Info: {stake_info}") # Example: Get delegates delegates = await subtensor.get_delegates_lite() print(f"Delegates: {delegates[:5]}") # Print first 5 asyncio.run(query_subtensor_data()) ``` -------------------------------- ### Console Instances Source: https://github.com/latent-to/btcli/blob/main/_autodocs/06-utilities.md Four Rich console instances are provided for different output contexts: main output, JSON output, error output, and verbose output. ```APIDOC ## Console Instances Four Rich console instances are provided for different output contexts: ```python from bittensor_cli.src.bittensor.utils import ( console, # Main output (colored, formatted) json_console, # JSON output (no markup, no color) err_console, # Error output (stderr stream) verbose_console, # Verbose/debug output (quiet mode) ) ``` | Console | Purpose | Color | Markup | Stream | |---------|---------|-------|--------|--------| | console | Normal output | Yes | Yes | stdout | | json_console | JSON data | No | No | stdout | | err_console | Error messages | Yes | Yes | stderr | | verbose_console | Verbose logging | Disabled | Yes | stdout | **Example:** ```python from bittensor_cli.src.bittensor.utils import console, err_console # Normal output console.print("[green]Success:[/green] Operation completed") # Error output err_console.print("[red]Error:[/red] Invalid argument") ``` ``` -------------------------------- ### Balance Methods Source: https://github.com/latent-to/btcli/blob/main/_autodocs/01-balance.md Provides methods for converting balance to dictionary, and creating balances from specific units. ```APIDOC ## Balance Methods ### to_dict() #### Description Returns the balance as a dictionary with both representations. #### Returns Dictionary with keys "rao" (int) and "tao" (float) #### Example ```python b = Balance(1.5) print(b.to_dict()) # {'rao': 1500000000, 'tao': 1.5} ``` ### from_float(amount: float) → Balance #### Description Create a Balance from a float value (interpreted as tao). #### Parameters - **amount** (float) - Required - Value in tao #### Returns `Balance` #### Example ```python b = Balance.from_float(2.75) assert b.tao == 2.75 ``` ### from_tao(amount: float) → Balance #### Description Create a Balance explicitly from tao units. Equivalent to `from_float()`. #### Parameters - **amount** (float) - Required - Value in tao #### Returns `Balance` #### Example ```python b = Balance.from_tao(10.0) assert b.tao == 10.0 assert b.rao == 10000000000 ``` ### from_rao(amount: int) → Balance #### Description Create a Balance explicitly from rao units. #### Parameters - **amount** (int) - Required - Value in rao #### Returns `Balance` #### Example ```python b = Balance.from_rao(5000000000) assert b.tao == 5.0 assert b.rao == 5000000000 ``` ### get_unit() → str #### Description Returns the current display unit symbol (τ for tao or ρ for rao). #### Returns `str` — Unicode symbol for the unit #### Example ```python b = Balance(1.0) unit = b.get_unit() # Returns "τ" (tao symbol) ``` ### set_unit(netuid: int) → Balance #### Description Set the display unit based on subnet ID. Enables context-aware unit display. #### Parameters - **netuid** (int) - Required - Subnet ID (typically 0-63) #### Returns `Balance` (self, for chaining) #### Example ```python b = Balance(100.0).set_unit(1) # Unit will be displayed based on subnet context ``` ```