diff --git a/bittensor/core/subtensor.py b/bittensor/core/subtensor.py index 6862f3a1c4..bea5bb0095 100644 --- a/bittensor/core/subtensor.py +++ b/bittensor/core/subtensor.py @@ -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: -