← 返回 Skills 市场
taoleeh

Bittensor SDK

作者 Taoli · GitHub ↗ · v1.0.2
cross-platform ⚠ suspicious
1084
总下载
1
收藏
0
当前安装
3
版本数
在 OpenClaw 中安装
/install bittensor-sdk
功能描述
Interact with the Bittensor blockchain to manage wallets, stake TAO, register neurons, query subnets/metagraphs, track emissions, and set neuron weights.
使用说明 (SKILL.md)

Bittensor SDK Skill

Comprehensive Bittensor blockchain interaction skill for agents. Enables seamless interaction with the Bittensor decentralized AI network through the Python SDK.

Overview

Bittensor is a decentralized machine learning network where independent subnets compete for TAO token emissions. This skill provides agents with full access to:

  • Wallet Management: Coldkey/hotkey operations, proxy relationships
  • Staking Operations: Stake/unstake TAO, auto-staking, safe staking
  • Subnet Management: Query subnet info, hyperparameters, registration
  • Neuron Operations: Register neurons, query metagraphs, weight management
  • Emissions & Rewards: Track emissions, claim root dividends, reward distribution

Key Concepts

Core Terminology

  • Coldkey: User's main wallet key for transfers and overall wallet management
  • Hotkey: Key used for neuron operations (mining/validation)
  • Netuid: Unique identifier for a subnet (0 = Root Subnet)
  • UID: Unique identifier for a neuron on a specific subnet
  • Metagraph: Complete state of a subnet at a given block
  • TAO: Base network token (1 TAO = 1e9 Rao)
  • Alpha: Subnet-specific token representing staked TAO
  • Rao: Smallest unit of TAO

Network Types

  • finney: Bittensor mainnet
  • test: Bittensor test network
  • local: Locally deployed blockchain

Installation

Prerequisites

pip install bittensor>=8.0.0

Opencode Installation

cp -r skills/bittensor-sdk ~/.opencode/skills/

How It Works

1. Initialization

The skill initializes the Subtensor interface for blockchain interaction:

import bittensor as bt

# Connect to mainnet
subtensor = bt.Subtensor(network="finney")

# Connect to testnet
subtensor = bt.Subtensor(network="test")

# Custom network with fallback endpoints
subtensor = bt.Subtensor(
    network="finney",
    fallback_endpoints=["wss://entrypoint-finney.opentensor.ai:443"],
    retry_forever=True
)

2. Wallet Setup

from bittensor import wallet

# Load existing wallet
wallet = bt.Wallet()

# Create new wallet
wallet = bt.Wallet(name="my_wallet", hotkey="miner1")

# Check balances
coldkey_balance = wallet.coldkey_balance
print(f"Coldkey balance: {coldkey_balance}")

3. Core Operations

Query Subnet Information

# Get all subnet netuids
netuids = subtensor.get_all_subnets_netuid()
print(f"Available subnets: {netuids}")

# Get detailed subnet info
subnet_info = subtensor.get_subnet_info(netuid=1)
print(f"Subnet 1 info: {subnet_info}")

Stake TAO

from bittensor import Balance

# Stake TAO to a hotkey
amount = Balance.from_tao(10.0)  # 10 TAO
result = subtensor.add_stake(
    wallet=wallet,
    netuid=1,
    hotkey_ss58="5Hx...",  # Hotkey SS58 address
    amount=amount,
    safe_staking=True,     # Enable price protection
    allow_partial_stake=True
)
print(f"Stake result: {result}")

Register Neuron

# Burned registration (recycle TAO)
result = subtensor.burned_register(
    wallet=wallet,
    netuid=1
)

# POW registration (computational proof)
result = subtensor.register(
    wallet=wallet,
    netuid=1
)

Query Metagraph

# Get metagraph for a subnet
metagraph = subtensor.metagraph(netuid=1)

print(f"Number of neurons: {metagraph.n}")
print(f"Stake per neuron: {metagraph.S}")
print(f"Rewards: {metagraph.R}")
print(f"Hotkeys: {metagraph.hotkeys}")

Set Weights

import numpy as np

# Validator sets weights for miners
uids = np.array([0, 1, 2, 3, 4])  # Miner UIDs
weights = np.array([0.2, 0.3, 0.2, 0.15, 0.15])  # Normalized weights

