# terminate-lease (/docs/tx/terminate-lease)

Ends the lease and transfers full subnet ownership to the beneficiary:
contributor dividends stop and the subnet becomes an ordinary owned
subnet. Only the lease's beneficiary can call it, and only after the
lease's end block has passed — earlier attempts fail, and perpetual leases
(no end block) can never be terminated this way. Check the lease's end
block with the `lease` read before calling.

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

## Parameters [#parameters]

| Parameter     | Type    | Required | Description                                                                                |
| ------------- | ------- | -------- | ------------------------------------------------------------------------------------------ |
| `lease_id`    | integer | yes      | Lease to terminate (see the leases read).                                                  |
| `hotkey_ss58` | string  | no       | Beneficiary hotkey recorded as the subnet's owner hotkey; defaults to the wallet's hotkey. |

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 terminate-lease \
  --lease-id <int> --dry-run
btcli tx terminate-lease \
  --lease-id <int> -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.TerminateLease(lease_id=0)

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

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

`SubtensorModule.terminate_lease` — [`pallets/subtensor/src/macros/dispatches.rs#L1696`](/code/pallets/subtensor/src/macros/dispatches.rs#L1694-L1702):

```rust
#[pallet::call_index(111)]
#[pallet::weight(<T as crate::pallet::Config>::WeightInfo::terminate_lease(T::MaxContributors::get()))]
pub fn terminate_lease(
    origin: OriginFor<T>,
    lease_id: LeaseId,
    hotkey: T::AccountId,
) -> DispatchResultWithPostInfo {
    Self::do_terminate_lease(origin, lease_id, hotkey)
}
```

Delegates to [`do_terminate_lease`](/code/pallets/subtensor/src/subnets/leasing.rs#L181).

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