> ## Documentation Index
> Fetch the complete documentation index at: https://docs.near.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Validator Staking

> Learn how to stake NEAR, delegate to validators, track rewards, and withdraw staked tokens safely.

export const TryOutOnLantstool = ({path, user = 'lantstool', repo = 'examples.near-protocol', branch = 'main'}) => {
  const lantstoolUrl = `https://app.lantstool.dev/import/gh/${user}/${repo}/${branch}/${path}`;
  const githubUrl = `https://github.com/${user}/${repo}/blob/${branch}/${path}`;
  const [code, setCode] = useState(null);
  function toRaw(ref) {
    const [org, repoName, , branchName, ...pathSeg] = new URL(ref).pathname.split('/').slice(1);
    return `https://raw.githubusercontent.com/${org}/${repoName}/${branchName}/${pathSeg.join('/')}`;
  }
  useEffect(() => {
    const rawUrl = toRaw(githubUrl);
    (async () => {
      try {
        let res;
        const validUntil = typeof window !== 'undefined' && localStorage.getItem(`${rawUrl}-until`);
        if (validUntil && Number(validUntil) > Date.now()) {
          res = localStorage.getItem(rawUrl);
        }
        if (!res) {
          res = await (await fetch(rawUrl)).text();
          if (typeof window !== 'undefined') {
            localStorage.setItem(rawUrl, res);
            localStorage.setItem(`${rawUrl}-until`, String(Date.now() + 60000));
          }
        }
        setCode(res);
      } catch {
        setCode('Error fetching code, please try reloading');
      }
    })();
  }, [githubUrl]);
  return <div>
      <p>
        Try it out on{' '}
        <a href={lantstoolUrl} target="_blank" rel="noopener noreferrer">
          Lantstool
        </a>
      </p>
      <div className="rounded-[0.625rem] border border-[#d0d7de] dark:border-[#30363d] overflow-hidden my-3 text-[0.8125rem] font-mono shadow-sm dark:shadow-[0_4px_24px_rgba(0,0,0,0.18)]">
        <div className="flex items-center gap-2 py-2 px-[0.875rem] bg-[#f6f8fa] dark:bg-[#161b22] border-b border-[#d0d7de] dark:border-[#30363d]">
          <svg width="15" height="15" viewBox="0 0 24 24" fill="currentColor" className="text-[#656d76] dark:text-[#8b949e]">
            <path d="M12 0C5.37 0 0 5.37 0 12c0 5.31 3.435 9.795 8.205 11.385.6.105.825-.255.825-.57 0-.285-.015-1.23-.015-2.235-3.015.555-3.795-.735-4.035-1.41-.135-.345-.72-1.41-1.23-1.695-.42-.225-1.02-.78-.015-.795.945-.015 1.62.87 1.845 1.23 1.08 1.815 2.805 1.305 3.495.99.105-.78.42-1.305.765-1.605-2.67-.3-5.46-1.335-5.46-5.925 0-1.305.465-2.385 1.23-3.225-.12-.3-.54-1.53.12-3.18 0 0 1.005-.315 3.3 1.23.96-.27 1.98-.405 3-.405s2.04.135 3 .405c2.295-1.56 3.3-1.23 3.3-1.23.66 1.65.24 2.88.12 3.18.765.84 1.23 1.905 1.23 3.225 0 4.605-2.805 5.625-5.475 5.925.435.375.81 1.095.81 2.22 0 1.605-.015 2.895-.015 3.3 0 .315.225.69.825.57A12.02 12.02 0 0 0 24 12c0-6.63-5.37-12-12-12z" />
          </svg>
          <span className="text-xs font-medium text-[#1f2328] dark:text-[#e6edf3]">
            {githubUrl.split('/').pop()}
          </span>
        </div>
        <div className="overflow-auto max-h-[480px] bg-white dark:bg-[#0d1117] [&_tr]:border-b-0 [&_td]:border-b-0">
          {code === null ? <div className="py-5 px-4 text-xs text-[#656d76] dark:text-[#6e7681]">Loading...</div> : <table className="w-full border-collapse leading-[1.6]">
              <tbody>
                {code.split('\n').map((line, i) => <tr key={i} className="align-top border-0">
                    <td style={{
    minWidth: '60px'
  }} className="select-none pl-2 pr-3 text-right text-[0.7rem] text-[#8c959f] dark:text-[#3d444d] w-[1%] whitespace-nowrap border-r border-0 border-r-[#d0d7de] dark:border-r-[#21262d]">
                      {i + 1}
                    </td>
                    <td className="pl-4 pr-6 text-[0.8125rem] text-[#1f2328] dark:text-[#e6edf3] whitespace-pre">
                      {line || ' '}
                    </td>
                  </tr>)}
              </tbody>
            </table>}
        </div>
      </div>
    </div>;
};