result = subtensor.set_weights(
    wallet=validator_wallet,
    netuid=1,
    uids=uids,
    weights=weights,
    wait_for_inclusion=True,
    wait_for_finalization=True
)

Usage Examples

Example 1: Complete Miner Setup

import bittensor as bt
from bittensor import Balance
import numpy as np

# Initialize
subtensor = bt.Subtensor(network="finney")
wallet = bt.Wallet(name="miner_wallet", hotkey="miner1")

# Check balance
balance = subtensor.get_balance(wallet.coldkey.ss58_address)
print(f"Balance: {balance.tao} TAO")

# Register on subnet 1
print("Registering neuron...")
result = subtensor.register(
    wallet=wallet,
    netuid=1,
    wait_for_inclusion=True
)

# Get metagraph info
metagraph = subtensor.metagraph(netuid=1)
print(f"Neurons on subnet 1: {metagraph.n}")

# Check my neuron
my_uid = metagraph.hotkeys.index(wallet.hotkey.ss58_address)
my_neuron = metagraph.neurons[my_uid]
print(f"My UID: {my_uid}")
print(f"My stake: {my_neuron.stake}")
print(f"My emission: {my_neuron.emission}")

Example 2: Validator Operations

import bittensor as bt
from bittensor import Balance
import numpy as np

# Initialize
subtensor = bt.Subtensor(network="finney")
validator_wallet = bt.Wallet(name="validator", hotkey="val1")

# Get metagraph
metagraph = subtensor.metagraph(netuid=1)
print(f"Total miners: {metagraph.n}")

# Calculate weights based on performance
weights = np.zeros(metagraph.n)
for i in range(metagraph.n):
    weights[i] = metagraph.R[i] * 0.7 + metagraph.S[i] * 0.3

# Normalize weights
weights = weights / weights.sum()

# Set weights
result = subtensor.set_weights(
    wallet=validator_wallet,
    netuid=1,
    uids=np.arange(metagraph.n),
    weights=weights,
    wait_for_inclusion=True,
    wait_for_finalization=True
)

print(f"Weights set: {result.success}")

Troubleshooting

Connection Issues

Problem: Unable to connect to network Solution:

# Use fallback endpoints
subtensor = bt.Subtensor(
    network="finney",
    fallback_endpoints=[
        "wss://entrypoint-finney.opentensor.ai:443",
        "wss://finney.opentensor.io:443"
    ],
    retry_forever=True
)

Rate Limiting

Problem: Too many requests error Solution:

import time
time.sleep(1)  # Rate limit delays

Registration Failures

Problem: Registration fails repeatedly Solutions:

  1. Check balance (need > 1 TAO for burn registration)
  2. Verify POW solution is correct
  3. Check network connectivity
  4. Try different registration method

Wallet Issues

Problem: Wallet not found Solution:

# Create new wallet
wallet = bt.Wallet(name="new_wallet", hotkey="new_hotkey")
wallet.create_if_non_existing()

Best Practices

  1. Always close connections: Use subtensor.close() when done
  2. Handle errors gracefully: Use try-except blocks
  3. Implement rate limiting: Don't exceed network limits
  4. Use MEV protection: Enable for large transactions
  5. Monitor emissions: Track network health
  6. Use safe staking: Enable price protection
  7. Keep keys secure: Never expose private keys

Security Considerations

  1. Private keys: Never expose or log private keys
  2. Seed phrases: Store securely, never share
  3. Transaction signing: Always verify before signing
  4. MEV protection: Enable for large transactions
  5. Proxy permissions: Understand proxy types before delegating
  6. Rate limiting: Prevent DoS by respecting limits

Present Results to Users

When presenting Bittensor SDK results to users:

  1. Format TAO amounts clearly: Show both TAO and Rao when relevant
  2. Explain network concepts: Clarify coldkey/hotkey, netuid, UID for non-technical users
  3. Highlight key metrics: Emphasize important values like stake, emission, registration costs
  4. Include relevant links: Link to documentation for deeper exploration
  5. Note risks: Highlight potential issues like deregistration risk, rate limits

Example output format:

=== Subnet 1 Status ===
Neurons: 256 registered
Total Stake: 125,450.5 TAO
Emission: 0.123 TAO/block
Registration Cost: 5.2 TAO
Validator Take: 18%
═══════════════════════════════════

References

Detailed Documentation

