# add-stake (/docs/tx/add-stake)

Swaps TAO from the coldkey's free balance into the subnet's alpha at the
current pool price and credits the result to your stake on the hotkey; on
netuid 0 (root) the stake stays TAO-denominated. The swap moves the pool,
so large amounts incur slippage. By default the call is slippage-protected:
it fails (`SlippageTooHigh`) instead of filling once the price rises more
than `rate_tolerance` (5%) above the price at submission — raise the
tolerance or set `slippage_protection` to False to execute at any price,
or use `add_stake_limit` to set an explicit limit price. The position's
value then follows the pool price and the validator's performance, and can
be exited later with `remove_stake`. Fails if the coldkey's free balance
cannot cover the amount plus the transaction fee, and with `AmountTooLow`
when the amount is below the chain minimum of 0.002 TAO plus the swap fee.
Dynamic subnets also reject a single swap larger than 1000x the pool's TAO
reserve (`InsufficientLiquidity`).

| Signer    | Origin                                 | Pallet          | Wraps                                                                                                                                                                                        |
| --------- | -------------------------------------- | --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `coldkey` | signed account (pallet role may apply) | SubtensorModule | [`SubtensorModule.add_stake`](/code/pallets/subtensor/src/macros/dispatches.rs#L559-L568), [`SubtensorModule.add_stake_limit`](/code/pallets/subtensor/src/macros/dispatches.rs#L1391-L1410) |

## Parameters [#parameters]

| Parameter             | Type              | Required | Description                                                                                                                                                                                                                        |
| --------------------- | ----------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `hotkey_ss58`         | string            | yes      | Hotkey the stake is added to (the validator you are backing).                                                                                                                                                                      |
| `netuid`              | integer           | yes      | Subnet the stake lives on (netuid 0 is the root network).                                                                                                                                                                          |
| `amount_tao`          | number \| `"all"` | yes      | How much of the coldkey's free balance to stake.                                                                                                                                                                                   |
| `slippage_protection` | boolean           | no       | Bound the price the swap may execute at (on by default): the call fails (`SlippageTooHigh`) instead of filling once the pool price moves more than `rate_tolerance` from the price at submission. Disable to execute at any price. |
| `rate_tolerance`      | number            | no       | Maximum price move slippage protection accepts, as a fraction (0.05 = 5%). Ignored when slippage protection is disabled.                                                                                                           |

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 add-stake \
  --hotkey <ss58|name> \
  --netuid <int> \
  --amount-tao <amount|all> --dry-run
btcli tx add-stake \
  --hotkey <ss58|name> \
  --netuid <int> \
  --amount-tao <amount|all> -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.AddStake(hotkey_ss58="5F...", netuid=1, amount_tao=1.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("add_stake", {...}, wallet)
```

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

`SubtensorModule.add_stake` — [`pallets/subtensor/src/macros/dispatches.rs#L561`](/code/pallets/subtensor/src/macros/dispatches.rs#L559-L568):

```rust
#[pallet::call_index(2)]
#[pallet::weight(<T as crate::pallet::Config>::WeightInfo::add_stake())]
pub fn add_stake(
    origin: OriginFor<T>,
    hotkey: T::AccountId,
    netuid: NetUid,
    amount_staked: TaoBalance,
) -> DispatchResult {
    Self::do_add_stake(origin, hotkey, netuid, amount_staked).map(|_| ())
}
```

Delegates to [`do_add_stake`](/code/pallets/subtensor/src/staking/add_stake.rs#L30).

`SubtensorModule.add_stake_limit` — [`pallets/subtensor/src/macros/dispatches.rs#L1393`](/code/pallets/subtensor/src/macros/dispatches.rs#L1391-L1410):

```rust
#[pallet::call_index(88)]
#[pallet::weight(<T as crate::pallet::Config>::WeightInfo::add_stake_limit())]
pub fn add_stake_limit(
    origin: OriginFor<T>,
    hotkey: T::AccountId,
    netuid: NetUid,
    amount_staked: TaoBalance,
    limit_price: TaoBalance,
    allow_partial: bool,
) -> DispatchResult {
    Self::do_add_stake_limit(
        origin,
        hotkey,
        netuid,
        amount_staked,
        limit_price,
        allow_partial,
    )
    .map(|_| ())
}
```

Delegates to [`do_add_stake_limit`](/code/pallets/subtensor/src/staking/add_stake.rs#L95).

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