# commit-weight-hash (/docs/tx/commit-weight-hash)

Use this only with the legacy commit/reveal protocol, followed by
`RevealWeights` with the same mechanism, uids, values, salt, and version
key. Most validators should use `CommitWeights` for a timelocked commit
or `SetWeights` to select the subnet's configured path automatically.
With `for_hotkey`, the signing hotkey must be that validator's authorized
delegate on this mechanism; the delegate pays the normal transaction fee.

| Signer   | Origin                                 | Pallet          | Wraps                                                                                                                                                                                                                    |
| -------- | -------------------------------------- | --------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `hotkey` | signed account (pallet role may apply) | SubtensorModule | [`SubtensorModule.commit_mechanism_weights`](/code/pallets/subtensor/src/macros/dispatches.rs#L212-L221), [`SubtensorModule.commit_mechanism_weights_for`](/code/pallets/subtensor/src/macros/dispatches.rs#L3318-L3328) |

## Parameters [#parameters]

| Parameter     | Type    | Required | Description                                                                                                                                                                                   |
| ------------- | ------- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `netuid`      | integer | yes      | Subnet whose miners the weights score.                                                                                                                                                        |
| `commit_hash` | string  | yes      | Legacy weight commit hash (0x-prefixed H256).                                                                                                                                                 |
| `mechid`      | integer | no       | Mechanism index within the subnet. 0 is the default (and for most subnets the only) mechanism.                                                                                                |
| `for_hotkey`  | string  | no       | Validator hotkey to act for. Requires the hotkey to have authorized the signing hotkey as its weight delegate on this netuid and mechanism; normal transaction fees are paid by the delegate. |

Address parameters (`--hotkey`, `--coldkey`, `--dest`, ...) accept a raw ss58
address, an address-book or proxy-book name, or a local wallet/hotkey name.

## CLI [#cli]

Preview with `--dry-run` (shows fee, effects, and policy result without
submitting), then submit:

```bash
btcli tx commit-weight-hash \
  --netuid <int> \
  --commit-hash <value> --dry-run
btcli tx commit-weight-hash \
  --netuid <int> \
  --commit-hash <value> -w my_coldkey
```

## Python [#python]

```python
import bittensor as bt
from bittensor.wallet import Wallet

wallet = Wallet(name="my_coldkey", hotkey="my_hotkey")
intent = bt.CommitWeightHash(netuid=1, commit_hash="...")

sub = bt.Subtensor()
plan = sub.plan(intent, wallet)   # fee, effects, policy — no submission
result = sub.execute(intent, wallet)
if not result.success:
    print(result.error.code, result.error.remediation)
```

(`bt.Subtensor` is also the async client — `async with bt.Subtensor() as client:`
— see [The client](/docs/concepts/client).) Or build the intent by op name, as
an agent would:

```python
result = sub.execute_tool("commit_weight_hash", {...}, wallet)
```

## On-chain implementation [#on-chain-implementation]

`SubtensorModule.commit_mechanism_weights` — [`pallets/subtensor/src/macros/dispatches.rs#L214`](/code/pallets/subtensor/src/macros/dispatches.rs#L212-L221):

```rust
#[pallet::call_index(115)]
#[pallet::weight((<T as Config>::WeightInfo::commit_mechanism_weights(), DispatchClass::Normal, Pays::No))]
pub fn commit_mechanism_weights(
    origin: OriginFor<T>,
    netuid: NetUid,
    mecid: MechId,
    commit_hash: H256,
) -> DispatchResult {
    Self::do_commit_mechanism_weights(origin, netuid, mecid, commit_hash)
}
```

Delegates to [`do_commit_mechanism_weights`](/code/pallets/subtensor/src/subnets/weights.rs#L261).

`SubtensorModule.commit_mechanism_weights_for` — [`pallets/subtensor/src/macros/dispatches.rs#L3320`](/code/pallets/subtensor/src/macros/dispatches.rs#L3318-L3328):

```rust
#[pallet::call_index(172)]
#[pallet::weight((<T as Config>::WeightInfo::commit_mechanism_weights().saturating_add(T::DbWeight::get().reads(4)), DispatchClass::Normal, Pays::Yes))]
pub fn commit_mechanism_weights_for(
    origin: OriginFor<T>,
    netuid: NetUid,
    mecid: MechId,
    hotkey: T::AccountId,
    commit_hash: H256,
) -> DispatchResult {
    Self::do_commit_mechanism_weights_for(origin, netuid, mecid, hotkey, commit_hash)
}
```

Delegates to [`do_commit_mechanism_weights_for`](/code/pallets/subtensor/src/subnets/weights.rs#L91).

Every file is browsable under [/code](/code) exactly as built into the runtime, or as plain text under `/code/raw/<path>` (index: [`/code/index.json`](/code/index.json)).
