# spend-gamma (/docs/tx/spend-gamma)

Spends, in order, each entry's `amount_gamma` from the deposit at its
`hotkey_ss58`. Entries whose hotkey has no deposit, whose deposit you are
not the spender of, or whose amount is zero or above the deposit's balance
or what its daily spend cap allows, are skipped. Spent gamma is destroyed.
Each entry's optional `reference`, 32 bytes as hex, is repeated in its
`GammaSpent` or `GammaSpendSkipped` event; by convention it is the
service's own id for the request it pays for, returned with its response.
Sign as the spender, or as its `GammaSpend` proxy. The result's
`data["spent"]` lists, in order, each entry that spent, with its
`hotkey_ss58`, `amount_gamma` and `reference`, and
`data["skipped"]` each entry that was skipped, with the chain error that
skipped it as `reason`.

| Signer    | Origin                                 | Pallet          | Wraps                                                                                         |
| --------- | -------------------------------------- | --------------- | --------------------------------------------------------------------------------------------- |
| `coldkey` | signed account (pallet role may apply) | SubtensorModule | [`SubtensorModule.spend_gamma`](/code/pallets/subtensor/src/macros/dispatches.rs#L3328-L3345) |

## Parameters [#parameters]

| Parameter | Type            | Required | Description                                                                                              |
| --------- | --------------- | -------- | -------------------------------------------------------------------------------------------------------- |
| `netuid`  | integer         | yes      | Subnet of the deposits.                                                                                  |
| `spends`  | array of object | yes      | One to 512 objects of hotkey\_ss58, amount\_gamma and an optional 32-byte hex reference, spent in order. |

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 spend-gamma \
  --netuid <int> \
  --spends '<json>' --dry-run
btcli tx spend-gamma \
  --netuid <int> \
  --spends '<json>' -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.SpendGamma(netuid=1, spends=[...])

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("spend_gamma", {...}, wallet)
```

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

`SubtensorModule.spend_gamma` — [`pallets/subtensor/src/macros/dispatches.rs#L3330`](/code/pallets/subtensor/src/macros/dispatches.rs#L3328-L3345):

```rust
#[pallet::call_index(164)]
#[pallet::weight((<T as Config>::WeightInfo::spend_gamma(spends.len() as u32), DispatchClass::Normal, Pays::Yes))]
pub fn spend_gamma(
    origin: OriginFor<T>,
    netuid: NetUid,
    spends: BoundedVec<(T::AccountId, GammaBalance, [u8; 32]), ConstU32<MAX_GAMMA_SPENDS>>,
) -> DispatchResultWithPostInfo {
    let spent = Self::do_spend_gamma(origin, netuid, &spends)?;
    let skipped = (spends.len() as u32).saturating_sub(spent);
    Ok((
        Some(
            <T as Config>::WeightInfo::spend_gamma(spends.len() as u32)
                .saturating_sub(T::DbWeight::get().writes(skipped.into())),
        ),
        Pays::Yes,
    )
        .into())
}
```

Delegates to [`do_spend_gamma`](/code/pallets/subtensor/src/subnets/gamma.rs#L434).

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)).
