| Crates.io | bittensor-rs |
| lib.rs | bittensor-rs |
| version | 0.1.1 |
| created_at | 2025-12-27 23:50:16.012693+00 |
| updated_at | 2025-12-27 23:58:50.976167+00 |
| description | Standalone Rust SDK for Bittensor blockchain interactions |
| homepage | https://github.com/one-covenant/bittensor-rs |
| repository | https://github.com/one-covenant/bittensor-rs |
| max_upload_size | |
| id | 2008043 |
| size | 7,014,310 |
A standalone Rust SDK for interacting with the Bittensor blockchain network.
Add to your Cargo.toml:
[dependencies]
bittensor-rs = "0.1"
use bittensor::{config::BittensorConfig, Service};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create configuration for Finney mainnet
let config = BittensorConfig::finney("my_wallet", "my_hotkey", 1);
// Initialize the service (connects to the chain)
let service = Service::new(config).await?;
// Query the metagraph
let metagraph = service.get_metagraph(1).await?;
println!("Found {} neurons on subnet 1", metagraph.hotkeys.len());
// Get current block
let block = service.get_block_number().await?;
println!("Current block: {}", block);
Ok(())
}
The SDK supports multiple network configurations:
use bittensor::config::BittensorConfig;
// Finney mainnet
let config = BittensorConfig::finney("wallet", "hotkey", 1);
// Test network
let config = BittensorConfig::testnet("wallet", "hotkey", 1);
// Local development
let config = BittensorConfig::local("wallet", "hotkey", 1);
// Custom endpoint with connection pool settings
let config = BittensorConfig::finney("wallet", "hotkey", 1)
.with_endpoint("wss://custom-endpoint.com:443")
.with_pool_size(5)
.with_read_only(true);
use bittensor::{get_metagraph, get_balance, get_neuron, get_subnet_info};
// Get the full metagraph for a subnet
let metagraph = get_metagraph(&client, netuid).await?;
// Query account balance
let balance = get_balance(&client, &account_id).await?;
// Get neuron info by UID
let neuron = get_neuron(&client, netuid, uid).await?;
// Get subnet hyperparameters
let info = get_subnet_info(&client, netuid).await?;
use bittensor::extrinsics::{
set_weights, add_stake, transfer, serve_axon,
WeightsParams, StakeParams, TransferParams, ServeAxonParams,
};
// Set weights on a subnet
let params = WeightsParams {
netuid: 1,
uids: vec![0, 1, 2],
weights: vec![100, 200, 300],
version_key: 0,
};
set_weights(&client, &signer, params).await?;
// Add stake to a hotkey
let params = StakeParams {
hotkey: hotkey_account,
amount_rao: 1_000_000_000, // 1 TAO
};
add_stake(&client, &signer, params).await?;
// Transfer TAO
let params = TransferParams {
dest: destination_account,
amount_rao: 500_000_000,
};
transfer(&client, &signer, params).await?;
use bittensor::wallet::Wallet;
// Load an existing wallet from ~/.bittensor/wallets
let wallet = Wallet::load("my_wallet", "my_hotkey")?;
// Get the hotkey address
println!("Hotkey: {}", wallet.hotkey());
// Sign arbitrary data
let signature = wallet.sign(b"message to sign");
// Create from mnemonic
let wallet = Wallet::from_mnemonic("wallet", "hotkey", "word1 word2 ...")?;
The SDK includes robust connection handling:
use bittensor::{ConnectionPool, ConnectionPoolBuilder, HealthChecker};
// Build a connection pool with custom settings
let pool = ConnectionPoolBuilder::new(endpoints)
.max_connections(5)
.retry_config(RetryConfig::network())
.build();
// Get connection metrics
let metrics = service.connection_metrics().await;
println!("Healthy connections: {}/{}",
metrics.healthy_connections,
metrics.total_connections);
// Force reconnection if needed
service.force_reconnect().await?;
The SDK provides detailed error types with retry classification:
use bittensor::{BittensorError, ErrorCategory};
match service.get_metagraph(1).await {
Ok(metagraph) => { /* success */ }
Err(e) => {
match e.category() {
ErrorCategory::Transient => {
// Retry with backoff
}
ErrorCategory::Network => {
// Network issues, try reconnecting
}
ErrorCategory::Permanent => {
// Don't retry
}
_ => {}
}
}
}
| Feature | Description | Default |
|---|---|---|
wallet |
Enable wallet management functionality | ✓ |
generate-metadata |
Build-time metadata generation |
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 enumerationadd_stake, remove_stake, delegate_stake, undelegate_stakeset_weights, commit_weights, reveal_weightstransfer, transfer_keep_alive, transfer_allserve_axon, serve_prometheus, burned_registerregister_network, set_subnet_identityset_children, set_childkey_take, revoke_childrenroot_register, set_root_weightsMIT License - see LICENSE for details.
Contributions are welcome! Please feel free to submit a Pull Request.