Bittensor Data Structure Decoder

0.8.0 · active · verified Wed Apr 15

bt-decode is a Python wrapper around the high-performance Rust `scale-codec` crate, designed for rapid scale-decoding of Bittensor data structures. As of version 0.8.0, it provides essential tools to decode various Bittensor-specific information, including `DelegateInfo`, `NeuronInfo`, `NeuronInfoLite`, and `SubnetInfo`. The library maintains an active development and release cadence, with frequent updates to ensure compatibility and introduce new features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a (mock) Bittensor subtensor connection and use `bt_decode.DelegateInfo.decode_from_bytes` to parse a raw hexadecimal byte string representing Bittensor delegate information into a structured Python object. This pattern is similar for other Bittensor data structures like `NeuronInfo`.

import bittensor
from bt_decode import DelegateInfo

# NOTE: For a real scenario, 'subtensor' would connect to a Bittensor network
# and 'hex_bytes_result' would be actual data fetched from the chain.
# This example uses placeholder data for demonstration.

# Setup a mock subtensor connection (in a real app, this would connect)
class MockSubtensor:
    def __init__(self):
        pass

    def get_delegated_v2(self, *args, **kwargs):
        # This is placeholder hex bytes for a DelegateInfo object
        # In a real scenario, this would come from a live Bittensor chain.
        # The actual bytes would vary.
        return "0x0c00000000000000000000000000000000000000000000000000000000000000010000000000000001000000000000000200000000000000020000000000000003000000000000000300000000000000"

subtensor = MockSubtensor()

# Assume we fetched raw hex bytes (e.g., from subtensor.get_delegated_v2())
# This is a simplified placeholder.
raw_hex_bytes = subtensor.get_delegated_v2() # Example call

# Decode the raw hex bytes using DelegateInfo
try:
    decoded_delegate_info = DelegateInfo.decode_from_bytes(bytes.fromhex(raw_hex_bytes[2:]))
    print(f"Successfully decoded DelegateInfo: {decoded_delegate_info}")
except Exception as e:
    print(f"Error decoding: {e}")

view raw JSON →