bittensor.core.async_subtensor#
Classes#
Thin layer for interacting with Substrate Interface. Mostly a collection of frequently-used calls. |
Functions#
|
Factory method to create an initialized AsyncSubtensor. Mainly useful for when you don't want to run |
Module Contents#
- class bittensor.core.async_subtensor.AsyncSubtensor(network=None, config=None, _mock=False, log_verbose=False)#
Bases:
bittensor.core.types.SubtensorMixin
Thin layer for interacting with Substrate Interface. Mostly a collection of frequently-used calls.
Initializes an instance of the AsyncSubtensor class.
- Parameters:
- Raises:
Any exceptions raised during the setup, configuration, or connection process. –
- async add_stake(wallet, hotkey_ss58=None, netuid=None, amount=None, wait_for_inclusion=True, wait_for_finalization=False)#
Adds the specified amount of stake to a neuron identified by the hotkey
SS58
address. Staking is a fundamental process in the Bittensor network that enables neurons to participate actively and earnincentives.
- Parameters:
wallet (bittensor_wallet.Wallet) – The wallet to be used for staking.
hotkey_ss58 (Optional[str]) – The
SS58
address of the hotkey associated with the neuron.netuid (Optional[int]) – subnet UID
amount (Balance) – The amount of TAO to stake.
wait_for_inclusion (bool) – Waits for the transaction to be included in a block.
wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain.
- Returns:
True
if the staking is successful, False otherwise.- Return type:
- This function enables neurons to increase their stake in the network, enhancing their influence and potential
rewards in line with Bittensor’s consensus and reward mechanisms.
- async add_stake_multiple(wallet, hotkey_ss58s, netuids, amounts=None, wait_for_inclusion=True, wait_for_finalization=False)#
Adds stakes to multiple neurons identified by their hotkey SS58 addresses. This bulk operation allows for efficient staking across different neurons from a single wallet.
- Parameters:
wallet (bittensor_wallet.Wallet) – The wallet used for staking.
hotkey_ss58s (list[str]) – List of
SS58
addresses of hotkeys to stake to.amounts (list[Balance]) – Corresponding amounts of TAO to stake for each hotkey.
wait_for_inclusion (bool) – Waits for the transaction to be included in a block.
wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain.
- Returns:
True
if the staking is successful for all specified neurons, False otherwise.- Return type:
- This function is essential for managing stakes across multiple neurons, reflecting the dynamic and collaborative
nature of the Bittensor network.
- async all_subnets(block_number=None, block_hash=None, reuse_block=False)#
Retrieves the subnet information for all subnets in the network.
- Parameters:
block_number (Optional[int]) – The block number to query the subnet information from. Do not specify if using block_hash or reuse_block
block_hash (Optional[str]) – The hash of the blockchain block number for the query. Do not specify if using reuse_block or block.
reuse_block (bool) – Whether to reuse the last-used blockchain block hash. Do not set if using block_hash or block.
- Returns:
A list of DynamicInfo objects, each containing detailed information about a subnet.
- Return type:
Optional[DynamicInfo]
- property block#
Provides an asynchronous property to retrieve the current block.
- async blocks_since_last_update(netuid, uid)#
Returns the number of blocks since the last update for a specific UID in the subnetwork.
- async bonds(netuid, block=None, block_hash=None, reuse_block=False)#
- Retrieves the bond distribution set by neurons within a specific subnet of the Bittensor network.
Bonds represent the investments or commitments made by neurons in one another, indicating a level of trust and perceived value. This bonding mechanism is integral to the network’s market-based approach to measuring and rewarding machine intelligence.
- Parameters:
netuid (int) – The network UID of the subnet to query.
block (Optional[int]) – the block number for this query. Do not specify if using block_hash or reuse_block
block_hash (Optional[str]) – The hash of the blockchain block number for the query. Do not specify if using reuse_block or block.
reuse_block (bool) – Whether to reuse the last-used blockchain block hash. Do not set if using block_hash or block.
- Returns:
List of tuples mapping each neuron’s UID to its bonds with other neurons.
- Return type:
- Understanding bond distributions is crucial for analyzing the trust dynamics and market behavior within the
subnet. It reflects how neurons recognize and invest in each other’s intelligence and contributions, supporting diverse and niche systems within the Bittensor ecosystem.
- async burned_register(wallet, netuid, wait_for_inclusion=False, wait_for_finalization=True)#
- Registers a neuron on the Bittensor network by recycling TAO. This method of registration involves recycling
TAO tokens, allowing them to be re-mined by performing work on the network.
- Parameters:
wallet (bittensor_wallet.Wallet) – The wallet associated with the neuron to be registered.
netuid (int) – The unique identifier of the subnet.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block. Defaults to False.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain. Defaults to True.
- Returns:
True
if the registration is successful, False otherwise.- Return type:
- async close()#
Close the connection.
- async commit(wallet, netuid, data)#
Commits arbitrary data to the Bittensor network by publishing metadata.
- async commit_reveal_enabled(netuid, block=None, block_hash=None, reuse_block=False)#
Check if commit-reveal mechanism is enabled for a given network at a specific block.
- Parameters:
netuid (int) – The network identifier for which to check the commit-reveal mechanism.
block (Optional[int]) – The block number to query. Do not specify if using block_hash or reuse_block.
block_hash (Optional[str]) – The block hash of block at which to check the parameter. Do not set if using block or reuse_block.
reuse_block (bool) – Whether to reuse the last-used blockchain block hash. Do not set if using block_hash or block.
- Returns:
Returns the integer value of the hyperparameter if available; otherwise, returns None.
- Return type:
- async commit_weights(wallet, netuid, salt, uids, weights, version_key=version_as_int, wait_for_inclusion=False, wait_for_finalization=False, max_retries=5)#
Commits a hash of the neuron’s weights to the Bittensor blockchain using the provided wallet. This action serves as a commitment or snapshot of the neuron’s current weight distribution.
- Parameters:
wallet (bittensor_wallet.Wallet) – The wallet associated with the neuron committing the weights.
netuid (int) – The unique identifier of the subnet.
salt (list[int]) – list of randomly generated integers as salt to generated weighted hash.
uids (np.ndarray) – NumPy array of neuron UIDs for which weights are being committed.
weights (np.ndarray) – NumPy array of weight values corresponding to each UID.
version_key (int) – Version key for compatibility with the network. Default is
int representation of Bittensor version.
.wait_for_inclusion (bool) – Waits for the transaction to be included in a block. Default is
False
.wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain. Default is
False
.max_retries (int) – The number of maximum attempts to commit weights. Default is
5
.
- Returns:
True
if the weight commitment is successful, False otherwise. And msg, a stringvalue describing the success or potential error.
- Return type:
- This function allows neurons to create a tamper-proof record of their weight distribution at a specific point
in time, enhancing transparency and accountability within the Bittensor network.
- async determine_block_hash(block, block_hash=None, reuse_block=False)#
- async difficulty(netuid, block=None, block_hash=None, reuse_block=False)#
Retrieves the ‘Difficulty’ hyperparameter for a specified subnet in the Bittensor network.
- This parameter is instrumental in determining the computational challenge required for neurons to participate in
consensus and validation processes.
- Parameters:
netuid (int) – The unique identifier of the subnet.
block (Optional[int]) – The blockchain block number for the query. Do not specify if using block_hash or reuse_block
block_hash (Optional[str]) – The hash of the block to retrieve the parameter from. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to use the last-used block. Do not set if using block_hash or block.
- Returns:
The value of the ‘Difficulty’ hyperparameter if the subnet exists,
None
otherwise.- Return type:
Optional[int]
- The ‘Difficulty’ parameter directly impacts the network’s security and integrity by setting the computational
effort required for validating transactions and participating in the network’s consensus mechanism.
- async does_hotkey_exist(hotkey_ss58, block=None, block_hash=None, reuse_block=False)#
Returns true if the hotkey is known by the chain and there are accounts.
- Parameters:
hotkey_ss58 (str) – The SS58 address of the hotkey.
block (Optional[int]) – the block number for this query. Do not specify if using block_hash or reuse_block
block_hash (Optional[str]) – The hash of the block number to check the hotkey against. Do not specify if using reuse_block or block.
reuse_block (bool) – Whether to reuse the last-used blockchain hash. Do not set if using block_hash or block.
- Returns:
True if the hotkey is known by the chain and there are accounts, False otherwise.
- Return type:
- async encode_params(call_definition, params)#
Returns a hex encoded string of the params using their types.
- async filter_netuids_by_registered_hotkeys(all_netuids, filter_for_netuids, all_hotkeys, block=None, block_hash=None, reuse_block=False)#
Filters a given list of all netuids for certain specified netuids and hotkeys
- Parameters:
all_netuids (Iterable[int]) – A list of netuids to filter.
filter_for_netuids (Iterable[int]) – A subset of all_netuids to filter from the main list.
all_hotkeys (Iterable[Wallet]) – Hotkeys to filter from the main list.
block (Optional[int]) – The blockchain block number for the query.
block_hash (str) – hash of the blockchain block number at which to perform the query.
reuse_block (bool) – whether to reuse the last-used blockchain hash when retrieving info.
- Returns:
The filtered list of netuids.
- Return type:
- async get_all_commitments(netuid, block=None, block_hash=None, reuse_block=False)#
Retrieves the on-chain commitments for a specific subnet in the Bittensor network.
- Parameters:
netuid (int) – The unique identifier of the subnetwork.
block (Optional[int]) – The block number to retrieve the commitment from. If None, the latest block is used. Default is
None
.block_hash (Optional[str]) – The hash of the block to retrieve the subnet unique identifiers from.
reuse_block (bool) – Whether to reuse the last-used block hash.
- Returns:
A mapping of the ss58:commitment with the commitment as a string
- Return type:
- async get_all_metagraphs_info(block=None, block_hash=None, reuse_block=False)#
Retrieves a list of MetagraphInfo objects for all subnets
- Parameters:
block (Optional[int]) – the block number at which to retrieve the hyperparameter. Do not specify if using block_hash or reuse_block
block_hash (Optional[str]) – The hash of blockchain block number for the query. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to reuse the last-used block hash. Do not set if using block_hash or block.
- Returns:
MetagraphInfo dataclass
- Return type:
list[bittensor.core.chain_data.MetagraphInfo]
- async get_all_subnets_info(block=None, block_hash=None, reuse_block=False)#
- Retrieves detailed information about all subnets within the Bittensor network. This function provides
comprehensive data on each subnet, including its characteristics and operational parameters.
- Parameters:
- Returns:
A list of SubnetInfo objects, each containing detailed information about a subnet.
- Return type:
- Gaining insights into the subnets’ details assists in understanding the network’s composition, the roles of
different subnets, and their unique features.
- async get_balance(address, block=None, block_hash=None, reuse_block=False)#
Retrieves the balance for given coldkey.
- Parameters:
- Returns:
Balance object.
- Return type:
- async get_balances(*addresses, block=None, block_hash=None, reuse_block=False)#
Retrieves the balance for given coldkey(s)
- Parameters:
- Returns:
Balance objects}.
- Return type:
Dict of {address
- async get_block_hash(block=None)#
- Retrieves the hash of a specific block on the Bittensor blockchain. The block hash is a unique identifier
representing the cryptographic hash of the block’s content, ensuring its integrity and immutability.
- Parameters:
block (int) – The block number for which the hash is to be retrieved.
- Returns:
The cryptographic hash of the specified block.
- Return type:
- The block hash is a fundamental aspect of blockchain technology, providing a secure reference to each block’s
data. It is crucial for verifying transactions, ensuring data consistency, and maintaining the trustworthiness of the blockchain.
- async get_children(hotkey, netuid, block=None, block_hash=None, reuse_block=False)#
- This method retrieves the children of a given hotkey and netuid. It queries the SubtensorModule’s ChildKeys
storage function to get the children and formats them before returning as a tuple.
- Parameters:
hotkey (str) – The hotkey value.
netuid (int) – The netuid value.
block (Optional[int]) – The block number for which the children are to be retrieved.
block_hash (Optional[str]) – The hash of the block to retrieve the subnet unique identifiers from.
reuse_block (bool) – Whether to reuse the last-used block hash.
- Returns:
- A tuple containing a boolean indicating success or failure, a list of formatted children, and an error
message (if applicable)
- Return type:
- async get_commitment(netuid, uid, block=None, block_hash=None, reuse_block=False)#
Retrieves the on-chain commitment for a specific neuron in the Bittensor network.
- Parameters:
netuid (int) – The unique identifier of the subnetwork.
uid (int) – The unique identifier of the neuron.
block (Optional[int]) – The block number to retrieve the commitment from. If None, the latest block is used. Default is
None
.block_hash (Optional[str]) – The hash of the block to retrieve the subnet unique identifiers from.
reuse_block (bool) – Whether to reuse the last-used block hash.
- Returns:
The commitment data as a string.
- Return type:
- async get_current_block()#
- Returns the current block number on the Bittensor blockchain. This function provides the latest block number,
indicating the most recent state of the blockchain.
- Returns:
The current chain block number.
- Return type:
- Knowing the current block number is essential for querying real-time data and performing time-sensitive
operations on the blockchain. It serves as a reference point for network activities and data synchronization.
- async get_current_weight_commit_info(netuid, block=None, block_hash=None, reuse_block=False)#
Retrieves CRV3 weight commit information for a specific subnet.
- Parameters:
- Returns:
A list of commit details, where each entry is a dictionary with keys ‘who’, ‘serialized_commit’, and ‘reveal_round’, or an empty list if no data is found.
- Return type:
- async get_delegate_by_hotkey(hotkey_ss58, block=None, block_hash=None, reuse_block=False)#
- Retrieves detailed information about a delegate neuron based on its hotkey. This function provides a
comprehensive view of the delegate’s status, including its stakes, nominators, and reward distribution.
- Parameters:
- Returns:
Detailed information about the delegate neuron,
None
if not found.- Return type:
Optional[DelegateInfo]
- This function is essential for understanding the roles and influence of delegate neurons within the Bittensor
network’s consensus and governance structures.
- async get_delegate_identities(block=None, block_hash=None, reuse_block=False)#
- Fetches delegates identities from the chain and GitHub. Preference is given to chain data, and missing info is
filled-in by the info from GitHub. At some point, we want to totally move away from fetching this info from GitHub, but chain data is still limited in that regard.
- async get_delegate_take(hotkey_ss58, block=None, block_hash=None, reuse_block=False)#
- Retrieves the delegate ‘take’ percentage for a neuron identified by its hotkey. The ‘take’ represents the
percentage of rewards that the delegate claims from its nominators’ stakes.
- Parameters:
- Returns:
The delegate take percentage, None if not available.
- Return type:
Optional[float]
- The delegate take is a critical parameter in the network’s incentive structure, influencing the distribution of
rewards among neurons and their nominators.
- async get_delegated(coldkey_ss58, block=None, block_hash=None, reuse_block=False)#
Retrieves a list of delegates and their associated stakes for a given coldkey. This function identifies the delegates that a specific account has staked tokens on.
- Parameters:
- Returns:
A list of tuples, each containing a delegate’s information and staked amount.
- Return type:
list[tuple[bittensor.core.chain_data.DelegateInfo, bittensor.utils.balance.Balance]]
- This function is important for account holders to understand their stake allocations and their involvement in
the network’s delegation and consensus mechanisms.
- async get_delegates(block=None, block_hash=None, reuse_block=False)#
Fetches all delegates on the chain
- Parameters:
- Returns:
List of DelegateInfo objects, or an empty list if there are no delegates.
- Return type:
list[bittensor.core.chain_data.DelegateInfo]
- async get_existential_deposit(block=None, block_hash=None, reuse_block=False)#
Retrieves the existential deposit amount for the Bittensor blockchain. The existential deposit is the minimum amount of TAO required for an account to exist on the blockchain. Accounts with balances below this threshold can be reaped to conserve network resources.
- Parameters:
- Returns:
The existential deposit amount.
- Return type:
- The existential deposit is a fundamental economic parameter in the Bittensor network, ensuring efficient use of
storage and preventing the proliferation of dust accounts.
- async get_hotkey_owner(hotkey_ss58, block=None, block_hash=None, reuse_block=False)#
Retrieves the owner of the given hotkey at a specific block hash. This function queries the blockchain for the owner of the provided hotkey. If the hotkey does not exist at the
specified block hash, it returns None.
- Parameters:
- Returns:
The SS58 address of the owner if the hotkey exists, or None if it doesn’t.
- Return type:
Optional[str]
- async get_hyperparameter(param_name, netuid, block=None, block_hash=None, reuse_block=False)#
Retrieves a specified hyperparameter for a specific subnet.
- Parameters:
param_name (str) – The name of the hyperparameter to retrieve.
netuid (int) – The unique identifier of the subnet.
block (Optional[int]) – the block number at which to retrieve the hyperparameter. Do not specify if using block_hash or reuse_block
block_hash (Optional[str]) – The hash of blockchain block number for the query. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to reuse the last-used block hash. Do not set if using block_hash or block.
- Returns:
The value of the specified hyperparameter if the subnet exists, or None
- Return type:
Optional[Any]
- async get_metagraph_info(netuid, block=None, block_hash=None, reuse_block=False)#
Retrieves the MetagraphInfo dataclass from the node for a single subnet (netuid)
- Parameters:
netuid (int) – The NetUID of the subnet.
block (Optional[int]) – the block number at which to retrieve the hyperparameter. Do not specify if using block_hash or reuse_block
block_hash (Optional[str]) – The hash of blockchain block number for the query. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to reuse the last-used block hash. Do not set if using block_hash or block.
- Returns:
MetagraphInfo dataclass
- Return type:
Optional[bittensor.core.chain_data.MetagraphInfo]
- async get_minimum_required_stake()#
Returns the minimum required stake for nominators in the Subtensor network. This method retries the substrate call up to three times with exponential backoff in case of failures.
- async get_netuids_for_hotkey(hotkey_ss58, block=None, block_hash=None, reuse_block=False)#
- Retrieves a list of subnet UIDs (netuids) for which a given hotkey is a member. This function identifies the
specific subnets within the Bittensor network where the neuron associated with the hotkey is active.
- Parameters:
hotkey_ss58 (str) – The
SS58
address of the neuron’s hotkey.block (Optional[int]) – The blockchain block number for the query.
block_hash (Optional[str]) – The hash of the blockchain block number at which to perform the query.
reuse_block (Optional[bool]) – Whether to reuse the last-used block hash when retrieving info.
- Returns:
A list of netuids where the neuron is a member.
- Return type:
- async get_neuron_certificate(hotkey, netuid, block=None, block_hash=None, reuse_block=False)#
- Retrieves the TLS certificate for a specific neuron identified by its unique identifier (UID) within a
specified subnet (netuid) of the Bittensor network.
- Parameters:
hotkey (str) – The hotkey to query.
netuid (int) – The unique identifier of the subnet.
block (Optional[int]) – The blockchain block number for the query.
block_hash (Optional[str]) – The hash of the block to retrieve the parameter from. Do not specify if using block or reuse_block.
reuse_block (bool) – Whether to use the last-used block. Do not set if using block_hash or block.
- Returns:
the certificate of the neuron if found, None otherwise.
- Return type:
Optional[bittensor.utils.Certificate]
This function is used for certificate discovery for setting up mutual tls communication between neurons.
- async get_neuron_for_pubkey_and_subnet(hotkey_ss58, netuid, block=None, block_hash=None, reuse_block=False)#
- Retrieves information about a neuron based on its public key (hotkey SS58 address) and the specific subnet UID
(netuid). This function provides detailed neuron information for a particular subnet within the Bittensor network.
- Parameters:
hotkey_ss58 (str) – The
SS58
address of the neuron’s hotkey.netuid (int) – The unique identifier of the subnet.
block (Optional[int]) – The blockchain block number for the query.
block_hash (Optional[int]) – The blockchain block number at which to perform the query.
reuse_block (bool) – Whether to reuse the last-used blockchain block hash.
- Returns:
- Detailed information about the neuron if found,
None
otherwise.
- Return type:
- This function is crucial for accessing specific neuron data and understanding its status, stake, and other
attributes within a particular subnet of the Bittensor ecosystem.
- async get_stake(coldkey_ss58, hotkey_ss58, netuid, block=None, block_hash=None, reuse_block=False)#
Returns the stake under a coldkey - hotkey pairing.
- Parameters:
hotkey_ss58 (str) – The SS58 address of the hotkey.
coldkey_ss58 (str) – The SS58 address of the coldkey.
netuid (int) – The subnet ID.
block (Optional[int]) – The block number at which to query the stake information.
block_hash (Optional[str]) – The hash of the block to retrieve the stake from. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to use the last-used block. Do not set if using block_hash or block.
- Returns:
The stake under the coldkey - hotkey pairing.
- Return type:
- async get_stake_for_coldkey(coldkey_ss58, block=None, block_hash=None, reuse_block=False)#
Retrieves the stake information for a given coldkey.
- Parameters:
- Returns:
A list of StakeInfo objects, or
None
if no stake information is found.- Return type:
- async get_stake_for_coldkey_and_hotkey(coldkey_ss58, hotkey_ss58, netuids=None, block=None, block_hash=None, reuse_block=False)#
Retrieves all coldkey-hotkey pairing stake across specified (or all) subnets
- Parameters:
coldkey_ss58 (str) – The SS58 address of the coldkey.
hotkey_ss58 (str) – The SS58 address of the hotkey.
netuids (Optional[list[int]]) – The subnet IDs to query for. Set to None for all subnets.
block (Optional[int]) – The block number at which to query the stake information.
block_hash (Optional[str]) – The hash of the block to retrieve the stake from. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to use the last-used block. Do not set if using block_hash or block.
- Returns:
StakeInfo} pairing of all stakes across all subnets.
- Return type:
A {netuid
- get_stake_info_for_coldkey#
- async get_subnet_burn_cost(block=None, block_hash=None, reuse_block=False)#
- Retrieves the burn cost for registering a new subnet within the Bittensor network. This cost represents the
amount of Tao that needs to be locked or burned to establish a new subnet.
- Parameters:
- Returns:
The burn cost for subnet registration.
- Return type:
- The subnet burn cost is an important economic parameter, reflecting the network’s mechanisms for controlling
the proliferation of subnets and ensuring their commitment to the network’s long-term viability.
- async get_subnet_hyperparameters(netuid, block=None, block_hash=None, reuse_block=False)#
- Retrieves the hyperparameters for a specific subnet within the Bittensor network. These hyperparameters define
the operational settings and rules governing the subnet’s behavior.
- Parameters:
- Returns:
The subnet’s hyperparameters, or None if not available.
- Return type:
Optional[bittensor.core.chain_data.SubnetHyperparameters]
- Understanding the hyperparameters is crucial for comprehending how subnets are configured and managed, and how
they interact with the network’s consensus and incentive mechanisms.
- async get_subnet_reveal_period_epochs(netuid, block=None, block_hash=None)#
Retrieve the SubnetRevealPeriodEpochs hyperparameter.
- async get_subnets(block=None, block_hash=None, reuse_block=False)#
Retrieves the list of all subnet unique identifiers (netuids) currently present in the Bittensor network.
- Parameters:
- Returns:
A list of subnet netuids.
- Return type:
This function provides a comprehensive view of the subnets within the Bittensor network, offering insights into its diversity and scale.
- async get_total_subnets(block=None, block_hash=None, reuse_block=False)#
Retrieves the total number of subnets within the Bittensor network as of a specific blockchain block.
- Parameters:
- Returns:
The total number of subnets in the network.
- Return type:
Optional[str]
- Understanding the total number of subnets is essential for assessing the network’s growth and the extent of its
decentralized infrastructure.
- async get_transfer_fee(wallet, dest, value)#
- Calculates the transaction fee for transferring tokens from a wallet to a specified destination address. This
function simulates the transfer to estimate the associated cost, taking into account the current network conditions and transaction complexity.
- Parameters:
wallet (bittensor_wallet.Wallet) – The wallet from which the transfer is initiated.
dest (str) – The
SS58
address of the destination account.value (Union[bittensor.utils.balance.Balance, float, int]) – The amount of tokens to be transferred, specified as a Balance object, or in Tao (float) or Rao (int) units.
- Returns:
- The estimated transaction fee for the transfer, represented as a Balance
object.
- Return type:
- Estimating the transfer fee is essential for planning and executing token transactions, ensuring that the wallet
has sufficient funds to cover both the transfer amount and the associated costs. This function provides a crucial tool for managing financial operations within the Bittensor network.
- async get_uid_for_hotkey_on_subnet(hotkey_ss58, netuid, block=None, block_hash=None, reuse_block=False)#
Retrieves the unique identifier (UID) for a neuron’s hotkey on a specific subnet.
- Parameters:
hotkey_ss58 (str) – The
SS58
address of the neuron’s hotkey.netuid (int) – The unique identifier of the subnet.
block (Optional[int]) – The blockchain block number for the query.
block_hash (Optional[str]) – The blockchain block_hash representation of the block id.
reuse_block (bool) – Whether to reuse the last-used blockchain block hash.
- Returns:
The UID of the neuron if it is registered on the subnet,
None
otherwise.- Return type:
Optional[int]
- The UID is a critical identifier within the network, linking the neuron’s hotkey to its operational and
governance activities on a particular subnet.
- async get_vote_data(proposal_hash, block=None, block_hash=None, reuse_block=False)#
- Retrieves the voting data for a specific proposal on the Bittensor blockchain. This data includes information
about how senate members have voted on the proposal.
- Parameters:
proposal_hash (str) – The hash of the proposal for which voting data is requested.
block (Optional[int]) – The blockchain block number for the query.
block_hash (Optional[str]) – The hash of the blockchain block number to query the voting data.
reuse_block (bool) – Whether to reuse the last-used blockchain block hash.
- Returns:
An object containing the proposal’s voting data, or None if not found.
- Return type:
Optional[bittensor.core.chain_data.ProposalVoteData]
- This function is important for tracking and understanding the decision-making processes within the Bittensor
network, particularly how proposals are received and acted upon by the governing body.
- async immunity_period(netuid, block=None, block_hash=None, reuse_block=False)#
- Retrieves the ‘ImmunityPeriod’ hyperparameter for a specific subnet. This parameter defines the duration during
which new neurons are protected from certain network penalties or restrictions.
- Parameters:
- Returns:
The value of the ‘ImmunityPeriod’ hyperparameter if the subnet exists,
None
otherwise.- Return type:
Optional[int]
- The ‘ImmunityPeriod’ is a critical aspect of the network’s governance system, ensuring that new participants
have a grace period to establish themselves and contribute to the network without facing immediate punitive actions.
- async initialize()#
- async is_hotkey_delegate(hotkey_ss58, block=None, block_hash=None, reuse_block=False)#
- Determines whether a given hotkey (public key) is a delegate on the Bittensor network. This function checks if
the neuron associated with the hotkey is part of the network’s delegation system.
- Parameters:
- Returns:
True if the hotkey is a delegate, False otherwise.
- Return type:
- Being a delegate is a significant status within the Bittensor network, indicating a neuron’s involvement in
consensus and governance processes.
- async is_hotkey_registered(hotkey_ss58, netuid=None, block=None, block_hash=None, reuse_block=False)#
- Determines whether a given hotkey (public key) is registered in the Bittensor network, either globally across
any subnet or specifically on a specified subnet. This function checks the registration status of a neuron identified by its hotkey, which is crucial for validating its participation and activities within the network.
- Parameters:
hotkey_ss58 (str) – The SS58 address of the neuron’s hotkey.
netuid (Optional[int]) – The unique identifier of the subnet to check the registration. If None, the registration is checked across all subnets.
block (Optional[int]) – The blockchain block number at which to perform the query.
block_hash (Optional[str]) – The blockchain block_hash representation of the block id. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to reuse the last-used blockchain block hash. Do not set if using block_hash or reuse_block.
- Returns:
- True if the hotkey is registered in the specified context (either any subnet or a specific subnet),
False otherwise.
- Return type:
- This function is important for verifying the active status of neurons in the Bittensor network. It aids in
understanding whether a neuron is eligible to participate in network processes such as consensus, validation, and incentive distribution based on its registration status.
- async is_hotkey_registered_any(hotkey_ss58, block=None, block_hash=None, reuse_block=False)#
Checks if a neuron’s hotkey is registered on any subnet within the Bittensor network.
- Parameters:
- Returns:
True
if the hotkey is registered on any subnet, False otherwise.- Return type:
This function is essential for determining the network-wide presence and participation of a neuron.
- async is_hotkey_registered_on_subnet(hotkey_ss58, netuid, block=None, block_hash=None, reuse_block=False)#
Checks if the hotkey is registered on a given netuid.
- async last_drand_round()#
Retrieves the last drand round emitted in bittensor. This corresponds when committed weights will be revealed.
- Returns:
The latest Drand round emitted in bittensor.
- Return type:
- log_verbose = False#
- async max_weight_limit(netuid, block=None, block_hash=None, reuse_block=False)#
Returns network MaxWeightsLimit hyperparameter.
- Parameters:
- Returns:
- The value of the MaxWeightsLimit hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the MaxWeightsLimit hyperparameter, or
- Return type:
Optional[float]
- async metagraph(netuid, lite=True, block=None)#
- Returns a synced metagraph for a specified subnet within the Bittensor network. The metagraph represents the
network’s structure, including neuron connections and interactions.
- Parameters:
- Returns:
- The metagraph representing the subnet’s structure and neuron
relationships.
- Return type:
- The metagraph is an essential tool for understanding the topology and dynamics of the Bittensor network’s
decentralized architecture, particularly in relation to neuron interconnectivity and consensus processes.
- async min_allowed_weights(netuid, block=None, block_hash=None, reuse_block=False)#
Returns network MinAllowedWeights hyperparameter.
- Parameters:
- Returns:
- The value of the MinAllowedWeights hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the MinAllowedWeights hyperparameter, or
- Return type:
Optional[int]
- async move_stake(wallet, origin_hotkey, origin_netuid, destination_hotkey, destination_netuid, amount, wait_for_inclusion=True, wait_for_finalization=False)#
Moves stake to a different hotkey and/or subnet.
- Parameters:
wallet (bittensor.wallet) – The wallet to move stake from.
origin_hotkey (str) – The SS58 address of the source hotkey.
origin_netuid (int) – The netuid of the source subnet.
destination_hotkey (str) – The SS58 address of the destination hotkey.
destination_netuid (int) – The netuid of the destination subnet.
amount (Balance) – Amount of stake to move.
wait_for_inclusion (bool) – Waits for the transaction to be included in a block.
wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain.
- Returns:
True if the stake movement was successful.
- Return type:
success (bool)
- async neuron_for_uid(uid, netuid, block=None, block_hash=None, reuse_block=False)#
- Retrieves detailed information about a specific neuron identified by its unique identifier (UID) within a
specified subnet (netuid) of the Bittensor network. This function provides a comprehensive view of a neuron’s attributes, including its stake, rank, and operational status.
- Parameters:
uid (int) – The unique identifier of the neuron.
netuid (int) – The unique identifier of the subnet.
block (Optional[int]) – The blockchain block number for the query.
block_hash (str) – The hash of the blockchain block number for the query.
reuse_block (bool) – Whether to reuse the last-used blockchain block hash.
- Returns:
Detailed information about the neuron if found, a null neuron otherwise
- Return type:
bittensor.core.chain_data.NeuronInfo
- This function is crucial for analyzing individual neurons’ contributions and status within a specific subnet,
offering insights into their roles in the network’s consensus and validation mechanisms.
- async neurons(netuid, block=None, block_hash=None, reuse_block=False)#
Retrieves a list of all neurons within a specified subnet of the Bittensor network. This function provides a snapshot of the subnet’s neuron population, including each neuron’s attributes and
network interactions.
- Parameters:
- Returns:
A list of NeuronInfo objects detailing each neuron’s characteristics in the subnet.
- Return type:
list[bittensor.core.chain_data.NeuronInfo]
- Understanding the distribution and status of neurons within a subnet is key to comprehending the network’s
decentralized structure and the dynamics of its consensus and governance processes.
- async neurons_lite(netuid, block=None, block_hash=None, reuse_block=False)#
Retrieves a list of neurons in a ‘lite’ format from a specific subnet of the Bittensor network. This function provides a streamlined view of the neurons, focusing on key attributes such as stake and network
participation.
- Parameters:
- Returns:
A list of simplified neuron information for the subnet.
- Return type:
list[bittensor.core.chain_data.NeuronInfoLite]
- This function offers a quick overview of the neuron population within a subnet, facilitating efficient analysis
of the network’s decentralized structure and neuron dynamics.
- async query_constant(module_name, constant_name, block=None, block_hash=None, reuse_block=False)#
- Retrieves a constant from the specified module on the Bittensor blockchain. This function is used to access
fixed parameters or values defined within the blockchain’s modules, which are essential for understanding the network’s configuration and rules.
- Parameters:
module_name (str) – The name of the module containing the constant.
constant_name (str) – The name of the constant to retrieve.
block (Optional[int]) – The blockchain block number at which to query the constant. Do not specify if using block_hash or reuse_block
block_hash (Optional[str]) – the hash of th blockchain block at which to query the constant. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to reuse the blockchain block at which to query the constant.
- Returns:
The value of the constant if found, None otherwise.
- Return type:
Optional[async_substrate_interface.types.ScaleObj]
- Constants queried through this function can include critical network parameters such as inflation rates,
consensus rules, or validation thresholds, providing a deeper understanding of the Bittensor network’s operational parameters.
- async query_identity(coldkey_ss58, block=None, block_hash=None, reuse_block=False)#
- Queries the identity of a neuron on the Bittensor blockchain using the given key. This function retrieves
detailed identity information about a specific neuron, which is a crucial aspect of the network’s decentralized identity and governance system.
- Parameters:
coldkey_ss58 (str) – The coldkey used to query the neuron’s identity (technically the neuron’s coldkey SS58 address).
block (Optional[int]) – The blockchain block number for the query.
block_hash (str) – The hash of the blockchain block number at which to perform the query.
reuse_block (bool) – Whether to reuse the last-used blockchain block hash.
- Returns:
An object containing the identity information of the neuron if found,
None
otherwise.- Return type:
- The identity information can include various attributes such as the neuron’s stake, rank, and other
network-specific details, providing insights into the neuron’s role and status within the Bittensor network.
Note
- See the Bittensor CLI documentation for supported identity
parameters.
- async query_map(module, name, block=None, block_hash=None, reuse_block=False, params=None)#
- Queries map storage from any module on the Bittensor blockchain. This function retrieves data structures that
represent key-value mappings, essential for accessing complex and structured data within the blockchain modules.
- Parameters:
module (str) – The name of the module from which to query the map storage.
name (str) – The specific storage function within the module to query.
block (Optional[int]) – The blockchain block number at which to perform the query.
block_hash (Optional[str]) – The hash of the block to retrieve the parameter from. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to use the last-used block. Do not set if using block_hash or block.
params (Optional[list]) – Parameters to be passed to the query.
- Returns:
A data structure representing the map storage if found, None otherwise.
- Return type:
result
- This function is particularly useful for retrieving detailed and structured data from various blockchain
modules, offering insights into the network’s state and the relationships between its different components.
- async query_map_subtensor(name, block=None, block_hash=None, reuse_block=False, params=None)#
- Queries map storage from the Subtensor module on the Bittensor blockchain. This function is designed to retrieve
a map-like data structure, which can include various neuron-specific details or network-wide attributes.
- Parameters:
name (str) – The name of the map storage function to query.
block (Optional[int]) – The blockchain block number at which to perform the query.
block_hash (Optional[str]) – The hash of the block to retrieve the parameter from. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to use the last-used block. Do not set if using block_hash or block.
params (Optional[list]) – A list of parameters to pass to the query function.
- Returns:
An object containing the map-like data structure, or None if not found.
- Return type:
async_substrate_interface.AsyncQueryMapResult
- This function is particularly useful for analyzing and understanding complex network structures and
relationships within the Bittensor ecosystem, such as interneuronal connections and stake distributions.
- async query_module(module, name, block=None, block_hash=None, reuse_block=False, params=None)#
- Queries any module storage on the Bittensor blockchain with the specified parameters and block number. This
function is a generic query interface that allows for flexible and diverse data retrieval from various blockchain modules.
- Parameters:
module (str) – The name of the module from which to query data.
name (str) – The name of the storage function within the module.
block (Optional[int]) – The blockchain block number at which to perform the query.
block_hash (Optional[str]) – The hash of the block to retrieve the parameter from. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to use the last-used block. Do not set if using block_hash or block.
params (Optional[list[object]]) – A list of parameters to pass to the query function.
- Returns:
An object containing the requested data if found, None otherwise.
- Return type:
Optional[Union[async_substrate_interface.types.ScaleObj, Any]]
- This versatile query function is key to accessing a wide range of data and insights from different parts of the
Bittensor blockchain, enhancing the understanding and analysis of the network’s state and dynamics.
- async query_runtime_api(runtime_api, method, params, block=None, block_hash=None, reuse_block=False)#
- Queries the runtime API of the Bittensor blockchain, providing a way to interact with the underlying runtime and
retrieve data encoded in Scale Bytes format. This function is essential for advanced users who need to interact with specific runtime methods and decode complex data types.
- Parameters:
runtime_api (str) – The name of the runtime API to query.
method (str) – The specific method within the runtime API to call.
params (Optional[Union[list[Any], dict[str, Any]]]) – The parameters to pass to the method call.
block (Optional[int]) – the block number for this query. Do not specify if using block_hash or reuse_block
block_hash (Optional[str]) – The hash of the blockchain block number at which to perform the query. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to reuse the last-used block hash. Do not set if using block_hash or block
- Returns:
The decoded result from the runtime API call, or None if the call fails.
- Return type:
Optional[Any]
- This function enables access to the deeper layers of the Bittensor blockchain, allowing for detailed and
specific interactions with the network’s runtime environment.
- async query_subtensor(name, block=None, block_hash=None, reuse_block=False, params=None)#
- Queries named storage from the Subtensor module on the Bittensor blockchain. This function is used to retrieve
specific data or parameters from the blockchain, such as stake, rank, or other neuron-specific attributes.
- Parameters:
name (str) – The name of the storage function to query.
block (Optional[int]) – The blockchain block number at which to perform the query.
block_hash (Optional[str]) – The hash of the block to retrieve the parameter from. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to use the last-used block. Do not set if using block_hash or block.
params (Optional[list]) – A list of parameters to pass to the query function.
- Returns:
An object containing the requested data.
- Return type:
query_response
- This query function is essential for accessing detailed information about the network and its neurons, providing
valuable insights into the state and dynamics of the Bittensor ecosystem.
- async recycle(netuid, block=None, block_hash=None, reuse_block=False)#
- Retrieves the ‘Burn’ hyperparameter for a specified subnet. The ‘Burn’ parameter represents the amount of Tao
that is effectively recycled within the Bittensor network.
- Parameters:
- Returns:
The value of the ‘Burn’ hyperparameter if the subnet exists, None otherwise.
- Return type:
Optional[Balance]
- Understanding the ‘Burn’ rate is essential for analyzing the network registration usage, particularly how it is
correlated with user activity and the overall cost of participation in a given subnet.
- async register(wallet, netuid, wait_for_inclusion=False, wait_for_finalization=True, max_allowed_attempts=3, output_in_place=False, cuda=False, dev_id=0, tpb=256, num_processes=None, update_interval=None, log_verbose=False)#
Registers a neuron on the Bittensor network using the provided wallet.
- Registration is a critical step for a neuron to become an active participant in the network, enabling it to
stake, set weights, and receive incentives.
- Parameters:
wallet (bittensor_wallet.Wallet) – The wallet associated with the neuron to be registered.
netuid (int) – The unique identifier of the subnet.
wait_for_inclusion (bool) – Waits for the transaction to be included in a block. Defaults to False.
wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain. Defaults to True.
max_allowed_attempts (int) – Maximum number of attempts to register the wallet.
output_in_place (bool) – If true, prints the progress of the proof of work to the console in-place. Meaning the progress is printed on the same lines. Defaults to True.
cuda (bool) – If
true
, the wallet should be registered using CUDA device(s). Defaults to False.dev_id (Union[List[int], int]) – The CUDA device id to use, or a list of device ids. Defaults to 0 (zero).
tpb (int) – The number of threads per block (CUDA). Default to 256.
num_processes (Optional[int]) – The number of processes to use to register. Default to None.
update_interval (Optional[int]) – The number of nonces to solve between updates. Default to None.
log_verbose (bool) – If
true
, the registration process will log more information. Default to False.
- Returns:
True
if the registration is successful, False otherwise.- Return type:
This function facilitates the entry of new neurons into the network, supporting the decentralized growth and scalability of the Bittensor ecosystem.
- async register_subnet(wallet, wait_for_inclusion=False, wait_for_finalization=True)#
Registers a new subnetwork on the Bittensor network.
- Parameters:
wallet (bittensor_wallet.Wallet) – The wallet to be used for subnet registration.
wait_for_inclusion (bool) – If set, waits for the extrinsic to enter a block before returning true, or returns false if the extrinsic fails to enter the block within the timeout. Default is False.
wait_for_finalization (bool) – If set, waits for the extrinsic to be finalized on the chain before returning true, or returns false if the extrinsic fails to be finalized within the timeout. Default is True.
- Returns:
True if the subnet registration was successful, False otherwise.
- Return type:
- async reveal_weights(wallet, netuid, uids, weights, salt, version_key=version_as_int, wait_for_inclusion=False, wait_for_finalization=False, max_retries=5)#
Reveals the weights for a specific subnet on the Bittensor blockchain using the provided wallet. This action serves as a revelation of the neuron’s previously committed weight distribution.
- Parameters:
wallet (bittensor_wallet.Wallet) – The wallet associated with the neuron revealing the weights.
netuid (int) – The unique identifier of the subnet.
uids (np.ndarray) – NumPy array of neuron UIDs for which weights are being revealed.
weights (np.ndarray) – NumPy array of weight values corresponding to each UID.
salt (np.ndarray) – NumPy array of salt values corresponding to the hash function.
version_key (int) – Version key for compatibility with the network. Default is
int representation of Bittensor version
.wait_for_inclusion (bool) – Waits for the transaction to be included in a block. Default is
False
.wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain. Default is
False
.max_retries (int) – The number of maximum attempts to reveal weights. Default is
5
.
- Returns:
True
if the weight revelation is successful, False otherwise. And msg, a stringvalue describing the success or potential error.
- Return type:
- This function allows neurons to reveal their previously committed weight distribution, ensuring transparency
and accountability within the Bittensor network.
- async root_register(wallet, block_hash=None, wait_for_inclusion=True, wait_for_finalization=True)#
Register neuron by recycling some TAO.
- Parameters:
wallet (bittensor_wallet.Wallet) – Bittensor wallet instance.
block_hash (Optional[str]) – The hash of the blockchain block for the query.
wait_for_inclusion (bool) – Waits for the transaction to be included in a block. Default is
False
.wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain. Default is
False
.
- Returns:
True if registration was successful, otherwise False.
- Return type:
- async root_set_weights(wallet, netuids, weights, version_key=0, wait_for_inclusion=True, wait_for_finalization=True)#
Set weights for root network.
- Parameters:
wallet (bittensor_wallet.Wallet) – bittensor wallet instance.
version_key (int, optional) – Version key for compatibility with the network. Default is
0
.wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block. Defaults to
False
.wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain. Defaults to
False
.
- Returns:
True if the setting of weights is successful, False otherwise.
- Return type:
- async serve_axon(netuid, axon, wait_for_inclusion=False, wait_for_finalization=True, certificate=None)#
- Registers an
Axon
serving endpoint on the Bittensor network for a specific neuron. This function is used to set up the Axon, a key component of a neuron that handles incoming queries and data processing tasks.
- Parameters:
netuid (int) – The unique identifier of the subnetwork.
axon (bittensor.core.axon.Axon) – The Axon instance to be registered for serving.
wait_for_inclusion (bool) – Waits for the transaction to be included in a block. Default is
False
.wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain. Default is
True
.certificate (bittensor.utils.Certificate) – Certificate to use for TLS. If
None
, no TLS will be used. Defaults toNone
.
- Returns:
True
if the Axon serve registration is successful, False otherwise.- Return type:
- By registering an Axon, the neuron becomes an active part of the network’s distributed computing infrastructure,
contributing to the collective intelligence of Bittensor.
- Registers an
- set_commitment#
- async set_subnet_identity(wallet, netuid, subnet_identity, wait_for_inclusion=False, wait_for_finalization=True)#
Sets the identity of a subnet for a specific wallet and network.
- Parameters:
wallet (Wallet) – The wallet instance that will authorize the transaction.
netuid (int) – The unique ID of the network on which the operation takes place.
subnet_identity (SubnetIdentity) – The identity data of the subnet including attributes like name, GitHub repository, contact, URL, discord, description, and any additional metadata.
wait_for_inclusion (bool) – Indicates if the function should wait for the transaction to be included in the block.
wait_for_finalization (bool) – Indicates if the function should wait for the transaction to reach finalization.
- Returns:
- A tuple where the first element is a boolean indicating success or failure of the
operation, and the second element is a message providing additional information.
- Return type:
- async set_weights(wallet, netuid, uids, weights, version_key=version_as_int, wait_for_inclusion=False, wait_for_finalization=False, max_retries=5)#
- Sets the inter-neuronal weights for the specified neuron. This process involves specifying the influence or
trust a neuron places on other neurons in the network, which is a fundamental aspect of Bittensor’s decentralized learning architecture.
- Parameters:
wallet (bittensor_wallet.Wallet) – The wallet associated with the neuron setting the weights.
netuid (int) – The unique identifier of the subnet.
uids (Union[NDArray[np.int64], torch.LongTensor, list]) – The list of neuron UIDs that the weights are being set for.
weights (Union[NDArray[np.float32], torch.FloatTensor, list]) – The corresponding weights to be set for each UID.
version_key (int) – Version key for compatibility with the network. Default is int representation of Bittensor version.
wait_for_inclusion (bool) – Waits for the transaction to be included in a block. Default is
False
.wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain. Default is
False
.max_retries (int) – The number of maximum attempts to set weights. Default is
5
.
- Returns:
True
if the setting of weights is successful, False otherwise. And msg, a stringvalue describing the success or potential error.
- Return type:
- This function is crucial in shaping the network’s collective intelligence, where each neuron’s learning and
contribution are influenced by the weights it sets towards others【81†source】.
- async sign_and_send_extrinsic(call, wallet, wait_for_inclusion=True, wait_for_finalization=False, sign_with='coldkey')#
Helper method to sign and submit an extrinsic call to chain.
- Parameters:
call (scalecodec.types.GenericCall) – a prepared Call object
wallet (bittensor_wallet.Wallet) – the wallet whose coldkey will be used to sign the extrinsic
wait_for_inclusion (bool) – whether to wait until the extrinsic call is included on the chain
wait_for_finalization (bool) – whether to wait until the extrinsic call is finalized on the chain
sign_with (str) – the wallet’s keypair to use for the signing. Options are “coldkey”, “hotkey”, “coldkeypub”
- Returns:
(success, error message)
- Return type:
- async state_call(method, data, block=None, block_hash=None, reuse_block=False)#
- Makes a state call to the Bittensor blockchain, allowing for direct queries of the blockchain’s state. This
function is typically used for advanced queries that require specific method calls and data inputs.
- Parameters:
method (str) – The method name for the state call.
data (str) – The data to be passed to the method.
block (Optional[int]) – The blockchain block number at which to perform the state call.
block_hash (Optional[str]) – The hash of the block to retrieve the parameter from. Do not specify if using block or reuse_block
reuse_block (bool) – Whether to use the last-used block. Do not set if using block_hash or block.
- Returns:
The result of the rpc call.
- Return type:
result (dict[Any, Any])
- The state call function provides a more direct and flexible way of querying blockchain data, useful for specific
use cases where standard queries are insufficient.
- async subnet(netuid, block=None, block_hash=None, reuse_block=False)#
Retrieves the subnet information for a single subnet in the Bittensor network.
- Parameters:
- Returns:
A DynamicInfo object, containing detailed information about a subnet.
- Return type:
Optional[DynamicInfo]
- async subnet_exists(netuid, block=None, block_hash=None, reuse_block=False)#
Checks if a subnet with the specified unique identifier (netuid) exists within the Bittensor network.
- Parameters:
- Returns:
True if the subnet exists, False otherwise.
- Return type:
This function is critical for verifying the presence of specific subnets in the network, enabling a deeper understanding of the network’s structure and composition.
- async subnetwork_n(netuid, block=None, block_hash=None, reuse_block=False)#
Returns network SubnetworkN hyperparameter.
- Parameters:
- Returns:
- The value of the SubnetworkN hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the SubnetworkN hyperparameter, or
- Return type:
Optional[int]
- substrate#
- async swap_stake(wallet, hotkey_ss58, origin_netuid, destination_netuid, amount, wait_for_inclusion=True, wait_for_finalization=False)#
Moves stake between subnets while keeping the same coldkey-hotkey pair ownership. Like subnet hopping - same owner, same hotkey, just changing which subnet the stake is in.
- Parameters:
wallet (bittensor.wallet) – The wallet to swap stake from.
hotkey_ss58 (str) – The SS58 address of the hotkey whose stake is being swapped.
origin_netuid (int) – The netuid from which stake is removed.
destination_netuid (int) – The netuid to which stake is added.
wait_for_inclusion (bool) – Waits for the transaction to be included in a block.
wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain.
- Returns:
True if the extrinsic was successful.
- Return type:
success (bool)
- async tempo(netuid, block=None, block_hash=None, reuse_block=False)#
Returns network Tempo hyperparameter.
- Parameters:
- Returns:
- The value of the Tempo hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the Tempo hyperparameter, or
- Return type:
Optional[int]
- async transfer(wallet, dest, amount, transfer_all=False, wait_for_inclusion=True, wait_for_finalization=False, keep_alive=True)#
Transfer token of amount to destination.
- Parameters:
wallet (bittensor_wallet.Wallet) – Source wallet for the transfer.
dest (str) – Destination address for the transfer.
amount (float) – Amount of tokens to transfer.
transfer_all (bool) – Flag to transfer all tokens. Default is
False
.wait_for_inclusion (bool) – Waits for the transaction to be included in a block. Default is
True
.wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain. Default is
False
.keep_alive (bool) – Flag to keep the connection alive. Default is
True
.
- Returns:
True if the transferring was successful, otherwise False.
- Return type:
- async transfer_stake(wallet, destination_coldkey_ss58, hotkey_ss58, origin_netuid, destination_netuid, amount, wait_for_inclusion=True, wait_for_finalization=False)#
Transfers stake from one subnet to another while changing the coldkey owner.
- Parameters:
wallet (bittensor.wallet) – The wallet to transfer stake from.
destination_coldkey_ss58 (str) – The destination coldkey SS58 address.
hotkey_ss58 (str) – The hotkey SS58 address associated with the stake.
origin_netuid (int) – The source subnet UID.
destination_netuid (int) – The destination subnet UID.
amount (Balance) – Amount to transfer.
wait_for_inclusion (bool) – If true, waits for inclusion before returning.
wait_for_finalization (bool) – If true, waits for finalization before returning.
- Returns:
True if the transfer was successful.
- Return type:
success (bool)
- async tx_rate_limit(block=None, block_hash=None, reuse_block=False)#
Retrieves the transaction rate limit for the Bittensor network as of a specific blockchain block. This rate limit sets the maximum number of transactions that can be processed within a given time frame.
- Parameters:
- Returns:
The transaction rate limit of the network, None if not available.
- Return type:
Optional[int]
- The transaction rate limit is an essential parameter for ensuring the stability and scalability of the Bittensor
network. It helps in managing network load and preventing congestion, thereby maintaining efficient and timely transaction processing.
- async unstake(wallet, hotkey_ss58=None, netuid=None, amount=None, wait_for_inclusion=True, wait_for_finalization=False)#
- Removes a specified amount of stake from a single hotkey account. This function is critical for adjusting
individual neuron stakes within the Bittensor network.
- Parameters:
wallet (bittensor_wallet.wallet) – The wallet associated with the neuron from which the stake is being removed.
hotkey_ss58 (Optional[str]) – The
SS58
address of the hotkey account to unstake from.netuid (Optional[int]) – Subnet unique ID.
amount (Balance) – The amount of TAO to unstake. If not specified, unstakes all.
wait_for_inclusion (bool) – Waits for the transaction to be included in a block.
wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain.
- Returns:
True
if the unstaking process is successful, False otherwise.- Return type:
- This function supports flexible stake management, allowing neurons to adjust their network participation and
potential reward accruals.
- async unstake_multiple(wallet, hotkey_ss58s, netuids, amounts=None, wait_for_inclusion=True, wait_for_finalization=False)#
- Performs batch unstaking from multiple hotkey accounts, allowing a neuron to reduce its staked amounts
efficiently. This function is useful for managing the distribution of stakes across multiple neurons.
- Parameters:
wallet (bittensor_wallet.Wallet) – The wallet linked to the coldkey from which the stakes are being withdrawn.
hotkey_ss58s (List[str]) – A list of hotkey
SS58
addresses to unstake from.amounts (List[Union[Balance, float]]) – The amounts of TAO to unstake from each hotkey. If not provided, unstakes all available stakes.
wait_for_inclusion (bool) – Waits for the transaction to be included in a block.
wait_for_finalization (bool) – Waits for the transaction to be finalized on the blockchain.
- Returns:
True
if the batch unstaking is successful, False otherwise.- Return type:
- This function allows for strategic reallocation or withdrawal of stakes, aligning with the dynamic stake
management aspect of the Bittensor network.
- async wait_for_block(block=None)#
Waits until a specific block is reached on the chain. If no block is specified, waits for the next block.
- Parameters:
block (Optional[int]) – The block number to wait for. If None, waits for next block.
- Returns:
True if the target block was reached, False if timeout occurred.
- Return type:
Example
await subtensor.wait_for_block() # Waits for next block await subtensor.wait_for_block(block=1234) # Waits for specific block
- async weights(netuid, block=None, block_hash=None, reuse_block=False)#
Retrieves the weight distribution set by neurons within a specific subnet of the Bittensor network. This function maps each neuron’s UID to the weights it assigns to other neurons, reflecting the network’s trust
and value assignment mechanisms.
- Parameters:
- Returns:
A list of tuples mapping each neuron’s UID to its assigned weights.
- Return type:
- The weight distribution is a key factor in the network’s consensus algorithm and the ranking of neurons,
influencing their influence and reward allocation within the subnet.
- async weights_rate_limit(netuid, block=None, block_hash=None, reuse_block=False)#
Returns network WeightsSetRateLimit hyperparameter.
- Parameters:
- Returns:
- The value of the WeightsSetRateLimit hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the WeightsSetRateLimit hyperparameter, or
- Return type:
Optional[int]
- async bittensor.core.async_subtensor.get_async_subtensor(network=None, config=None, _mock=False, log_verbose=False)#
Factory method to create an initialized AsyncSubtensor. Mainly useful for when you don’t want to run await subtensor.initialize() after instantiation.
- Parameters:
network (Optional[str])
config (Optional[bittensor.core.config.Config])
_mock (bool)
log_verbose (bool)
- Return type: