Cybertensor API Reference
ct.cwtensor
The Cwtensor is utilized for managing interactions with the space-pussy chain. It serves as an interface to communicate with "space-pussy", Cybertensor's main blockchain network, or others, enabling operations like querying and transacting.
Examples
# Creating a default chain connection to remote space-pussy instance.
=
# Parsing --cwtensor.network and --cwtensor.chain_endpoint from the command line
=
# Connecting cwtensor's default local entrypoint "grpc+http://localhost:9090"
=
# Connecting to a specific endpoint
=
Methods
nominate
->
Designates the wallet's hotkey as a delegate.
delegate
->
Adds a specific amount of stake to a delegate using a wallet.
undelegate
->
Removes a specific amount of stake from a delegate using a wallet.
set_weights
->
Sets weights for a given netuid.
register
->
Registers the wallet to the chain.
burned_register
->
Registers the wallet to the chain by recycling PUSSY.
transfer
->
Transfers funds from the wallet to a destination public key address.
get_existential_deposit
->
Returns the existential deposit for the chain.
serve
->
Starts serving on a specific IP, port and protocol for a given netuid.
serve_axon
->
Starts serving an Axon for a given netuid.
serve_prometheus
->
Starts serving a Prometheus server on a specific port for a given netuid.
add_stake
->
Adds a specific amount of stake to a hotkey uid.
add_stake_multiple
->
Adds stake to each hotkey in the list from a common coldkey.
unstake
->
Removes stake into the wallet coldkey from the specified hotkey uid.
unstake_multiple
->
Removes stake from each hotkey in the list to a common coldkey.
Hyperparameters
rho
->
Returns the network Rho hyperparameter if the network exists. Accepts an integer netuid representing the unique network ID and an optional integer block representing the block number.
kappa
->
Returns the network Kappa hyperparameter if the network exists. Inputs are netuid and an optional block number.
difficulty
->
Returns the network Difficulty hyperparameter if the network exists. Inputs are netuid and an optional block number.
burn
->
Returns the network Burn hyperparameter if the network exists. Inputs are netuid and an optional block number.
immunity_period
->
Returns the network ImmunityPeriod hyperparameter if the network exists. Inputs are netuid and an optional block number.
validator_batch_size
->
Returns the network ValidatorBatchSize hyperparameter if the network exists. Inputs are netuid and an optional block number.
validator_prune_len
->
Returns the network ValidatorPruneLen hyperparameter if the network exists. Inputs are netuid and an optional block number.
validator_logits_divergence
->
Returns the network ValidatorLogitsDivergence hyperparameter if the network exists. Inputs are netuid and an optional block number.
validator_sequence_length
->
Returns the network ValidatorSequenceLength hyperparameter if the network exists. Inputs are netuid and an optional block number.
validator_epochs_per_reset
->
Returns the network ValidatorEpochsPerReset hyperparameter if the network exists. Inputs are netuid and an optional block number.
validator_epoch_length
->
Returns the network ValidatorEpochLen hyperparameter if the network exists. Inputs are netuid and an optional block number.
validator_exclude_quantile
->
Returns the network ValidatorExcludeQuantile hyperparameter if the network exists. Inputs are netuid and an optional block number.
max_allowed_validators
->
Returns the network MaxAllowedValidators hyperparameter if the network exists. Inputs are netuid and an optional block number.
min_allowed_weights
->
Returns the network MinAllowedWeights hyperparameter if the network exists. Inputs are netuid and an optional block number.
max_weight_limit
->
Returns the network MaxWeightsLimit hyperparameter if the network exists. Inputs are netuid and an optional block number.
scaling_law_power
->
Returns the network ScalingLawPower hyperparameter if the network exists. Inputs are netuid and an optional block number.
synergy_scaling_law_power
->
Returns the network SynergyScalingLawPower hyperparameter if the network exists. Inputs are netuid and an optional block number.
subnetwork_n
->
Returns the network SubnetworkN hyperparameter if the network exists. Inputs are netuid and an optional block number.
max_n
->
Returns the network MaxAllowedUids hyperparameter if the network exists. Inputs are netuid and an optional block number.
blocks_since_epoch
->
Returns the network BlocksSinceLastStep hyperparameter if the network exists. Inputs are netuid and an optional block number.
tempo
->
Returns the network Tempo hyperparameter if the network exists. Inputs are netuid and an optional block number.
Account functions
get_total_stake_for_hotkey
->
Returns the total stake held on a hotkey including delegated. Inputs are address and an optional block number.
get_total_stake_for_coldkey
->
Returns the total stake held on a coldkey across all hotkeys including delegates. Inputs are address and an optional block number.
get_stake_for_coldkey_and_hotkey
->
Returns the stake under a coldkey - hotkey pairing. Inputs are hotkey, coldkey and an optional block number.
get_stake
->
Returns a list of stake tuples (coldkey, balance) for each delegating coldkey including the owner. Inputs are hotkey and an optional block number.
does_hotkey_exist
->
Returns true if the hotkey is known by the chain and there are accounts. Inputs are hotkey and an optional block number.
get_hotkey_owner
->
Returns the coldkey owner of the passed hotkey if it exists. Inputs are hotkey and an optional block number.
get_axon_info
->
Returns the axon information for the specified hotkey account if it exists. Inputs are hotkey and an optional block number.
get_prometheus_info
->
Returns the prometheus information for the specified hotkey account if it exists. Inputs are hotkey and an optional block number.
Global state
block
Property that returns the current chain block.
total_issuance
->
Returns the total issuance of tokens as of a specified block. If no block is provided, the default is the current block.
total_stake
->
Returns the total amount of stake as of a specified block. If no block is provided, the default is the current block.
serving_rate_limit
->
Returns the serving rate limit as of a specified block. If no block is provided, the default is the current block.
tx_rate_limit
->
Returns the transaction rate limit as of a specified block. If no block is provided, the default is the current block.
Subnet stake
subnet_exists
->
Checks if a subnet with the given netuid exists as of a specified block. If no block is provided, the default is the current block.
get_all_subnet_netuids
->
Returns a list of netuids of all subnets as of a specified block. If no block is provided, the default is the current block.
get_total_subnets
->
Returns the total number of subnets as of a specified block. If no block is provided, the default is the current block.
get_subnet_modality
->
Returns the modality of a subnet with a specified netuid as of a given block. If no block is provided, the default is the current block.
get_subnet_connection_requirement
->
Returns the connection requirement between two subnets with specified netuids as of a given block. If no block is provided, the default is the current block.
get_emission_value_by_subnet
->
Returns the emission value of a subnet with the given netuid as of a specified block. If no block is provided, the default is the current block.
get_subnet_connection_requirements
->
Returns a dictionary of the connection requirements of a subnet with the given netuid as of a specified block. If no block is provided, the default is the current block.
get_subnets
->
Returns a list of all subnets as of a specified block. If no block is provided, the default is the current block.
get_all_subnets_info
->
Returns a list of information about all subnets as of a specified block. If no block is provided, the default is the current block.
get_subnet_info
->
Returns information about a subnet with a given netuid as of a specified block. If no block is provided, the default is the current block.
Delegation
is_hotkey_delegate
->
Checks if a delegate with the specified hotkey exists.
get_delegate_take
->
Returns the 'take' (portion of the reward a delegate receives from staking) of a delegate specified by a hotkey as of a given block. If no block is provided, the default is the current block.
get_nominators_for_hotkey
->
Returns a list of tuples, each containing a nominator's address and balance for the delegate specified by a hotkey as of a given block. If no block is provided, the default is the current block.
get_delegate_by_hotkey
->
Returns information about a delegate specified by a hotkey as of a given block. If no block is provided, the default is the current block.
get_delegates
->
Returns a list of all delegates as of a specified block. If no block is provided, the default is the current block.
get_delegated
->
Returns a list of delegates that a given coldkey is staked to, as of a specified block. If no block is provided, the default is the current block. Each item in the list is a tuple containing the delegate's information and the staked balance.
Neuron information per subnet
is_hotkey_registered_any
->
Returns True if the hotkey is registered on any subnet. If no block is specified, the current block is used.
is_hotkey_registered_on_subnet
->
Returns True if the hotkey is registered on a specified subnet. If no block is specified, the current block is used.
is_hotkey_registered
->
Returns True if the hotkey is registered on a specified subnet. If no block is specified, the current block is used.
get_uid_for_hotkey_on_subnet
->
Returns the user id (uid) for the hotkey on a specified subnet. If no block is specified, the current block is used.
get_all_uids_for_hotkey
->
Returns a list of all user ids (uids) for the hotkey. If no block is specified, the current block is used.
get_netuids_for_hotkey
->
Returns a list of all network user ids (netuids) for the hotkey. If no block is specified, the current block is used.
get_neuron_for_pubkey_and_subnet
->
Returns the neuron information for the hotkey on a specified subnet. If no block is specified, the current block is used.
get_all_neurons_for_pubkey
->
Returns a list of all neurons for the hotkey. If no block is specified, the current block is used.
neuron_has_validator_permit
->
Returns True if the neuron with the given uid has a validator permit for the specified subnet. If no block is specified, the current block is used.
neuron_for_wallet
->
Returns the neuron information for the given wallet on a specified subnet. If no block is specified, the current block is used.
neuron_for_uid
->
Returns the neuron metadata associated with a given user id (uid) and network user id (netuid) at a specified block, or None if it does not exist.
neurons
->
Returns a list of neurons from the chain for a given network user id (netuid) at a specified block.
neuron_for_uid_lite
->
Returns the lightweight neuron metadata (without weights and bonds) associated with a given user id (uid) and network user id (netuid) at a specified block, or None if it does not exist.
neurons_lite
->
Returns a list of lightweight neurons (without weights and bonds) from the chain for a given network user id (netuid) at a specified block.
metagraph
->
Returns the metagraph for the subnet associated with a given network user id (netuid). If 'lite' is True, it returns a metagraph using the lightweight sync (no weights, no bonds).
Legacy
get_balance
->
Returns the token balance for the given Substrate address at a specified block.
get_current_block
->
Returns the current block number on the chain.
get_balances
->
Returns a dictionary of balances for all addresses at a specified block. The dictionary keys are addresses and values are their corresponding balances.
__str__()
This method is used to provide a string representation of the instance.
If the network argument equals the chain_endpoint argument, it returns a string that denotes connecting to a chain endpoint without a known network. Otherwise, it represents connecting to a network with a known endpoint.
__repr__()
This method is used to provide an official string representation of the instance.
The string returned by this method is identical to the one provided by the __str__() method.
Initialization
To initialize an instance of the Subtensor class, you'll need to provide three arguments:
=
Arguments
config (ct.Config, optional, defaults=ct.cwtensor.config()): Cwtensor config object containing arguments from ct.cwtensor.config() which are automatically parsed from command line and ENV vars.network (str, optional, default='space-pussy'): The cwtensor network flag. The likely choices are: -- local (local running network) -- space-pussy (main network) -- mock (mock network for testing.) If this option is set it overloads cwtensor.chain_endpoint with an entry point node from that network.chain_endpoint (str, default=None): The cwtensor endpoint flag. If set, overrides the network argument.
ct.metagraph
Chain state Torch interface
The Metagraph class holds the chain state of a particular subnetwork at a specific block.
Examples
# Creating metagraph and sync state from a netuid parameter, defaults to connecting to network `space-pussy`
=
# Create metagraph and sync with lite = False to sync weights and bonds matrices.
=
# Create metagraph and sync state from local entrypoint, assuming a space-pussy chain is currently running.
=
# Create an empty metagraph object with no state syncing.
=
# Sync the metagraph at a particular block
# Save the metagraph to ~/.cybertensor/metagraphs/network-$NETWORK_NAME/netuid-#NETUID/block-$BLOCK.pt
# Load the latest metagraph by block.
Methods
S
Returns the total stake.
R
Returns the ranks.
I
Returns the incentive.
E
Returns the emission.
C
Returns the consensus.
T
Returns the trust.
Tv
Returns the validator trust.
D
Returns the dividends.
B
Returns the bonds.
W
Returns the weights.
hotkeys
Returns the list of hotkeys for the axons.
coldkeys
Returns the list of coldkeys for the axons.
addresses
Returns the list of IP addresses for the axons.
str
Returns a string representation of the Metagraph.
repr
Returns the same string representation as __str__.
metadata
Returns a dictionary of Metagraph metadata.
init
Initializes a new instance of the Metagraph.
sync
Syncs the Metagraph state at the passed block. Optionally syncs the weights also.
save
Saves the Metagraph object's state_dict under bittensor root directory.
load
Loads the Metagraph object's state_dict from bittensor root directory.
load_from_path
Loads the Metagraph object's state_dict from the specified directory path.
ct.logging
The Logging interfaces with bittensor internal logging system.
Examples
# Turn on debug logs
# Turn on trace logs
# Turn off debug logs
# Turn off trace logs
# Turn on logging from class definition
# Instantiate logging from command line args
# Turn on logging to file
# Log
>>> 2023-05-29 09:27:25.426 | |
# Log using prefex suffix design
>>> 2023-05-29 09:27:47.184 | |