NEAR uses a Proof-of-Stake (PoS), meaning that users chose the active node validators by delegating their tokens to them.

In this article you'll find a detailed explanation of the staking process, including delegating, viewing balances, and withdrawing using the [NEAR CLI](../../tools/cli).

<Note>
  **Contract source code**

  You can review the Staking pool smart contract source code in [this GitHub repository](https://github.com/near/core-contracts/tree/master/staking-pool).
</Note>

***

## Delegate NEAR tokens

Before delegating, you need to choose a validator (a node that participates in staking).

Check [NearBlocks](https://nearblocks.io/node-explorer), [Pikespeak](https://pikespeak.ai/validators/overview) or [Near Staking](https://near-staking.com/), and look for validators with a good track record, uptime, and reasonable commission rates.

<Accordion title="List validators using CLI">
  If you prefer, you can get the list of current validators by using the [`near-validator`](../../tools/cli#validator-extension) CLI:

  ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
  near-validator validators network-config mainnet now
  ```
</Accordion>

### Stake Tokens

<Tabs>
  <Tab title="Staking CLI">
    ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
    near staking delegation <user-account.near> deposit-and-stake '100 NEAR' <my_validator> network-config mainnet sign-with-keychain
    ```
  </Tab>

  <Tab title="Function Call">
    ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
    near call <my_validator> deposit_and_stake --useAccount <user-account.near> --deposit 100
    ```
  </Tab>

  <Tab title="Lantstool" icon="https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/docs/tools/lantstool-logo-circle.svg?fit=max&auto=format&n=qO2GD-gji1aakHqN&q=85&s=e40405f8a9eda7a97dd89b9cc07a9ca9" width="100" height="100" data-path="assets/docs/tools/lantstool-logo-circle.svg">
    <TryOutOnLantstool path="docs/2.build/5.primitives/staking/deposit-and-stake.json" />
  </Tab>
</Tabs>

<Tip>
  You will start earning staking rewards after the next epoch (approximately 12 hours)
</Tip>

### Staked Balance

To check your staked balance on the `<my_validator>` pool for the `<user-account.near>` account, run the following command:

<Tabs>
  <Tab title="Staking CLI">
    ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
    near staking delegation <user-account.near> view-balance <my_validator> network-config mainnet now
    ```
  </Tab>

  <Tab title="Function Call">
    ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
    near view <my_validator> get_account_staked_balance '{"account_id": "<user-account.near>"}'
    ```
  </Tab>

  <Tab title="Lantstool" icon="https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/docs/tools/lantstool-logo-circle.svg?fit=max&auto=format&n=qO2GD-gji1aakHqN&q=85&s=e40405f8a9eda7a97dd89b9cc07a9ca9" width="100" height="100" data-path="assets/docs/tools/lantstool-logo-circle.svg">
    <TryOutOnLantstool path="docs/2.build/5.primitives/staking/account-staked-balance.json" />
  </Tab>
</Tabs>

<Accordion title="Staking pool balances">
  You can view additional information and balances from the staking pool using the following CLI commands:

  #### Total staked balance of the entire pool

  <Tabs>
    <Tab title="🖥️ CLI">
      ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
      near view <my_validator> get_total_staked_balance '{}'
      ```
    </Tab>

    <Tab title="Lantstool" icon="https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/docs/tools/lantstool-logo-circle.svg?fit=max&auto=format&n=qO2GD-gji1aakHqN&q=85&s=e40405f8a9eda7a97dd89b9cc07a9ca9" width="100" height="100" data-path="assets/docs/tools/lantstool-logo-circle.svg">
      <TryOutOnLantstool path="docs/2.build/5.primitives/staking/pool-total-staked-balance.json" />
    </Tab>
  </Tabs>

  #### Owner of the staking pool

  <Tabs>
    <Tab title="🖥️ CLI">
      ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
      near view <my_validator> get_owner_id '{}'
      ```
    </Tab>

    <Tab title="Lantstool" icon="https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/docs/tools/lantstool-logo-circle.svg?fit=max&auto=format&n=qO2GD-gji1aakHqN&q=85&s=e40405f8a9eda7a97dd89b9cc07a9ca9" width="100" height="100" data-path="assets/docs/tools/lantstool-logo-circle.svg">
      <TryOutOnLantstool path="docs/2.build/5.primitives/staking/pool-owner.json" />
    </Tab>
  </Tabs>

  #### Current reward fee

  <Tabs>
    <Tab title="🖥️ CLI">
      ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
      near view <my_validator> get_reward_fee_fraction '{}'
      ```
    </Tab>

    <Tab title="Lantstool" icon="https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/docs/tools/lantstool-logo-circle.svg?fit=max&auto=format&n=qO2GD-gji1aakHqN&q=85&s=e40405f8a9eda7a97dd89b9cc07a9ca9" width="100" height="100" data-path="assets/docs/tools/lantstool-logo-circle.svg">
      <TryOutOnLantstool path="docs/2.build/5.primitives/staking/reward-fee.json" />
    </Tab>
  </Tabs>

  #### Owner's balance

  <Tabs>
    <Tab title="🖥️ CLI">
      ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
      near view <my_validator> get_account_total_balance '{"account_id": "owner"}'
      ```
    </Tab>

    <Tab title="Lantstool" icon="https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/docs/tools/lantstool-logo-circle.svg?fit=max&auto=format&n=qO2GD-gji1aakHqN&q=85&s=e40405f8a9eda7a97dd89b9cc07a9ca9" width="100" height="100" data-path="assets/docs/tools/lantstool-logo-circle.svg">
      <TryOutOnLantstool path="docs/2.build/5.primitives/staking/owner-balance.json" />
    </Tab>
  </Tabs>

  #### Staking key

  <Tabs>
    <Tab title="🖥️ CLI">
      ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
      near view <my_validator> get_staking_key '{}'
      ```
    </Tab>

    <Tab title="Lantstool" icon="https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/docs/tools/lantstool-logo-circle.svg?fit=max&auto=format&n=qO2GD-gji1aakHqN&q=85&s=e40405f8a9eda7a97dd89b9cc07a9ca9" width="100" height="100" data-path="assets/docs/tools/lantstool-logo-circle.svg">
      <TryOutOnLantstool path="docs/2.build/5.primitives/staking/staking-key.json" />
    </Tab>
  </Tabs>
</Accordion>

***

## Withdrawing Staked Tokens

To withdraw your staked tokens, you will first need to "un-delegate" them from the validator.

Your tokens will enter a 4 epoch (\~24 hours) unbonding period before they can be withdrawn.

### Unstake Tokens

<Tabs>
  <Tab title="Staking CLI">
    ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
    near staking delegation <user-account.near> unstake '1 NEAR' <my_validator> network-config mainnet sign-with-keychain
    ```

    <Info>
      Use the `unstake-all` command to to unstake all tokens at once:

      ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
      near staking delegation <user-account.near> unstake-all <my_validator> network-config mainnet sign-with-keychain
      ```
    </Info>
  </Tab>

  <Tab title="Function Call">
    ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
    near call <my_validator> unstake '{"amount": "100000000000000000000000000"}' --useAccount <user-account.near>
    ```

    <Info>
      Call the `unstake_all` method to unstake all tokens at once
    </Info>
  </Tab>

  <Tab title="Lantstool" icon="https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/docs/tools/lantstool-logo-circle.svg?fit=max&auto=format&n=qO2GD-gji1aakHqN&q=85&s=e40405f8a9eda7a97dd89b9cc07a9ca9" width="100" height="100" data-path="assets/docs/tools/lantstool-logo-circle.svg">
    <TryOutOnLantstool path="docs/2.build/5.primitives/staking/unstake.json" />
  </Tab>
</Tabs>

### Query Unstaked Balance

<Tabs>
  <Tab title="Staking CLI">
    ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
    near staking delegation <user-account.near> view-balance <my_validator> network-config mainnet now
    ```
  </Tab>

  <Tab title="Function Call">
    ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
    near view <my_validator> get_account_unstaked_balance '{"account_id": "<user-account.near>"}'
    ```
  </Tab>

  <Tab title="Lantstool" icon="https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/docs/tools/lantstool-logo-circle.svg?fit=max&auto=format&n=qO2GD-gji1aakHqN&q=85&s=e40405f8a9eda7a97dd89b9cc07a9ca9" width="100" height="100" data-path="assets/docs/tools/lantstool-logo-circle.svg">
    <TryOutOnLantstool path="docs/2.build/5.primitives/staking/account-unstaked-balance.json" />
  </Tab>
</Tabs>

### Withdraw Tokens

Once the unbonding period has passed, you can withdraw your unstaked tokens:

<Tabs>
  <Tab title="Staking CLI">
    ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
    near staking delegation <user-account.near> withdraw '1 NEAR' <my_validator> network-config mainnet sign-with-keychain
    ```

    <Info>
      If you want to withdraw all available tokens, you can use the `withdraw-all` command:

      ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
      near staking delegation <user-account.near> withdraw-all <my_validator> network-config mainnet sign-with-keychain
      ```
    </Info>
  </Tab>

  <Tab title="Function Call">
    ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
    near call <my_validator> withdraw '{"amount": "100000000000000000000000000"}' --useAccount <user-account.near>
    ```
  </Tab>

  <Tab title="Lantstool" icon="https://mintcdn.com/neardocs/qO2GD-gji1aakHqN/assets/docs/tools/lantstool-logo-circle.svg?fit=max&auto=format&n=qO2GD-gji1aakHqN&q=85&s=e40405f8a9eda7a97dd89b9cc07a9ca9" width="100" height="100" data-path="assets/docs/tools/lantstool-logo-circle.svg">
    <TryOutOnLantstool path="docs/2.build/5.primitives/staking/withdraw-unstaked-tokens.json" />
  </Tab>
</Tabs>

***

## Sunsetting a Stake Pool

If you are a stake pool owner and want to wind down your validator service, follow these steps to ensure delegators can safely recover their funds.

### Step 1: Notify Delegators

Before making any changes, inform your delegators that the pool is shutting down. Give them enough time to unstake and withdraw their tokens. They need to:

1. Call `unstake_all` on the pool.
2. Wait for the **4-epoch unbonding period** (\~48 hours).
3. Call `withdraw_all` to retrieve their tokens.

You can share the commands from the [Withdrawing Staked Tokens](#withdrawing-staked-tokens) section above with them.

### Step 2: Pause Staking

Call `pause_staking` from the pool owner account. This causes the contract to unstake everything (stake 0) and stop restaking, without affecting share balances or reward calculations.

```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
near call <my_validator> pause_staking '{}' --useAccount <owner-account.near> --depositYocto 1 --networkId mainnet
```

<Note>
  The contract will unstake all tokens at the next epoch boundary. Delegators will still see their shares and can unstake and withdraw normally.
</Note>

### Step 3: Withdraw Owner Balance

Once your own staked tokens are unstaked and the unbonding period has passed, withdraw them:

<Tabs>
  <Tab title="Staking CLI">
    ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
    near staking delegation <owner-account.near> withdraw-all <my_validator> network-config mainnet sign-with-keychain
    ```
  </Tab>

  <Tab title="Function Call">
    ```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
    near call <my_validator> withdraw_all '{}' --useAccount <owner-account.near> --networkId mainnet
    ```
  </Tab>
</Tabs>

### Step 4: Resume (Optional)

If you decide to keep the pool running again, you can re-enable staking at any time:

```sh theme={"theme":{"light":"github-light","dark":"github-dark"}}
near call <my_validator> resume_staking '{}' --useAccount <owner-account.near> --depositYocto 1 --networkId mainnet
```

***

## Tools and Resources

* Supported wallets for staking and managing your tokens:
  * [Ecosystem Wallets](https://wallet.near.org/)
* To explore validators and staking pools:
  * [NearBlocks](https://nearblocks.io/)
  * [Pikespeak](https://pikespeak.ai/)
  * [NEAR Staking](https://near-staking.com/)
