bittensor-rs
A standalone Rust SDK for interacting with the Bittensor blockchain network.
Features
- Connection Pooling - Automatic connection management with health checks, failover, and circuit breaker patterns
- Wallet Management - Load wallets, sign transactions, and manage keys compatible with the Bittensor CLI
- Chain Queries - Query metagraph data, neuron information, subnet details, balances, and stake
- Extrinsics - Submit transactions for staking, weight setting, registration, transfers, and more
- Retry Logic - Built-in exponential backoff with configurable retry strategies
- Type-Safe API - Strongly typed interfaces generated from Bittensor chain metadata
Installation
Add to your Cargo.toml:
[]
= "0.1"
Quick Start
use ;
async
Configuration
The SDK supports multiple network configurations:
use BittensorConfig;
// Finney mainnet
let config = finney;
// Test network
let config = testnet;
// Local development
let config = local;
// Custom endpoint with connection pool settings
let config = finney
.with_endpoint
.with_pool_size
.with_read_only;
Core Modules
Chain Queries
use ;
// Get the full metagraph for a subnet
let metagraph = get_metagraph.await?;
// Query account balance
let balance = get_balance.await?;
// Get neuron info by UID
let neuron = get_neuron.await?;
// Get subnet hyperparameters
let info = get_subnet_info.await?;
Extrinsics (Transactions)
use ;
// Set weights on a subnet
let params = WeightsParams ;
set_weights.await?;
// Add stake to a hotkey
let params = StakeParams ;
add_stake.await?;
// Transfer TAO
let params = TransferParams ;
transfer.await?;
Wallet Management
use Wallet;
// Load an existing wallet from ~/.bittensor/wallets
let wallet = load?;
// Get the hotkey address
println!;
// Sign arbitrary data
let signature = wallet.sign;
// Create from mnemonic
let wallet = from_mnemonic?;
Connection Management
The SDK includes robust connection handling:
use ;
// Build a connection pool with custom settings
let pool = new
.max_connections
.retry_config
.build;
// Get connection metrics
let metrics = service.connection_metrics.await;
println!;
// Force reconnection if needed
service.force_reconnect.await?;
Error Handling
The SDK provides detailed error types with retry classification:
use ;
match service.get_metagraph.await
Feature Flags
| Feature | Description | Default |
|---|---|---|
wallet |
Enable wallet management functionality | ✓ |
generate-metadata |
Build-time metadata generation |
Supported Operations
Queries
get_metagraph/get_selective_metagraph- Subnet metagraph dataget_neuron/get_neuron_lite- Neuron informationget_balance/get_stake- Account balancesget_subnet_info/get_subnet_hyperparameters- Subnet configurationget_total_subnets/subnet_exists- Subnet enumeration
Extrinsics
- Staking:
add_stake,remove_stake,delegate_stake,undelegate_stake - Weights:
set_weights,commit_weights,reveal_weights - Transfer:
transfer,transfer_keep_alive,transfer_all - Registration:
serve_axon,serve_prometheus,burned_register - Subnet:
register_network,set_subnet_identity - Children:
set_children,set_childkey_take,revoke_children - Root:
root_register,set_root_weights
Requirements
- Rust 1.70 or later
- Tokio runtime
License
MIT License - see LICENSE for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.