bittensor.subtensor#
The bittensor.subtensor
module in Bittensor serves as a crucial interface for interacting with the Bittensor
blockchain, facilitating a range of operations essential for the decentralized machine learning network.
Attributes#
Classes#
dict() -> new empty dictionary |
|
The Subtensor class in Bittensor serves as a crucial interface for interacting with the Bittensor blockchain, |
Module Contents#
- class bittensor.subtensor.ParamWithTypes[source]#
Bases:
TypedDict
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s
(key, value) pairs
- dict(iterable) -> new dictionary initialized as if via:
d = {} for k, v in iterable:
d[k] = v
- dict(**kwargs) -> new dictionary initialized with the name=value pairs
in the keyword argument list. For example: dict(one=1, two=2)
Initialize self. See help(type(self)) for accurate signature.
- class bittensor.subtensor.Subtensor(network=None, config=None, _mock=False, log_verbose=True, connection_timeout=600)[source]#
The Subtensor class in Bittensor serves as a crucial interface for interacting with the Bittensor blockchain, facilitating a range of operations essential for the decentralized machine learning network.
This class enables neurons (network participants) to engage in activities such as registering on the network, managing staked weights, setting inter-neuronal weights, and participating in consensus mechanisms.
The Bittensor network operates on a digital ledger where each neuron holds stakes (S) and learns a set of inter-peer weights (W). These weights, set by the neurons themselves, play a critical role in determining the ranking and incentive mechanisms within the network. Higher-ranked neurons, as determined by their contributions and trust within the network, receive more incentives.
The Subtensor class connects to various Bittensor networks like the main
finney
network or local test networks, providing a gateway to the blockchain layer of Bittensor. It leverages a staked weighted trust system and consensus to ensure fair and distributed incentive mechanisms, where incentives (I) are primarily allocated to neurons that are trusted by the majority of the network.Additionally, Bittensor introduces a speculation-based reward mechanism in the form of bonds (B), allowing neurons to accumulate bonds in other neurons, speculating on their future value. This mechanism aligns with market-based speculation, incentivizing neurons to make judicious decisions in their inter-neuronal investments.
Example Usage:
# Connect to the main Bittensor network (Finney). finney_subtensor = subtensor(network='finney') # Close websocket connection with the Bittensor network. finney_subtensor.close() # (Re)creates the websocket connection with the Bittensor network. finney_subtensor.connect_websocket() # Register a new neuron on the network. wallet = bittensor.wallet(...) # Assuming a wallet instance is created. success = finney_subtensor.register(wallet=wallet, netuid=netuid) # Set inter-neuronal weights for collaborative learning. success = finney_subtensor.set_weights(wallet=wallet, netuid=netuid, uids=[...], weights=[...]) # Speculate by accumulating bonds in other promising neurons. success = finney_subtensor.delegate(wallet=wallet, delegate_ss58=other_neuron_ss58, amount=bond_amount) # Get the metagraph for a specific subnet using given subtensor connection metagraph = subtensor.metagraph(netuid=netuid)
By facilitating these operations, the Subtensor class is instrumental in maintaining the decentralized intelligence and dynamic learning environment of the Bittensor network, as envisioned in its foundational principles and mechanisms described in the NeurIPS paper. paper.
Initializes a Subtensor interface for interacting with the Bittensor blockchain.
Note
Currently subtensor defaults to the
finney
network. This will change in a future release.We strongly encourage users to run their own local subtensor node whenever possible. This increases decentralization and resilience of the network. In a future release, local subtensor will become the default and the fallback to
finney
removed. Please plan ahead for this change. We will provide detailed instructions on how to run a local subtensor node in the documentation in a subsequent release.- Parameters:
network (str, optional) – The network name to connect to (e.g.,
finney
,local
). This can also be the chain endpoint (e.g.,wss://entrypoint-finney.opentensor.ai:443
) and will be correctly parsed into the network and chain endpoint. If not specified, defaults to the main Bittensor network.config (bittensor.config, optional) – Configuration object for the subtensor. If not provided, a default configuration is used.
_mock (bool, optional) – If set to
True
, uses a mocked connection for testing purposes.log_verbose (bool)
connection_timeout (int)
This initialization sets up the connection to the specified Bittensor network, allowing for various blockchain operations such as neuron registration, stake management, and setting weights.
- log_verbose#
- _connection_timeout#
- _get_substrate()[source]#
Establishes a connection to the Substrate node using configured parameters.
- classmethod add_args(parser, prefix=None)[source]#
Adds command-line arguments to the provided ArgumentParser for configuring the Subtensor settings.
- Parameters:
parser (argparse.ArgumentParser) – The ArgumentParser object to which the Subtensor arguments will be added.
prefix (Optional[str]) – An optional prefix for the argument names. If provided, the prefix is prepended to each argument name.
- Arguments added:
- –subtensor.network: The Subtensor network flag. Possible values are ‘finney’, ‘test’, ‘archive’, and
‘local’. Overrides the chain endpoint if set.
–subtensor.chain_endpoint: The Subtensor chain endpoint flag. If set, it overrides the network flag. –subtensor._mock: If true, uses a mocked connection to the chain.
Example
parser = argparse.ArgumentParser() Subtensor.add_args(parser)
- static determine_chain_endpoint_and_network(network)[source]#
Determines the chain endpoint and network from the passed network or chain_endpoint.
- Parameters:
network (str) – The network flag. The choices are:
-- finney
(main network),-- archive
(archive network +300 blocks),-- local
(local running network),-- test
(test network).- Returns:
The network flag. chain_endpoint (str): The chain endpoint flag. If set, overrides the
network
argument.- Return type:
network (str)
- static setup_config(network, config)[source]#
Sets up and returns the configuration for the Subtensor network and endpoint.
This method determines the appropriate network and chain endpoint based on the provided network string or configuration object. It evaluates the network and endpoint in the following order of precedence: 1. Provided network string. 2. Configured chain endpoint in the config object. 3. Configured network in the config object. 4. Default chain endpoint. 5. Default network.
- Parameters:
network (str) – The name of the Subtensor network. If None, the network and endpoint will be determined from the config object.
config (bittensor.config) – The configuration object containing the network and chain endpoint settings.
- Returns:
A tuple containing the formatted WebSocket endpoint URL and the evaluated network name.
- Return type:
- close()[source]#
Cleans up resources for this subtensor instance like active websocket connection and active extensions.
- nominate(wallet, wait_for_finalization=False, wait_for_inclusion=True)[source]#
Becomes a delegate for the hotkey associated with the given wallet. This method is used to nominate a neuron (identified by the hotkey in the wallet) as a delegate on the Bittensor network, allowing it to participate in consensus and validation processes.
- Parameters:
- Returns:
True
if the nomination process is successful,False
otherwise.- Return type:
This function is a key part of the decentralized governance mechanism of Bittensor, allowing for the dynamic selection and participation of validators in the network’s consensus process.
- delegate(wallet, delegate_ss58=None, amount=None, wait_for_inclusion=True, wait_for_finalization=False, prompt=False)[source]#
Becomes a delegate for the hotkey associated with the given wallet. This method is used to nominate a neuron (identified by the hotkey in the wallet) as a delegate on the Bittensor network, allowing it to participate in consensus and validation processes.
- Parameters:
wallet (bittensor.wallet) – The wallet containing the hotkey to be nominated.
delegate_ss58 (Optional[str]) – The
SS58
address of the delegate neuron.amount (Union[Balance, float]) – The amount of TAO to undelegate.
wait_for_finalization (bool, optional) – If
True
, waits until the transaction is finalized on the blockchain.wait_for_inclusion (bool, optional) – If
True
, waits until the transaction is included in a block.prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- Returns:
True
if the nomination process is successful, False otherwise.- Return type:
This function is a key part of the decentralized governance mechanism of Bittensor, allowing for the dynamic selection and participation of validators in the network’s consensus process.
- undelegate(wallet, delegate_ss58=None, amount=None, wait_for_inclusion=True, wait_for_finalization=False, prompt=False)[source]#
Removes a specified amount of stake from a delegate neuron using the provided wallet. This action reduces the staked amount on another neuron, effectively withdrawing support or speculation.
- Parameters:
wallet (bittensor.wallet) – The wallet used for the undelegation process.
delegate_ss58 (Optional[str]) – The
SS58
address of the delegate neuron.amount (Union[Balance, float]) – The amount of TAO to undelegate.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- Returns:
True
if the undelegation is successful, False otherwise.- Return type:
This function reflects the dynamic and speculative nature of the Bittensor network, allowing neurons to adjust their stakes and investments based on changing perceptions and performances within the network.
- set_take(wallet, delegate_ss58=None, take=0.0, wait_for_inclusion=True, wait_for_finalization=False)[source]#
Set delegate hotkey take :param wallet: The wallet containing the hotkey to be nominated. :type wallet: bittensor.wallet :param delegate_ss58: Hotkey :type delegate_ss58: str, optional :param take: Delegate take on subnet ID :type take: float :param wait_for_finalization: If
True
, waits until the transaction is finalized on theblockchain.
- Parameters:
- Returns:
True
if the process is successful, False otherwise.- Return type:
This function is a key part of the decentralized governance mechanism of Bittensor, allowing for the dynamic selection and participation of validators in the network’s consensus process.
- send_extrinsic(wallet, module, function, params, period=5, wait_for_inclusion=False, wait_for_finalization=False, max_retries=3, wait_time=3, max_wait=20)[source]#
Sends an extrinsic to the Bittensor blockchain using the provided wallet and parameters. This method constructs and submits the extrinsic, handling retries and blockchain communication.
- Parameters:
wallet (bittensor.wallet) – The wallet associated with the extrinsic.
module (str) – The module name for the extrinsic.
function (str) – The function name for the extrinsic.
params (dict) – The parameters for the extrinsic.
period (int, optional) – The number of blocks for the extrinsic to live in the mempool. Defaults to 5.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
max_retries (int, optional) – The maximum number of retries for the extrinsic. Defaults to 3.
wait_time (int, optional) – The wait time between retries. Defaults to 3.
max_wait (int, optional) – The maximum wait time for the extrinsic. Defaults to 20.
- Returns:
The receipt of the extrinsic if successful, None otherwise.
- Return type:
Optional[ExtrinsicReceipt]
- set_weights(wallet, netuid, uids, weights, version_key=bittensor.__version_as_int__, wait_for_inclusion=False, wait_for_finalization=False, prompt=False, max_retries=5)[source]#
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) – 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, optional) – Version key for compatibility with the network.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.max_retries (int, optional) – The number of maximum attempts to set weights. (Default: 5)
- Returns:
True
if the setting of weights is successful, False otherwise. And msg, a string value 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】.
- _do_set_weights(wallet, uids, vals, netuid, version_key=bittensor.__version_as_int__, wait_for_inclusion=False, wait_for_finalization=False)[source]#
Internal method to send a transaction to the Bittensor blockchain, setting weights for specified neurons. This method constructs and submits the transaction, handling retries and blockchain communication.
- Parameters:
wallet (bittensor.wallet) – The wallet associated with the neuron setting the weights.
uids (List[int]) – List of neuron UIDs for which weights are being set.
vals (List[int]) – List of weight values corresponding to each UID.
netuid (int) – Unique identifier for the network.
version_key (int, optional) – Version key for compatibility with the network.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
- Returns:
A tuple containing a success flag and an optional error message.
- Return type:
This method is vital for the dynamic weighting mechanism in Bittensor, where neurons adjust their trust in other neurons based on observed performance and contributions.
- commit_weights(wallet, netuid, salt, uids, weights, version_key=bittensor.__version_as_int__, wait_for_inclusion=False, wait_for_finalization=False, prompt=False, max_retries=5)[source]#
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) – 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, optional) – Version key for compatibility with the network.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.max_retries (int, optional) – The number of maximum attempts to commit weights. (Default: 5)
- Returns:
True
if the weight commitment is successful, False otherwise. And msg, a string value 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.
- _do_commit_weights(wallet, netuid, commit_hash, wait_for_inclusion=False, wait_for_finalization=False)[source]#
Internal method to send a transaction to the Bittensor blockchain, committing the hash of a neuron’s weights. This method constructs and submits the transaction, handling retries and blockchain communication.
- Parameters:
wallet (bittensor.wallet) – The wallet associated with the neuron committing the weights.
netuid (int) – The unique identifier of the subnet.
commit_hash (str) – The hash of the neuron’s weights to be committed.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
- Returns:
A tuple containing a success flag and an optional error message.
- Return type:
This method ensures that the weight commitment is securely recorded on the Bittensor blockchain, providing a verifiable record of the neuron’s weight distribution at a specific point in time.
- reveal_weights(wallet, netuid, uids, weights, salt, version_key=bittensor.__version_as_int__, wait_for_inclusion=False, wait_for_finalization=False, prompt=False, max_retries=5)[source]#
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) – 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, optional) – Version key for compatibility with the network.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.max_retries (int, optional) – The number of maximum attempts to reveal weights. (Default: 5)
- Returns:
True
if the weight revelation is successful, False otherwise. And msg, a string value 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.
- _do_reveal_weights(wallet, netuid, uids, values, salt, version_key, wait_for_inclusion=False, wait_for_finalization=False)[source]#
Internal method to send a transaction to the Bittensor blockchain, revealing the weights for a specific subnet. This method constructs and submits the transaction, handling retries and blockchain communication.
- Parameters:
wallet (bittensor.wallet) – The wallet associated with the neuron revealing the weights.
netuid (int) – The unique identifier of the subnet.
uids (List[int]) – List of neuron UIDs for which weights are being revealed.
values (List[int]) – List of weight values corresponding to each UID.
salt (List[int]) – List of salt values corresponding to the hash function.
version_key (int) – Version key for compatibility with the network.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
- Returns:
A tuple containing a success flag and an optional error message.
- Return type:
This method ensures that the weight revelation is securely recorded on the Bittensor blockchain, providing transparency and accountability for the neuron’s weight distribution.
- register(wallet, netuid, wait_for_inclusion=False, wait_for_finalization=True, prompt=False, max_allowed_attempts=3, output_in_place=True, cuda=False, dev_id=0, tpb=256, num_processes=None, update_interval=None, log_verbose=False)[source]#
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) – 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.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.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.
- swap_hotkey(wallet, new_wallet, wait_for_inclusion=False, wait_for_finalization=True, prompt=False)[source]#
Swaps an old hotkey with a new hotkey for the specified wallet.
This method initiates an extrinsic to change the hotkey associated with a wallet to a new hotkey. It provides options to wait for inclusion and finalization of the transaction, and to prompt the user for confirmation.
- Parameters:
wallet (bittensor.wallet) – The wallet whose hotkey is to be swapped.
new_wallet (bittensor.wallet) – The new wallet with the hotkey to be set.
wait_for_inclusion (bool) – Whether to wait for the transaction to be included in a block. Default is False.
wait_for_finalization (bool) – Whether to wait for the transaction to be finalized. Default is True.
prompt (bool) – Whether to prompt the user for confirmation before proceeding. Default is False.
- Returns:
True if the hotkey swap was successful, False otherwise.
- Return type:
- run_faucet(wallet, wait_for_inclusion=False, wait_for_finalization=True, prompt=False, max_allowed_attempts=3, output_in_place=True, cuda=False, dev_id=0, tpb=256, num_processes=None, update_interval=None, log_verbose=False)[source]#
Facilitates a faucet transaction, allowing new neurons to receive an initial amount of TAO for participating in the network. This function is particularly useful for newcomers to the Bittensor network, enabling them to start with a small stake on testnet only.
- Parameters:
wallet (bittensor.wallet) – The wallet for which the faucet transaction is to be run.
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.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.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 faucet transaction is successful, False otherwise.- Return type:
This function is part of Bittensor’s onboarding process, ensuring that new neurons have the necessary resources to begin their journey in the decentralized AI network.
Note
This is for testnet ONLY and is disabled currently. You must build your own staging subtensor chain with the
--features pow-faucet
argument to enable this.
- burned_register(wallet, netuid, wait_for_inclusion=False, wait_for_finalization=True, prompt=False)[source]#
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) – 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.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding. Defaults to False.
- Returns:
True
if the registration is successful, False otherwise.- Return type:
- _do_pow_register(netuid, wallet, pow_result, wait_for_inclusion=False, wait_for_finalization=True)[source]#
Sends a (POW) register extrinsic to the chain.
- Parameters:
netuid (int) – The subnet to register on.
wallet (bittensor.wallet) – The wallet to register.
pow_result (POWSolution) – The PoW result to register.
wait_for_inclusion (bool) – If
True
, waits for the extrinsic to be included in a block. Default to False.wait_for_finalization (bool) – If
True
, waits for the extrinsic to be finalized. Default to True.
- Returns:
True
if the extrinsic was included in a block. error (Optional[str]):None
on success or not waiting for inclusion/finalization, otherwise the errormessage.
- Return type:
success (bool)
- _do_burned_register(netuid, wallet, wait_for_inclusion=False, wait_for_finalization=True)[source]#
Performs a burned register extrinsic call to the Subtensor chain.
This method sends a registration transaction to the Subtensor blockchain using the burned register mechanism. It retries the call up to three times with exponential backoff in case of failures.
- Parameters:
netuid (int) – The network unique identifier to register on.
wallet (bittensor.wallet) – The wallet to be registered.
wait_for_inclusion (bool) – Whether to wait for the transaction to be included in a block. Default is False.
wait_for_finalization (bool) – Whether to wait for the transaction to be finalized. Default is True.
- Returns:
A tuple containing a boolean indicating success or failure, and an optional error message.
- Return type:
- _do_swap_hotkey(wallet, new_wallet, wait_for_inclusion=False, wait_for_finalization=True)[source]#
Performs a hotkey swap extrinsic call to the Subtensor chain.
- Parameters:
wallet (bittensor.wallet) – The wallet whose hotkey is to be swapped.
new_wallet (bittensor.wallet) – The wallet with the new hotkey to be set.
wait_for_inclusion (bool) – Whether to wait for the transaction to be included in a block. Default is
False.
wait_for_finalization (bool) – Whether to wait for the transaction to be finalized. Default is True.
- Returns:
- A tuple containing a boolean indicating success or failure, and an optional
error message.
- Return type:
- transfer(wallet, dest, amount, wait_for_inclusion=True, wait_for_finalization=False, prompt=False)[source]#
Executes a transfer of funds from the provided wallet to the specified destination address. This function is used to move TAO tokens within the Bittensor network, facilitating transactions between neurons.
- Parameters:
wallet (bittensor.wallet) – The wallet from which funds are being transferred.
dest (str) – The destination public key address.
amount (Union[Balance, float]) – The amount of TAO to be transferred.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- Returns:
True
if the transfer is successful, False otherwise.- Return type:
transfer_extrinsic (bool)
This function is essential for the fluid movement of tokens in the network, supporting various economic activities such as staking, delegation, and reward distribution.
- get_transfer_fee(wallet, dest, value)[source]#
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:
- 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.
- _do_transfer(wallet, dest, transfer_balance, wait_for_inclusion=True, wait_for_finalization=False)[source]#
Sends a transfer extrinsic to the chain.
- Parameters:
wallet (
bittensor.wallet()
) – Wallet object.dest (str) – Destination public key address.
transfer_balance (
Balance()
) – Amount to transfer.wait_for_inclusion (bool) – If
true
, waits for inclusion.wait_for_finalization (bool) – If
true
, waits for finalization.
- Returns:
True
if transfer was successful. block_hash (str): Block hash of the transfer. On success and if wait_for_ finalization/inclusion isTrue
.error (str): Error message if transfer failed.
- Return type:
success (bool)
- get_existential_deposit(block=None)[source]#
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:
block (Optional[int]) – Block number at which to query the deposit amount. If
None
, the current block is used.- Returns:
The existential deposit amount, or
None
if the query fails.- Return type:
Optional[Balance]
The existential deposit is a fundamental economic parameter in the Bittensor network, ensuring efficient use of storage and preventing the proliferation of dust accounts.
- register_subnetwork(wallet, wait_for_inclusion=False, wait_for_finalization=True, prompt=False)[source]#
Registers a new subnetwork on the Bittensor network using the provided wallet. This function is used for the creation and registration of subnetworks, which are specialized segments of the overall Bittensor network.
- Parameters:
wallet (bittensor.wallet) – The wallet to be used for registration.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- Returns:
True
if the subnetwork registration is successful, False otherwise.- Return type:
This function allows for the expansion and diversification of the Bittensor network, supporting its decentralized and adaptable architecture.
- set_hyperparameter(wallet, netuid, parameter, value, wait_for_inclusion=False, wait_for_finalization=True, prompt=False)[source]#
Sets a specific hyperparameter for a given subnetwork on the Bittensor blockchain. This action involves adjusting network-level parameters, influencing the behavior and characteristics of the subnetwork.
- Parameters:
wallet (bittensor.wallet) – The wallet used for setting the hyperparameter.
netuid (int) – The unique identifier of the subnetwork.
parameter (str) – The name of the hyperparameter to be set.
value – The new value for the hyperparameter.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- Returns:
True
if the hyperparameter setting is successful, False otherwise.- Return type:
This function plays a critical role in the dynamic governance and adaptability of the Bittensor network, allowing for fine-tuning of network operations and characteristics.
- serve(wallet, ip, port, protocol, netuid, placeholder1=0, placeholder2=0, wait_for_inclusion=False, wait_for_finalization=True)[source]#
Registers a neuron’s serving endpoint on the Bittensor network. This function announces the IP address and port where the neuron is available to serve requests, facilitating peer-to-peer communication within the network.
- Parameters:
wallet (bittensor.wallet) – The wallet associated with the neuron being served.
ip (str) – The IP address of the serving neuron.
port (int) – The port number on which the neuron is serving.
protocol (int) – The protocol type used by the neuron (e.g., GRPC, HTTP).
netuid (int) – The unique identifier of the subnetwork.
placeholder1 (int, optional) – Placeholder parameter for future extensions. Default is
0
.placeholder2 (int, optional) – Placeholder parameter for future extensions. Default is
0
.wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block. Default is
False
.wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain. Default is
True
.
- Returns:
True
if the serve registration is successful, False otherwise.- Return type:
This function is essential for establishing the neuron’s presence in the network, enabling it to participate in the decentralized machine learning processes of Bittensor.
- serve_axon(netuid, axon, wait_for_inclusion=False, wait_for_finalization=True)[source]#
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.Axon) – The Axon instance to be registered for serving.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
- 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.
- _do_serve_axon(wallet, call_params, wait_for_inclusion=False, wait_for_finalization=True)[source]#
Internal method to submit a serve axon transaction to the Bittensor blockchain. This method creates and submits a transaction, enabling a neuron’s Axon to serve requests on the network.
- Parameters:
wallet (bittensor.wallet) – The wallet associated with the neuron.
call_params (AxonServeCallParams) – Parameters required for the serve axon call.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
- Returns:
A tuple containing a success flag and an optional error message.
- Return type:
This function is crucial for initializing and announcing a neuron’s Axon service on the network, enhancing the decentralized computation capabilities of Bittensor.
- serve_prometheus(wallet, port, netuid, wait_for_inclusion=False, wait_for_finalization=True)[source]#
- _do_serve_prometheus(wallet, call_params, wait_for_inclusion=False, wait_for_finalization=True)[source]#
Sends a serve prometheus extrinsic to the chain. :param wallet: Wallet object. :type wallet:
bittensor.wallet()
:param call_params: Prometheus serve call parameters. :type call_params:PrometheusServeCallParams()
:param wait_for_inclusion: Iftrue
, waits for inclusion. :type wait_for_inclusion: bool :param wait_for_finalization: Iftrue
, waits for finalization. :type wait_for_finalization: bool- Returns:
True
if serve prometheus was successful. error (Optional[str]()
): Error message if serve prometheus failed,None
otherwise.- Return type:
success (bool)
- Parameters:
wallet (bittensor.wallet)
call_params (bittensor.types.PrometheusServeCallParams)
wait_for_inclusion (bool)
wait_for_finalization (bool)
- _do_associate_ips(wallet, ip_info_list, netuid, wait_for_inclusion=False, wait_for_finalization=True)[source]#
Sends an associate IPs extrinsic to the chain.
- Parameters:
wallet (
bittensor.wallet()
) – Wallet object.ip_info_list (
List[IPInfo]()
) – List of IPInfo objects.netuid (int) – Netuid to associate IPs to.
wait_for_inclusion (bool) – If
true
, waits for inclusion.wait_for_finalization (bool) – If
true
, waits for finalization.
- Returns:
True
if associate IPs was successful. error (Optional[str]()
): Error message if associate IPs failed, None otherwise.- Return type:
success (bool)
- add_stake(wallet, hotkey_ss58=None, amount=None, wait_for_inclusion=True, wait_for_finalization=False, prompt=False)[source]#
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 earn incentives.- Parameters:
wallet (bittensor.wallet) – The wallet to be used for staking.
hotkey_ss58 (Optional[str]) – The
SS58
address of the hotkey associated with the neuron.amount (Union[Balance, float]) – The amount of TAO to stake.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- 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.
- add_stake_multiple(wallet, hotkey_ss58s, amounts=None, wait_for_inclusion=True, wait_for_finalization=False, prompt=False)[source]#
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) – The wallet used for staking.
hotkey_ss58s (List[str]) – List of
SS58
addresses of hotkeys to stake to.amounts (List[Union[Balance, float]], optional) – Corresponding amounts of TAO to stake for each hotkey.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- 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.
- _do_stake(wallet, hotkey_ss58, amount, wait_for_inclusion=True, wait_for_finalization=False)[source]#
Sends a stake extrinsic to the chain.
- Parameters:
wallet (
bittensor.wallet()
) – Wallet object that can sign the extrinsic.hotkey_ss58 (str) – Hotkey
ss58
address to stake to.amount (
Balance()
) – Amount to stake.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 extrinsic was successful.- Return type:
success (bool)
- Raises:
StakeError – If the extrinsic failed.
- unstake_multiple(wallet, hotkey_ss58s, amounts=None, wait_for_inclusion=True, wait_for_finalization=False, prompt=False)[source]#
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) – 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]], optional) – The amounts of TAO to unstake from each hotkey. If not provided, unstakes all available stakes.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- 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.
- unstake(wallet, hotkey_ss58=None, amount=None, wait_for_inclusion=True, wait_for_finalization=False, prompt=False)[source]#
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) – 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.amount (Union[Balance, float], optional) – The amount of TAO to unstake. If not specified, unstakes all.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- 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.
- _do_unstake(wallet, hotkey_ss58, amount, wait_for_inclusion=True, wait_for_finalization=False)[source]#
Sends an unstake extrinsic to the chain.
- Parameters:
wallet (
bittensor.wallet()
) – Wallet object that can sign the extrinsic.hotkey_ss58 (str) – Hotkey
ss58
address to unstake from.amount (
Balance()
) – Amount to unstake.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 extrinsic was successful.- Return type:
success (bool)
- Raises:
StakeError – If the extrinsic failed.
- set_childkey_take(wallet, hotkey, take, netuid, wait_for_inclusion=True, wait_for_finalization=False, prompt=False)[source]#
Sets a childkey take extrinsic on the subnet.
- Parameters:
wallet (
bittensor.wallet()
) – Wallet object that can sign the extrinsic.hotkey (str) – (str): Hotkey
ss58
address of the child for which take is getting set.netuid (int) – Unique identifier of for the subnet.
take (float) – Value of childhotkey take on subnet.
wait_for_inclusion (bool) – If
true
, waits for inclusion before returning.wait_for_finalization (bool) – If
true
, waits for finalization before returning.prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- Returns:
True
if the extrinsic was successful.- Return type:
success (bool)
- Raises:
ChildHotkeyError – If the extrinsic failed.
- _do_set_childkey_take(wallet, hotkey, take, netuid, wait_for_inclusion=True, wait_for_finalization=False)[source]#
Sends a set_children hotkey extrinsic on the chain.
- Parameters:
wallet (
bittensor.wallet()
) – Wallet object that can sign the extrinsic.hotkey (str) – (str): Hotkey
ss58
address of the wallet for which take is getting set.take (int) – (int): The take that this ss58 hotkey will have if assigned as a child hotkey as u16 value.
netuid (int) – Unique identifier for the network.
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 extrinsic was successful.- Return type:
success (bool)
- set_children(wallet, hotkey, children_with_proportions, netuid, wait_for_inclusion=True, wait_for_finalization=False, prompt=False)[source]#
Sets a children hotkeys extrinsic on the subnet.
- Parameters:
wallet (
bittensor.wallet()
) – Wallet object that can sign the extrinsic.hotkey (str) – (str): Hotkey
ss58
address of the parent.netuid (int) – Unique identifier of for the subnet.
children_with_proportions (List[Tuple[float, str]]) – List of (proportion, child_ss58) pairs.
wait_for_inclusion (bool) – If
true
, waits for inclusion before returning.wait_for_finalization (bool) – If
true
, waits for finalization before returning.prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- Returns:
True
if the extrinsic was successful.- Return type:
success (bool)
- Raises:
ChildHotkeyError – If the extrinsic failed.
- _do_set_children(wallet, hotkey, children, netuid, wait_for_inclusion=True, wait_for_finalization=False)[source]#
Sends a set_children hotkey extrinsic on the chain.
- Parameters:
wallet (
bittensor.wallet()
) – Wallet object that can sign the extrinsic.hotkey (str) – (str): Hotkey
ss58
address of the parent.children (List[Tuple[int, str]]) – (List[Tuple[int, str]]): A list of tuples containing the hotkey
ss58
addresses of the children and their proportions as u16 MAX standardized values.netuid (int) – Unique identifier for the network.
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 extrinsic was successful.- Return type:
success (bool)
- check_in_arbitration(ss58_address)[source]#
Checks storage function to see if the provided coldkey is in arbitration. If 0, swap has not been called on this key. If 1, swap has been called once, so the key is not in arbitration. If >1, swap has been called with multiple destinations, and the key is thus in arbitration.
- get_remaining_arbitration_period(coldkey_ss58, block=None)[source]#
Retrieves the remaining arbitration period for a given coldkey. :param coldkey_ss58: The SS58 address of the coldkey. :type coldkey_ss58: str :param block: The block number to query. If None, uses the latest block. :type block: Optional[int], optional
- register_senate(wallet, wait_for_inclusion=True, wait_for_finalization=False, prompt=False)[source]#
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) – The wallet associated with the neuron from which the stake is being removed.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- 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.
- leave_senate(wallet, wait_for_inclusion=True, wait_for_finalization=False, prompt=False)[source]#
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) – The wallet associated with the neuron from which the stake is being removed.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- 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.
- vote_senate(wallet, proposal_hash, proposal_idx, vote, wait_for_inclusion=True, wait_for_finalization=False, prompt=False)[source]#
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) – The wallet associated with the neuron from which the stake is being removed.
proposal_hash (str) – The hash of the proposal being voted on.
proposal_idx (int) – The index of the proposal being voted on.
vote (bool) – The vote to be cast (True for yes, False for no).
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- 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.
- is_senate_member(hotkey_ss58, block=None)[source]#
Checks if a given neuron (identified by its hotkey SS58 address) is a member of the Bittensor senate. The senate is a key governance body within the Bittensor network, responsible for overseeing and approving various network operations and proposals.
- Parameters:
- Returns:
True
if the neuron is a senate member at the given block, False otherwise.- Return type:
This function is crucial for understanding the governance dynamics of the Bittensor network and for identifying the neurons that hold decision-making power within the network.
- get_vote_data(proposal_hash, block=None)[source]#
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:
- Returns:
An object containing the proposal’s voting data, or
None
if not found.- Return type:
Optional[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.
- get_proposal_vote_data#
- get_senate_members(block=None)[source]#
Retrieves the list of current senate members from the Bittensor blockchain. Senate members are responsible for governance and decision-making within the network.
- Parameters:
block (Optional[int]) – The blockchain block number at which to retrieve the senate members.
- Returns:
A list of
SS58
addresses of current senate members, orNone
if not available.- Return type:
Optional[List[str]]
Understanding the composition of the senate is key to grasping the governance structure and decision-making authority within the Bittensor network.
- get_proposal_call_data(proposal_hash, block=None)[source]#
Retrieves the call data of a specific proposal on the Bittensor blockchain. This data provides detailed information about the proposal, including its purpose and specifications.
- Parameters:
- Returns:
An object containing the proposal’s call data, or
None
if not found.- Return type:
Optional[GenericCall]
This function is crucial for analyzing the types of proposals made within the network and the specific changes or actions they intend to implement or address.
- get_proposal_hashes(block=None)[source]#
Retrieves the list of proposal hashes currently present on the Bittensor blockchain. Each hash uniquely identifies a proposal made within the network.
- Parameters:
block (Optional[int]) – The blockchain block number to query the proposal hashes.
- Returns:
A list of proposal hashes, or
None
if not available.- Return type:
Optional[List[str]]
This function enables tracking and reviewing the proposals made in the network, offering insights into the active governance and decision-making processes.
- get_proposals(block=None)[source]#
Retrieves all active proposals on the Bittensor blockchain, along with their call and voting data. This comprehensive view allows for a thorough understanding of the proposals and their reception by the senate.
- Parameters:
block (Optional[int]) – The blockchain block number to query the proposals.
- Returns:
- A dictionary mapping
proposal hashes to their corresponding call and vote data, or
None
if not available.
- Return type:
Optional[Dict[str, Tuple[bittensor.ProposalCallData, bittensor.ProposalVoteData]]]
This function is integral for analyzing the governance activity on the Bittensor network, providing a holistic view of the proposals and their impact or potential changes within the network.
- root_register(wallet, wait_for_inclusion=False, wait_for_finalization=True, prompt=False)[source]#
Registers the neuron associated with the wallet on the root network. This process is integral for participating in the highest layer of decision-making and governance within the Bittensor network.
- Parameters:
wallet (bittensor.wallet) – The wallet associated with the neuron to be registered on the root network.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- Returns:
True
if the registration on the root network is successful, False otherwise.- Return type:
This function enables neurons to engage in the most critical and influential aspects of the network’s governance, signifying a high level of commitment and responsibility in the Bittensor ecosystem.
- root_set_weights(wallet, netuids, weights, version_key=0, wait_for_inclusion=False, wait_for_finalization=False, prompt=False)[source]#
Sets the weights for neurons on the root network. This action is crucial for defining the influence and interactions of neurons at the root level of the Bittensor network.
- Parameters:
wallet (bittensor.wallet) – The wallet associated with the neuron setting the weights.
netuids (Union[NDArray[np.int64], torch.LongTensor, list]) – The list of neuron UIDs for which weights are being set.
weights (Union[NDArray[np.float32], torch.FloatTensor, list]) – The corresponding weights to be set for each UID.
version_key (int, optional) – Version key for compatibility with the network.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
prompt (bool, optional) – If
True
, prompts for user confirmation before proceeding.
- Returns:
True
if the setting of root-level weights is successful, False otherwise.- Return type:
This function plays a pivotal role in shaping the root network’s collective intelligence and decision-making processes, reflecting the principles of decentralized governance and collaborative learning in Bittensor.
- _do_set_root_weights(wallet, uids, vals, netuid=0, version_key=bittensor.__version_as_int__, wait_for_inclusion=False, wait_for_finalization=False)[source]#
Internal method to send a transaction to the Bittensor blockchain, setting weights for specified neurons on root. This method constructs and submits the transaction, handling retries and blockchain communication.
- Parameters:
wallet (bittensor.wallet) – The wallet associated with the neuron setting the weights.
uids (List[int]) – List of neuron UIDs for which weights are being set.
vals (List[int]) – List of weight values corresponding to each UID.
netuid (int) – Unique identifier for the network.
version_key (int, optional) – Version key for compatibility with the network.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
- Returns:
A tuple containing a success flag and an optional error message.
- Return type:
This method is vital for the dynamic weighting mechanism in Bittensor, where neurons adjust their trust in other neurons based on observed performance and contributions on the root network.
- query_identity(key, block=None)[source]#
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.
Note
See the Bittensor CLI documentation for supported identity parameters.
- Parameters:
- Returns:
An object containing the identity information of the neuron if found,
None
otherwise.- Return type:
result (dict)
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.
- update_identity(wallet, identified=None, params=None, wait_for_inclusion=True, wait_for_finalization=False)[source]#
Updates the identity of a neuron on the Bittensor blockchain. This function allows neurons to modify their identity attributes, reflecting changes in their roles, stakes, or other network-specific parameters.
Note
See the Bittensor CLI documentation for supported identity parameters.
- Parameters:
wallet (bittensor.wallet) – The wallet associated with the neuron whose identity is being updated.
identified (str, optional) – The identified
SS58
address of the neuron. Defaults to the wallet’s coldkey address.params (dict, optional) – A dictionary of parameters to update in the neuron’s identity.
wait_for_inclusion (bool, optional) – Waits for the transaction to be included in a block.
wait_for_finalization (bool, optional) – Waits for the transaction to be finalized on the blockchain.
- Returns:
True
if the identity update is successful, False otherwise.- Return type:
This function plays a vital role in maintaining the accuracy and currency of neuron identities in the Bittensor network, ensuring that the network’s governance and consensus mechanisms operate effectively.
- commit(wallet, netuid, data)[source]#
Commits arbitrary data to the Bittensor network by publishing metadata.
- get_commitment(netuid, uid, block=None)[source]#
Retrieves the on-chain commitment for a specific neuron in the Bittensor network.
- Parameters:
- Returns:
The commitment data as a string.
- Return type:
- query_subtensor(name, block=None, params=None)[source]#
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:
- Returns:
An object containing the requested data.
- Return type:
query_response (ScaleType)
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.
- query_map_subtensor(name, block=None, params=None)[source]#
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:
- Returns:
An object containing the map-like data structure, or
None
if not found.- Return type:
QueryMapResult
This function is particularly useful for analyzing and understanding complex network structures and relationships within the Bittensor ecosystem, such as inter-neuronal connections and stake distributions.
- query_constant(module_name, constant_name, block=None)[source]#
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:
- Returns:
The value of the constant if found,
None
otherwise.- Return type:
Optional[ScaleType]
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.
- query_module(module, name, block=None, params=None)[source]#
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.
params (Optional[List[object]], optional) – A list of parameters to pass to the query function.
- Returns:
An object containing the requested data if found,
None
otherwise.- Return type:
Optional[ScaleType]
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.
- query_map(module, name, block=None, params=None)[source]#
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.
params (Optional[List[object]], optional) – Parameters to be passed to the query.
- Returns:
A data structure representing the map storage if found,
None
otherwise.- Return type:
result (QueryMapResult)
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.
- state_call(method, data, block=None)[source]#
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:
- 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.
- query_runtime_api(runtime_api, method, params, block=None)[source]#
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[List[ParamWithTypes]], optional) – The parameters to pass to the method call.
block (Optional[int]) – The blockchain block number at which to perform the query.
- Returns:
The Scale Bytes encoded result from the runtime API call, or
None
if the call fails.- Return type:
Optional[bytes]
This function enables access to the deeper layers of the Bittensor blockchain, allowing for detailed and specific interactions with the network’s runtime environment.
- _encode_params(call_definition, params)[source]#
Returns a hex encoded string of the params using their types.
- Parameters:
call_definition (List[ParamWithTypes])
params (Union[List[Any], Dict[str, Any]])
- Return type:
- _get_hyperparameter(param_name, netuid, block=None)[source]#
Retrieves a specified hyperparameter for a specific subnet.
- Parameters:
- Returns:
- The value of the specified hyperparameter if the subnet exists,
None
otherwise.
- The value of the specified hyperparameter if the subnet exists,
- Return type:
- rho(netuid, block=None)[source]#
Retrieves the ‘Rho’ hyperparameter for a specified subnet within the Bittensor network. ‘Rho’ represents the global inflation rate, which directly influences the network’s token emission rate and economic model.
Note
This is currently fixed such that the Bittensor blockchain emmits 7200 Tao per day.
- Parameters:
- Returns:
The value of the ‘Rho’ hyperparameter if the subnet exists,
None
otherwise.- Return type:
Optional[int]
- Mathematical Context:
Rho (p) is calculated based on the network’s target inflation and actual neuron staking. It adjusts the emission rate of the TAO token to balance the network’s economy and dynamics. The formula for Rho is defined as: p = (Staking_Target / Staking_Actual) * Inflation_Target. Here, Staking_Target and Staking_Actual represent the desired and actual total stakes in the network, while Inflation_Target is the predefined inflation rate goal.
‘Rho’ is essential for understanding the network’s economic dynamics, affecting the reward distribution and incentive structures across the network’s neurons.
- kappa(netuid, block=None)[source]#
Retrieves the ‘Kappa’ hyperparameter for a specified subnet. ‘Kappa’ is a critical parameter in the Bittensor network that controls the distribution of stake weights among neurons, impacting their rankings and incentive allocations.
- Parameters:
- Returns:
The value of the ‘Kappa’ hyperparameter if the subnet exists, None otherwise.
- Return type:
Optional[float]
- Mathematical Context:
Kappa (κ) is used in the calculation of neuron ranks, which determine their share of network incentives. It is derived from the softmax function applied to the inter-neuronal weights set by each neuron. The formula for Kappa is: κ_i = exp(w_i) / Σ(exp(w_j)), where w_i represents the weight set by neuron i, and the denominator is the sum of exponential weights set by all neurons. This mechanism ensures a normalized and probabilistic distribution of ranks based on relative weights.
Understanding ‘Kappa’ is crucial for analyzing stake dynamics and the consensus mechanism within the network, as it plays a significant role in neuron ranking and incentive allocation processes.
- difficulty(netuid, block=None)[source]#
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:
- 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.
- recycle(netuid, block=None)[source]#
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.
- immunity_period(netuid, block=None)[source]#
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.
- validator_batch_size(netuid, block=None)[source]#
Returns network ValidatorBatchSize hyper parameter.
- Parameters:
- Returns:
- The value of the ValidatorBatchSize hyperparameter, or None if the subnetwork does not exist
or the parameter is not found.
- Return type:
Optional[int]
- validator_prune_len(netuid, block=None)[source]#
Returns network ValidatorPruneLen hyper parameter.
- Parameters:
- Returns:
The value of the ValidatorPruneLen hyperparameter, or None if the subnetwork does not exist or the parameter is not found.
- Return type:
Optional[int]
- validator_logits_divergence(netuid, block=None)[source]#
Returns network ValidatorLogitsDivergence hyper parameter.
- Parameters:
- Returns:
The value of the ValidatorLogitsDivergence hyperparameter, or None if the subnetwork does not exist or the parameter is not found.
- Return type:
Optional[float]
- validator_sequence_length(netuid, block=None)[source]#
Returns network ValidatorSequenceLength hyperparameter.
- Parameters:
- Returns:
- The value of the ValidatorSequenceLength hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the ValidatorSequenceLength hyperparameter, or
- Return type:
Optional[int]
- validator_epochs_per_reset(netuid, block=None)[source]#
Returns network ValidatorEpochsPerReset hyperparameter.
- Parameters:
- Returns:
- The value of the ValidatorEpochsPerReset hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the ValidatorEpochsPerReset hyperparameter, or
- Return type:
Optional[int]
- validator_epoch_length(netuid, block=None)[source]#
Returns network ValidatorEpochLen hyperparameter.
- Parameters:
- Returns:
- The value of the ValidatorEpochLen hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the ValidatorEpochLen hyperparameter, or
- Return type:
Optional[int]
- validator_exclude_quantile(netuid, block=None)[source]#
Returns network ValidatorExcludeQuantile hyperparameter.
- Parameters:
- Returns:
The value of the ValidatorExcludeQuantile hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.- Return type:
Optional[float]
- max_allowed_validators(netuid, block=None)[source]#
Returns network ValidatorExcludeQuantile hyperparameter.
- Parameters:
- Returns:
- The value of the ValidatorExcludeQuantile hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the ValidatorExcludeQuantile hyperparameter, or
- Return type:
Optional[float]
- min_allowed_weights(netuid, block=None)[source]#
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]
- max_weight_limit(netuid, block=None)[source]#
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]
- adjustment_alpha(netuid, block=None)[source]#
Returns network AdjustmentAlpha hyperparameter.
- Parameters:
- Returns:
- The value of the AdjustmentAlpha hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the AdjustmentAlpha hyperparameter, or
- Return type:
Optional[float]
- bonds_moving_avg(netuid, block=None)[source]#
Returns network BondsMovingAverage hyperparameter.
- Parameters:
- Returns:
- The value of the BondsMovingAverage hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the BondsMovingAverage hyperparameter, or
- Return type:
Optional[float]
- synergy_scaling_law_power(netuid, block=None)[source]#
Returns network ScalingLawPower hyperparameter.
- Parameters:
- Returns:
- The value of the ScalingLawPower hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the ScalingLawPower hyperparameter, or
- Return type:
Optional[float]
- subnetwork_n(netuid, block=None)[source]#
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]
- max_n(netuid, block=None)[source]#
Returns network MaxAllowedUids hyperparameter.
- Parameters:
- Returns:
- The value of the MaxAllowedUids hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the MaxAllowedUids hyperparameter, or
- Return type:
Optional[int]
- blocks_since_epoch(netuid, block=None)[source]#
Returns network BlocksSinceEpoch hyperparameter.
- Parameters:
- Returns:
- The value of the BlocksSinceEpoch hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.
- The value of the BlocksSinceEpoch hyperparameter, or
- Return type:
Optional[int]
- blocks_since_last_update(netuid, uid)[source]#
Returns the number of blocks since the last update for a specific UID in the subnetwork.
- tempo(netuid, block=None)[source]#
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]
- get_total_stake_for_hotkey(ss58_address, block=None)[source]#
Returns the total stake held on a hotkey including delegative.
- Parameters:
- Returns:
- The total stake held on the hotkey, or
None
if the hotkey does not exist or the stake is not found.
- The total stake held on the hotkey, or
- Return type:
Optional[Balance]
- get_total_stake_for_coldkey(ss58_address, block=None)[source]#
Returns the total stake held on a coldkey.
- Parameters:
- Returns:
- The total stake held on the coldkey, or
None
if the coldkey does not exist or the stake is not found.
- The total stake held on the coldkey, or
- Return type:
Optional[Balance]
- get_stake_for_coldkey_and_hotkey(hotkey_ss58, coldkey_ss58, block=None)[source]#
Returns the stake under a coldkey - hotkey pairing.
- Parameters:
- Returns:
- The stake under the coldkey - hotkey pairing, or
None
if the pairing does not exist or the stake is not found.
- The stake under the coldkey - hotkey pairing, or
- Return type:
Optional[Balance]
- get_stake(hotkey_ss58, block=None)[source]#
Returns a list of stake tuples (coldkey, balance) for each delegating coldkey including the owner.
- Parameters:
- Returns:
- A list of tuples, each containing a coldkey SS58 address and the corresponding
balance staked by that coldkey.
- Return type:
- does_hotkey_exist(hotkey_ss58, block=None)[source]#
Returns true if the hotkey is known by the chain and there are accounts.
- Parameters:
- Returns:
True
if the hotkey is known by the chain and there are accounts,False
otherwise.- Return type:
- get_hotkey_owner(hotkey_ss58, block=None)[source]#
Returns the coldkey owner of the passed hotkey.
- Parameters:
- Returns:
- The SS58 address of the coldkey owner, or
None
if the hotkey does not exist or the owner is not found.
- The SS58 address of the coldkey owner, or
- Return type:
Optional[str]
- get_axon_info(netuid, hotkey_ss58, block=None)[source]#
Returns the axon information for this hotkey account.
- Parameters:
- Returns:
- An AxonInfo object containing the axon information, or
None
if the axon information is not found.
- An AxonInfo object containing the axon information, or
- Return type:
Optional[AxonInfo]
- get_prometheus_info(netuid, hotkey_ss58, block=None)[source]#
Returns the prometheus information for this hotkey account.
- Parameters:
- Returns:
- A PrometheusInfo object containing the prometheus information, or
None
if the prometheus information is not found.
- A PrometheusInfo object containing the prometheus information, or
- Return type:
Optional[PrometheusInfo]
- property block: int#
Returns current chain block. :returns: Current chain block. :rtype: block (int)
- Return type:
- total_issuance(block=None)[source]#
Retrieves the total issuance of the Bittensor network’s native token (Tao) as of a specific blockchain block. This represents the total amount of currency that has been issued or mined on the network.
- Parameters:
block (Optional[int], optional) – The blockchain block number at which to perform the query.
- Returns:
The total issuance of TAO, represented as a Balance object.
- Return type:
The total issuance is a key economic indicator in the Bittensor network, reflecting the overall supply of the currency and providing insights into the network’s economic health and inflationary trends.
- total_stake(block=None)[source]#
Retrieves the total amount of TAO staked on the Bittensor network as of a specific blockchain block. This represents the cumulative stake across all neurons in the network, indicating the overall level of participation and investment by the network’s participants.
- Parameters:
block (Optional[int], optional) – The blockchain block number at which to perform the query.
- Returns:
The total amount of TAO staked on the network, represented as a Balance object.
- Return type:
The total stake is an important metric for understanding the network’s security, governance dynamics, and the level of commitment by its participants. It is also a critical factor in the network’s consensus and incentive mechanisms.
- serving_rate_limit(netuid, block=None)[source]#
Retrieves the serving rate limit for a specific subnet within the Bittensor network. This rate limit determines how often you can change your node’s IP address on the blockchain. Expressed in number of blocks. Applies to both subnet validator and subnet miner nodes. Used when you move your node to a new machine.
- Parameters:
- Returns:
The serving rate limit of the subnet if it exists,
None
otherwise.- Return type:
Optional[int]
The serving rate limit is a crucial parameter for maintaining network efficiency and preventing overuse of resources by individual neurons. It helps ensure a balanced distribution of service requests across the network.
- tx_rate_limit(block=None)[source]#
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:
block (Optional[int], optional) – The blockchain block number at which to perform the query.
- 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.
- subnet_exists(netuid, block=None)[source]#
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.
- get_all_subnet_netuids(block=None)[source]#
Retrieves the list of all subnet unique identifiers (netuids) currently present in the Bittensor network.
- Parameters:
block (Optional[int], optional) – The blockchain block number at which to retrieve the subnet netuids.
- Returns:
A list of subnet netuids.
- Return type:
List[int]
This function provides a comprehensive view of the subnets within the Bittensor network, offering insights into its diversity and scale.
- get_total_subnets(block=None)[source]#
Retrieves the total number of subnets within the Bittensor network as of a specific blockchain block.
- Parameters:
block (Optional[int], optional) – The blockchain block number for the query.
- Returns:
The total number of subnets in the network.
- Return type:
Understanding the total number of subnets is essential for assessing the network’s growth and the extent of its decentralized infrastructure.
- get_subnet_modality(netuid, block=None)[source]#
Returns the NetworkModality hyperparameter for a specific subnetwork.
- Parameters:
- Returns:
The value of the NetworkModality hyperparameter, or
None
if the subnetwork does not exist or the parameter is not found.- Return type:
Optional[int]
- get_emission_value_by_subnet(netuid, block=None)[source]#
Retrieves the emission value of a specific subnet within the Bittensor network. The emission value represents the rate at which the subnet emits or distributes the network’s native token (Tao).
- Parameters:
- Returns:
The emission value of the subnet, None if not available.
- Return type:
Optional[float]
The emission value is a critical economic parameter, influencing the incentive distribution and reward mechanisms within the subnet.
- get_subnet_connection_requirements(netuid, block=None)[source]#
Retrieves the connection requirements for a specific subnet within the Bittensor network. This function provides details on the criteria that must be met for neurons to connect to the subnet.
- Parameters:
- Returns:
A dictionary detailing the connection requirements for the subnet.
- Return type:
Understanding these requirements is crucial for neurons looking to participate in or interact with specific subnets, ensuring compliance with their connection standards.
- get_subnets(block=None)[source]#
Retrieves a list of all subnets currently active within the Bittensor network. This function provides an overview of the various subnets and their identifiers.
- Parameters:
block (Optional[int], optional) – The blockchain block number for the query.
- Returns:
A list of network UIDs representing each active subnet.
- Return type:
List[int]
This function is valuable for understanding the network’s structure and the diversity of subnets available for neuron participation and collaboration.
- get_all_subnets_info(block=None)[source]#
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:
block (Optional[int], optional) – The blockchain block number for the query.
- Returns:
A list of SubnetInfo objects, each containing detailed information about a subnet.
- Return type:
List[SubnetInfo]
Gaining insights into the subnets’ details assists in understanding the network’s composition, the roles of different subnets, and their unique features.
- get_subnet_info(netuid, block=None)[source]#
Retrieves detailed information about a specific subnet within the Bittensor network. This function provides key data on the subnet, including its operational parameters and network status.
- Parameters:
- Returns:
Detailed information about the subnet, or
None
if not found.- Return type:
Optional[SubnetInfo]
This function is essential for neurons and stakeholders interested in the specifics of a particular subnet, including its governance, performance, and role within the broader network.
- get_subnet_hyperparameters(netuid, block=None)[source]#
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[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.
- get_subnet_owner(netuid, block=None)[source]#
Retrieves the owner’s address of a specific subnet within the Bittensor network. The owner is typically the entity responsible for the creation and maintenance of the subnet.
- Parameters:
- Returns:
The SS58 address of the subnet’s owner, or
None
if not available.- Return type:
Optional[str]
Knowing the subnet owner provides insights into the governance and operational control of the subnet, which can be important for decision-making and collaboration within the network.
- is_hotkey_delegate(hotkey_ss58, block=None)[source]#
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.
- get_delegate_take(hotkey_ss58, block=None)[source]#
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.
- get_nominators_for_hotkey(hotkey_ss58, block=None)[source]#
Retrieves a list of nominators and their stakes for a neuron identified by its hotkey. Nominators are neurons that stake their tokens on a delegate to support its operations.
- Parameters:
- Returns:
A list of tuples containing each nominator’s address and staked amount or 0.
- Return type:
This function provides insights into the neuron’s support network within the Bittensor ecosystem, indicating its trust and collaboration relationships.
- get_delegate_by_hotkey(hotkey_ss58, block=None)[source]#
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.
- get_delegates_lite(block=None)[source]#
Retrieves a lighter list of all delegate neurons within the Bittensor network. This function provides an overview of the neurons that are actively involved in the network’s delegation system.
Analyzing the delegate population offers insights into the network’s governance dynamics and the distribution of trust and responsibility among participating neurons.
This is a lighter version of
get_delegates()
.- Parameters:
block (Optional[int], optional) – The blockchain block number for the query.
- Returns:
A list of
DelegateInfoLite
objects detailing each delegate’s characteristics.- Return type:
List[DelegateInfoLite]
- get_delegates(block=None)[source]#
Retrieves a list of all delegate neurons within the Bittensor network. This function provides an overview of the neurons that are actively involved in the network’s delegation system.
Analyzing the delegate population offers insights into the network’s governance dynamics and the distribution of trust and responsibility among participating neurons.
- Parameters:
block (Optional[int], optional) – The blockchain block number for the query.
- Returns:
A list of DelegateInfo objects detailing each delegate’s characteristics.
- Return type:
List[DelegateInfo]
- get_delegated(coldkey_ss58, block=None)[source]#
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[DelegateInfo, Balance]]
This function is important for account holders to understand their stake allocations and their involvement in the network’s delegation and consensus mechanisms.
- get_childkey_take(hotkey, netuid, block=None)[source]#
Get the childkey take of a hotkey on a specific network. Args: - hotkey (str): The hotkey to search for. - netuid (int): The netuid to search for. - block (Optional[int]): Optional parameter specifying the block number. Defaults to None.
Returns: - Optional[int]: The value of the “ChildkeyTake” if found, or None if any error occurs.
- get_children(hotkey, netuid)[source]#
Get the children of a hotkey on a specific network. :param hotkey: The hotkey to query. :type hotkey: str :param netuid: The network ID. :type netuid: int
- Returns:
List of (proportion, child_address) tuples, or None if an error occurred.
- Return type:
list or None
- get_parents(child_hotkey, netuid)[source]#
Get the parents of a child hotkey on a specific network. :param child_hotkey: The child hotkey to query. :type child_hotkey: str :param netuid: The network ID. :type netuid: int
- Returns:
List of (proportion, parent_address) tuples, or None if an error occurred.
- Return type:
list or None
- get_stake_info_for_coldkey(coldkey_ss58, block=None)[source]#
Retrieves stake information associated with a specific coldkey. This function provides details about the stakes held by an account, including the staked amounts and associated delegates.
- Parameters:
- Returns:
A list of StakeInfo objects detailing the stake allocations for the account.
- Return type:
List[StakeInfo]
Stake information is vital for account holders to assess their investment and participation in the network’s delegation and consensus processes.
- get_stake_info_for_coldkeys(coldkey_ss58_list, block=None)[source]#
Retrieves stake information for a list of coldkeys. This function aggregates stake data for multiple accounts, providing a collective view of their stakes and delegations.
- Parameters:
- Returns:
A dictionary mapping each coldkey to a list of its StakeInfo objects.
- Return type:
This function is useful for analyzing the stake distribution and delegation patterns of multiple accounts simultaneously, offering a broader perspective on network participation and investment strategies.
- get_minimum_required_stake()[source]#
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.
- is_hotkey_registered_any(hotkey_ss58, block=None)[source]#
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.
- is_hotkey_registered_on_subnet(hotkey_ss58, netuid, block=None)[source]#
Checks if a neuron’s hotkey is registered on a specific subnet within the Bittensor network.
- Parameters:
- Returns:
True
if the hotkey is registered on the specified subnet, False otherwise.- Return type:
This function helps in assessing the participation of a neuron in a particular subnet, indicating its specific area of operation or influence within the network.
- is_hotkey_registered(hotkey_ss58, netuid=None, block=None)[source]#
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:
- Returns:
True
if the hotkey is registered in the specified context (either any subnet or a specificsubnet),
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.
- get_uid_for_hotkey_on_subnet(hotkey_ss58, netuid, block=None)[source]#
Retrieves the unique identifier (UID) for a neuron’s hotkey on a specific subnet.
- Parameters:
- 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.
- get_all_uids_for_hotkey(hotkey_ss58, block=None)[source]#
Retrieves all unique identifiers (UIDs) associated with a given hotkey across different subnets within the Bittensor network. This function helps in identifying all the neuron instances that are linked to a specific hotkey.
- Parameters:
- Returns:
A list of UIDs associated with the given hotkey across various subnets.
- Return type:
List[int]
This function is important for tracking a neuron’s presence and activities across different subnets within the Bittensor ecosystem.
- get_netuids_for_hotkey(hotkey_ss58, block=None)[source]#
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.
- get_neuron_for_pubkey_and_subnet(hotkey_ss58, netuid, block=None)[source]#
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:
- Returns:
Detailed information about the neuron if found,
None
otherwise.- Return type:
Optional[NeuronInfo]
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.
- get_all_neurons_for_pubkey(hotkey_ss58, block=None)[source]#
Retrieves information about all neuron instances associated with a given public key (hotkey
SS58
address) across different subnets of the Bittensor network. This function aggregates neuron data from various subnets to provide a comprehensive view of a neuron’s presence and status within the network.- Parameters:
- Returns:
A list of NeuronInfo objects detailing the neuron’s presence across various subnets.
- Return type:
List[NeuronInfo]
This function is valuable for analyzing a neuron’s overall participation, influence, and contributions across the Bittensor network.
- neuron_has_validator_permit(uid, netuid, block=None)[source]#
Checks if a neuron, identified by its unique identifier (UID), has a validator permit on a specific subnet within the Bittensor network. This function determines whether the neuron is authorized to participate in validation processes on the subnet.
- Parameters:
- Returns:
True
if the neuron has a validator permit, False otherwise.- Return type:
Optional[bool]
This function is essential for understanding a neuron’s role and capabilities within a specific subnet, particularly regarding its involvement in network validation and governance.
- neuron_for_wallet(wallet, netuid, block=None)[source]#
Retrieves information about a neuron associated with a given wallet on a specific subnet. This function provides detailed data about the neuron’s status, stake, and activities based on the wallet’s hotkey address.
- Parameters:
- Returns:
Detailed information about the neuron if found,
None
otherwise.- Return type:
Optional[NeuronInfo]
This function is important for wallet owners to understand and manage their neuron’s presence and activities within a particular subnet of the Bittensor network.
- neuron_for_uid(uid, netuid, block=None)[source]#
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:
- Returns:
Detailed information about the neuron if found,
None
otherwise.- Return type:
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.
- neurons(netuid, block=None)[source]#
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[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.
- neuron_for_uid_lite(uid, netuid, block=None)[source]#
Retrieves a lightweight version of information about a neuron in a specific subnet, identified by its UID. The ‘lite’ version focuses on essential attributes such as stake and network activity.
- Parameters:
- Returns:
A simplified version of neuron information if found,
None
otherwise.- Return type:
Optional[NeuronInfoLite]
This function is useful for quick and efficient analyses of neuron status and activities within a subnet without the need for comprehensive data retrieval.
- neurons_lite(netuid, block=None)[source]#
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[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.
- metagraph(netuid, lite=True, block=None)[source]#
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:
bittensor.Metagraph
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.
- incentive(netuid, block=None)[source]#
Retrieves the list of incentives for neurons within a specific subnet of the Bittensor network. This function provides insights into the reward distribution mechanisms and the incentives allocated to each neuron based on their contributions and activities.
- Parameters:
- Returns:
The list of incentives for neurons within the subnet, indexed by UID.
- Return type:
List[int]
Understanding the incentive structure is crucial for analyzing the network’s economic model and the motivational drivers for neuron participation and collaboration.
- weights(netuid, block=None)[source]#
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.
- bonds(netuid, block=None)[source]#
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:
- Returns:
- A 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.
- get_subnet_burn_cost(block=None)[source]#
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:
block (Optional[int]) – The blockchain block number for the query.
- 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.
- _do_delegation(wallet, delegate_ss58, amount, wait_for_inclusion=True, wait_for_finalization=False)[source]#
Delegates a specified amount of stake to a delegate’s hotkey.
This method sends a transaction to add stake to a delegate’s hotkey and retries the call up to three times with exponential backoff in case of failures.
- Parameters:
wallet (bittensor.wallet) – The wallet from which the stake will be delegated.
delegate_ss58 (str) – The SS58 address of the delegate’s hotkey.
amount (Balance) – The amount of stake to be delegated.
wait_for_inclusion (bool, optional) – Whether to wait for the transaction to be included in a block. Default is
True
.wait_for_finalization (bool, optional) – Whether to wait for the transaction to be finalized. Default is
False
.
- Returns:
True
if the delegation is successful,False
otherwise.- Return type:
- _do_undelegation(wallet, delegate_ss58, amount, wait_for_inclusion=True, wait_for_finalization=False)[source]#
Removes a specified amount of stake from a delegate’s hotkey.
This method sends a transaction to remove stake from a delegate’s hotkey and retries the call up to three times with exponential backoff in case of failures.
- Parameters:
wallet (bittensor.wallet) – The wallet from which the stake will be removed.
delegate_ss58 (str) – The SS58 address of the delegate’s hotkey.
amount (Balance) – The amount of stake to be removed.
wait_for_inclusion (bool, optional) – Whether to wait for the transaction to be included in a block. Default is
True
.wait_for_finalization (bool, optional) – Whether to wait for the transaction to be finalized. Default is
False
.
- Returns:
True
if the undelegation is successful,False
otherwise.- Return type:
- _do_nominate(wallet, wait_for_inclusion=True, wait_for_finalization=False)[source]#
Nominates the wallet’s hotkey to become a delegate.
This method sends a transaction to nominate the wallet’s hotkey to become a delegate and retries the call up to three times with exponential backoff in case of failures.
- Parameters:
wallet (bittensor.wallet) – The wallet whose hotkey will be nominated.
wait_for_inclusion (bool, optional) – Whether to wait for the transaction to be included in a block. Default is
True
.wait_for_finalization (bool, optional) – Whether to wait for the transaction to be finalized. Default is
False
.
- Returns:
True
if the nomination is successful,False
otherwise.- Return type:
- _do_increase_take(wallet, hotkey_ss58, take, wait_for_inclusion=True, wait_for_finalization=False)[source]#
Increases the take rate for a delegate’s hotkey.
This method sends a transaction to increase the take rate for a delegate’s hotkey and retries the call up to three times with exponential backoff in case of failures.
- Parameters:
wallet (bittensor.wallet) – The wallet from which the transaction will be signed.
hotkey_ss58 (str) – The SS58 address of the delegate’s hotkey.
take (int) – The new take rate to be set.
wait_for_inclusion (bool, optional) – Whether to wait for the transaction to be included in a block. Default is
True
.wait_for_finalization (bool, optional) – Whether to wait for the transaction to be finalized. Default is
False
.
- Returns:
True
if the take rate increase is successful,False
otherwise.- Return type:
- _do_decrease_take(wallet, hotkey_ss58, take, wait_for_inclusion=True, wait_for_finalization=False)[source]#
Decreases the take rate for a delegate’s hotkey.
This method sends a transaction to decrease the take rate for a delegate’s hotkey and retries the call up to three times with exponential backoff in case of failures.
- Parameters:
wallet (bittensor.wallet) – The wallet from which the transaction will be signed.
hotkey_ss58 (str) – The SS58 address of the delegate’s hotkey.
take (int) – The new take rate to be set.
wait_for_inclusion (bool, optional) – Whether to wait for the transaction to be included in a block. Default is
True
.wait_for_finalization (bool, optional) – Whether to wait for the transaction to be finalized. Default is
False
.
- Returns:
True
if the take rate decrease is successful,False
otherwise.- Return type:
- get_balance(address, block=None)[source]#
Retrieves the token balance of a specific address within the Bittensor network. This function queries the blockchain to determine the amount of Tao held by a given account.
- Parameters:
- Returns:
The account balance at the specified block, represented as a Balance object.
- Return type:
This function is important for monitoring account holdings and managing financial transactions within the Bittensor ecosystem. It helps in assessing the economic status and capacity of network participants.
- get_current_block()[source]#
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.
- get_balances(block=None)[source]#
Retrieves the token balances of all accounts within the Bittensor network as of a specific blockchain block. This function provides a comprehensive view of the token distribution among different accounts.
- Parameters:
block (int, optional) – The blockchain block number at which to perform the query.
- Returns:
A dictionary mapping each account’s
ss58
address to its balance.- Return type:
This function is valuable for analyzing the overall economic landscape of the Bittensor network, including the distribution of financial resources and the financial status of network participants.
- get_block_hash(block_id)[source]#
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_id (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.
- bittensor.subtensor.subtensor#