This directory contains comprehensive examples demonstrating how to use the Bittensor Rust SDK. Each example is self-contained and can be run independently.
Before running the examples, ensure you have:
- Rust 1.70 or higher installed
- Network connectivity to a Bittensor RPC endpoint
- (Optional) Set
BITTENSOR_RPCenvironment variable for custom endpoint (defaults to Finney)
Execute any example using cargo:
cargo run --example <example_name>For custom RPC endpoint:
BITTENSOR_RPC=wss://your-endpoint:443 cargo run --example chain_infoQuery fundamental blockchain information including block height, runtime version, and chain properties.
cargo run --example chain_infoOutput includes:
- Current block number
- Chain name and properties
- Runtime version
- Token decimals and symbols
Query wallet balances and account information for single or multiple addresses.
cargo run --example walletsFeatures:
- Query balance for specific addresses
- Display free, reserved, and frozen balance
- Support for SS58 address format
List all subnets on the network with their configuration and statistics.
cargo run --example subnetsDisplays:
- Subnet ID and owner
- Network parameters (tempo, emission ratio)
- Registration status and costs
- Number of neurons
Query and display individual neuron information within subnets.
cargo run --example neuronsShows:
- Neuron UID and addresses (hotkey/coldkey)
- Stake amounts and distribution
- Performance metrics (rank, trust, consensus)
- Network endpoints (axon/prometheus)
Display subnet metagraph in a formatted table showing key metrics.
cargo run --example metagraphOutput format:
- Tabular view of all neurons
- Stake, rank, trust, consensus values
- Active status and validator permits
- Emission rates
Query delegate information and analyze delegation patterns.
cargo run --example delegatesShows:
- Delegate addresses and metadata
- Total stake and nominator count
- Commission rates (take)
- Return calculations
Interact with governance voting system and proposals.
cargo run --example votingFeatures:
- List active proposals
- Query vote counts
- Check senate membership
- Display voting history
Query weight commitment data for commit-reveal schemes.
cargo run --example commitmentsDisplays:
- Current commitments
- Reveal status
- Block numbers for commits
Query and display on-chain identity information.
cargo run --example identityShows:
- Identity fields (name, email, web, etc.)
- Verification status
- Identity judgements
Query liquidity pool information and swap calculations.
cargo run --example liquidityFeatures:
- Pool reserves
- Swap rate calculations
- Liquidity provider information
BITTENSOR_RPC- RPC endpoint override. All examples and integration tests default to the Finney mainnet entrypoint (wss://entrypoint-finney.opentensor.ai:443). Set this to use testnet, local, or archive nodes:# Use local node BITTENSOR_RPC=ws://127.0.0.1:9944 cargo run --example chain_info # Use testnet BITTENSOR_RPC=wss://test.finney.opentensor.ai:443 cargo run --example chain_info
SEED- Random seed for subnet selection in examples
All examples implement proper error handling:
match result {
Ok(data) => process_data(data),
Err(e) => eprintln!("Error: {}", e),
}All examples use BittensorClient::with_default() which connects to the Finney mainnet by default (wss://entrypoint-finney.opentensor.ai:443). Override with BITTENSOR_RPC to point at a different endpoint (testnet, local, archive):
// Connects to Finney by default; override with BITTENSOR_RPC env var
let client = BittensorClient::with_default().await?;
// Multiple queries using same clientExamples use SS58 encoding for display:
use sp_core::crypto::Ss58Codec;
println!("Address: {}", account_id.to_ss58check());To create new examples:
- Create a new file in
examples/directory - Add the example to
Cargo.tomlif needed - Follow the established patterns for error handling and output formatting
- Document the example purpose and usage
- Use bulk query functions when fetching multiple items
- Cache results when appropriate
- Consider rate limiting for continuous monitoring
- Prefer specific queries over fetching all data
- Verify RPC endpoint is accessible
- Check network connectivity
- Ensure WebSocket support for WSS endpoints
- Update to latest SDK version
- Verify runtime compatibility
- Check for network upgrades
- Use bulk query examples as reference
- Implement caching for repeated queries
- Consider concurrent fetching patterns