Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion bittensor/core/subtensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,9 +1568,40 @@ def get_commitment(self, netuid: int, uid: int, block: Optional[int] = None) ->

Returns:
The commitment data as a string.

Example:
import bittensor as bt
import json

wallet = bt.Wallet()
subtensor = bt.Subtensor(network="test")
netuid = 1

# Realistic commitment data often includes versioning and content hashes
commitment_data = {
"version": "1.0.0",
"model_hash": "QmX...", # IPFS hash or similar
"timestamp": 1234567890
}

# Convert to string for storage
data_str = json.dumps(commitment_data)

# Set commitment
# Note: This requires the wallet to be a registered neuron on the subnet
subtensor.set_commitment(wallet=wallet, netuid=netuid, data=data_str)

# TODO: add a real example of how to handle realistic commitment data, or chop example
# Retrieve commitment
uid = 123
retrieved_data_str = subtensor.get_commitment(netuid=netuid, uid=uid)

if retrieved_data_str:
try:
# Parse back to dictionary
retrieved_data = json.loads(retrieved_data_str)
print(f"Retrieved version: {retrieved_data.get('version')}")
except json.JSONDecodeError:
print("Failed to decode commitment data")

Notes:
- <https://docs.learnbittensor.org/glossary#commit-reveal>
Expand Down