For complete API reference, extended examples, and comprehensive troubleshooting, see:

安全使用建议
This skill can perform real blockchain operations (staking, registering neurons, sending transactions) which require private keys/private wallet files for signing. Before installing or using it: (1) Confirm where bt.Wallet() will look for keys on your system and ensure you do not expose coldkeys or other sensitive files to the agent. (2) Prefer using a read-only / watch-only wallet or a testnet account with no real funds for initial testing. (3) Require explicit user confirmation before sending any transaction and avoid granting the agent direct filesystem access to wallet directories. (4) Verify the bittensor Python package source/version you install (pip source, checksums) and the network endpoints the skill will use. If you cannot guarantee the agent will not access local private keys, treat this skill as high-risk and do not use it with production funds.
功能分析
Type: OpenClaw Skill Name: bittensor-sdk Version: 1.0.2 The OpenClaw AgentSkills skill bundle for 'bittensor-sdk' is designed for comprehensive interaction with the Bittensor blockchain. Analysis of `_meta.json`, `SKILL.md`, and `references/API_REFERENCE.md` reveals no evidence of intentional harmful behavior. The `SKILL.md` provides legitimate instructions for installing the bittensor Python package and using its SDK for wallet management, staking, subnet operations, and neuron registration. The `references/API_REFERENCE.md` details the SDK's functions, all of which are standard blockchain interaction methods. There are no signs of data exfiltration, malicious execution, persistence, obfuscation, or prompt injection against the agent with harmful objectives. The skill's capabilities are aligned with its stated purpose as a Bittensor SDK.
能力评估
Purpose & Capability
The SKILL.md describes a Bittensor SDK that performs wallet, staking, subnet, neuron, and emission operations and instructs use of the bittensor Python package and network endpoints — these requirements align with the stated purpose.
Instruction Scope
Runtime instructions show performing sensitive actions (creating/loading wallets, staking, registering neurons, setting weights, submitting extrinsics). The document does not explicitly describe how private keys are provided, but bt.Wallet() calls will typically read local wallet/key files or require secret material for signing. The instructions give the agent broad ability to perform on-chain transactions (which can transfer or lock funds) without describing safeguards or explicit user approval flows.
Install Mechanism
No install spec or downloaded code is included; this is instruction-only and only requires installing a public Python package (bittensor>=8.0.0) which is a normal, low-risk install pattern. No unknown URLs or archive extracts are present.
Credentials
The skill declares no required environment variables or config paths, yet its functionality inherently requires access to private keys/wallet files and network endpoints. Not declaring that it will access local wallet stores (or require secrets) is a mismatch and raises the risk the agent will access sensitive local files or secret material without explicit declaration or user consent.
Persistence & Privilege
always is false and there is no install spec that would persist code or change other skills or system-wide settings. The skill does not request persistent presence or elevated privileges in the provided metadata.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install bittensor-sdk
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /bittensor-sdk 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.2
Changes the API_REFERENCE.md to cover the entire SDK.
v1.0.1
Removed script references.
v1.0.0
Bittensor SDK Skill 1.0.0 initial release - Provides comprehensive interaction with the Bittensor decentralized AI network via Python SDK. - Supports wallet creation, management, and querying of balances. - Enables staking, unstaking, safe staking, and auto-staking TAO tokens. - Includes functionality for registering neurons, subnet management, metagraph analysis, and weight setting. - Adds scripts for subnet info, stake, unstake, neuron queries, delegate listings, and wallet operations. - Extensive documentation and troubleshooting for typical network, registration, and wallet issues.
元数据
Slug bittensor-sdk
版本 1.0.2
许可证
累计安装 0
当前安装数 0
历史版本数 3
常见问题

Bittensor SDK 是什么?

Interact with the Bittensor blockchain to manage wallets, stake TAO, register neurons, query subnets/metagraphs, track emissions, and set neuron weights. 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 1084 次。

如何安装 Bittensor SDK?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install bittensor-sdk」即可一键安装,无需额外配置。

Bittensor SDK 是免费的吗?

是的,Bittensor SDK 完全免费(开源免费),可自由下载、安装和使用。

Bittensor SDK 支持哪些平台?

Bittensor SDK 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 Bittensor SDK?

由 Taoli(@taoleeh)开发并维护,当前版本 v1.0.2。

💬 留言讨论