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

# Withdrawal

> Withdraw staked assets on Polkadot with the P2P.org Staking API.

The withdrawal process in the Polkadot network using the Staking API can be done following these steps:

1. Create unbonding request: unbond tokens within the Polkadot network that were previously bonded.

> It takes 7 days (28 eras) to unbond on Kusama, 28 days (28 eras) on Polkadot, and 12 hours (2 eras) on Westend.

2. Create withdrawal request: withdraw the unbonded tokens. Note that this request is available after the unbonding period.

## Staking directly

### 1. Create unbonding request

1. Send a POST request to [/api/v1/polkadot/\{network}/staking/unbond](/reference/polkadot-staking-unbond).

   Example request (for `westend`):

<CodeGroup>
  ```bash curl theme={null}
  curl --request POST \
       --url https://api.p2p.org/api/v1/polkadot/westend/staking/unbond \
       --header 'accept: application/json' \
       --header 'authorization: Bearer <token>' \
       --header 'content-type: application/json' \
       --data '
  {
    "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
    "amount": 3
  }'
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch("https://api.p2p.org/api/v1/polkadot/westend/staking/unbond", {
    method: "POST",
    headers: {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
      "amount": 3
    }),
  });
  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.p2p.org/api/v1/polkadot/westend/staking/unbond",
      headers={
          "Authorization": "Bearer <token>",
          "Content-Type": "application/json",
      },
      json={
          "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
          "amount": 3
      },
  )
  print(response.json())
  ```

  ```go Go theme={null}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"fmt"
  	"io"
  	"net/http"
  )

  func main() {
  	payload := map[string]interface{}{
  		"stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
  		"amount": 3,
  	}
  	body, _ := json.Marshal(payload)
  	req, _ := http.NewRequest("POST", "https://api.p2p.org/api/v1/polkadot/westend/staking/unbond", bytes.NewBuffer(body))
  	req.Header.Set("Authorization", "Bearer <token>")
  	req.Header.Set("Content-Type", "application/json")
  	resp, _ := http.DefaultClient.Do(req)
  	defer resp.Body.Close()
  	respBody, _ := io.ReadAll(resp.Body)
  	fmt.Println(string(respBody))
  }
  ```
</CodeGroup>

* `stashAccountAddress` — main <Tooltip tip="On Polkadot and Avail, this is an account that holds funds bonded for staking, but delegates all staking functions to a staking proxy account. You may actively participate in staking with a stash private key kept in a cold wallet like Ledger, meaning it stays offline all the time. Having a staking proxy will allow you to sign all staking-related transactions with the proxy instead of using your Ledger device. This will allow you to avoid carrying around your Ledger device just to sign staking-related transactions, and to keep the transaction history of your stash clean.">stash account</Tooltip> address which keeps tokens for bonding.
* `amount` — amount of tokens to unbond. DOT is used for the main network, KSM for Kusama, and WND for Westend.

Example response:

<CodeGroup>
  ```js<Tooltip tip="On Polkadot and Avail, this is an account that holds funds bonded for staking, but delegates all staking functions to a staking proxy account. You may actively participate in staking with a stash private key kept in a cold wallet like Ledger, meaning it stays offline all the time. Having a staking proxy will allow you to sign all staking-related transactions with the proxy instead of using your Ledger device. This will allow you to avoid carrying around your Ledger device just to sign staking-related transactions, and to keep the transaction history of your stash clean.">on theme={null}
  {
      "res</Tooltip>ult": {
        "unsignedTransaction": "0xac0406000b00487835a302032c6eca5cdaa3e87d7f8e06d10015bf0508b52d301c8991af113d5cf49a53553f",
        "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
        "amount": 3,
        "createdAt": "2023-08-15T15:07:54.795Z"
      }
    }
  ```
</CodeGroup>

* `unsignedTransaction` — <Tooltip tip="A transaction that must be signed and broadcasted to the blockchain network.">unsigned transaction</Tooltip> in hex format. Sign the transaction and submit it to the blockchain to perform the called action.
* `stashAccountAddress` — main stash account address which keeps tokens for bonding.
* `amount` — amount of tokens for bond operations. DOT is used for the main network, KSM for Kusama, and WND for Westend.
* `createdAt` — timestamp of the transaction in the ISO 8601 format.

2. [Sign and broadcast](/docs/signing-transaction-polkadot) the `unsignedTransaction` to the Polkadot network.

### 2. Create withdrawal request

1. Send a POST request to [/api/v1/polkadot/\{network}/staking/withdrawal-unbonded](/reference/polkadot-staking-withdrawunbonded).

   Example request (for `westend`):

<CodeGroup>
  ```bash curl theme={null}
  curl --request POST \
       --url https://api.p2p.org/api/v1/polkadot/westend/staking/withdrawal-unbonded \
       --header 'accept: application/json' \
       --header 'authorization: Bearer <token>' \
       --header 'content-type: application/json' \
       --data '
  {
    "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5"
  }'
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch("https://api.p2p.org/api/v1/polkadot/westend/staking/withdrawal-unbonded", {
    method: "POST",
    headers: {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5"
    }),
  });
  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.p2p.org/api/v1/polkadot/westend/staking/withdrawal-unbonded",
      headers={
          "Authorization": "Bearer <token>",
          "Content-Type": "application/json",
      },
      json={
          "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5"
      },
  )
  print(response.json())
  ```

  ```go Go theme={null}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"fmt"
  	"io"
  	"net/http"
  )

  func main() {
  	payload := map[string]interface{}{
  		"stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
  	}
  	body, _ := json.Marshal(payload)
  	req, _ := http.NewRequest("POST", "https://api.p2p.org/api/v1/polkadot/westend/staking/withdrawal-unbonded", bytes.NewBuffer(body))
  	req.Header.Set("Authorization", "Bearer <token>")
  	req.Header.Set("Content-Type", "application/json")
  	resp, _ := http.DefaultClient.Do(req)
  	defer resp.Body.Close()
  	respBody, _ := io.ReadAll(resp.Body)
  	fmt.Println(string(respBody))
  }
  ```
</CodeGroup>

* `stashAccountAddress` — main stash account address which keeps tokens for bonding.

Example response:

<CodeGroup>
  ```json theme={null}
  {
      "result": {
        "unsignedTransaction": "0xac0406000b00487835a302032c6eca5cdaa3e87d7f8e06d10015bf0508b52d301c8991af113d5cf49a53553f",
        "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
   <Tooltip tip="A transaction that must be signed and broadcasted to the blockchain network.">     "createdAt": "2</Tooltip>023-08-15T15:07:54.795Z"
      }
    }
  ```
</CodeGroup>

* `unsignedTransaction` — unsigned transaction in hex format. Sign the transaction and submit it to the blockchain to perform the called action.
* `stashAccountAddress` — main stash account address which keeps tokens for bonding.
* `createdAt` — timestamp of the transaction in the ISO 8601 format.

2. [Sign and broadcast](/docs/signing-transaction-polkadot) the `unsignedTransaction` to the Polkadot network.

## Staking via a nomination pool

### 1. Create unbonding request

1. Send a POST request to [api/v1/polkadot/\{network}/staking/pool/unbond](/reference/polkadot-pool-unbond).

   Example request (for `westend`):

<CodeGroup>
  ```bash curl theme={null}
  curl --request POST \
    --url https://api.p2p.org/api/v1/polkadot/{network}/staking/pool/unbond \
    --header 'accept: application/json' \
    --header 'authorization: Bearer <token>' \
    --header 'content-type: application/json' \
    --data '
  {
  "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
  "amount": 3
  }'
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch("https://api.p2p.org/api/v1/polkadot/{network}/staking/pool/unbond", {
    method: "POST",
    headers: {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
      "amount": 3
    }),
  });
  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.p2p.org/api/v1/polkadot/{network}/staking/pool/unbond",
      headers={
          "Authorization": "Bearer <token>",
          "Content-Type": "application/json",
      },
      json={
          "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
          "amount": 3
      },
  )
  print(response.json())
  ```

  ```go Go theme={null}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"fmt"
  	"io"
  	"net/http"
  )

  func main() {
  	payload := map[string]interface{}{
  		"stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
  		"amount": 3,
  	}
  	body, _ := json.Marshal(payload)
  	req, _ := http.NewRequest("POST", "https://api.p2p.org/api/v1/polkadot/{network}/staking/pool/unbond", bytes.NewBuffer(body))
  	req.Header.Set("Authorization", "Bearer <token>")
  	req.Header.Set("Content-Type", "application/json")
  	resp, _ := http.DefaultClient.Do(req)
  	defer resp.Body.Close()
  	respBody, _ := io.ReadAll(resp.Body)
  	fmt.Println(string(respBody))
  }
  ```
</CodeGroup>

* `stashAccountAddress` — main stash account address which keeps tokens for bonding.
* `amount` — amount of tokens to unbond. DOT is used for the main network, KSM for Kusama, and WND for Westend.

Example response:

<CodeGroup>
  ```json theme={null}
  {
    "result": {
     "unsignedTransaction": "0xac0406000b00487835a302032c6eca5cdaa3e87d7f8e06d10015bf0508b52d301c8991af113d5cf49a53553f",
     "amount": 3,
     "createdAt": "2023-08-15T15:07:54.795Z"
    }
    }
  ```
</CodeGroup>

* `unsignedTransaction` — unsigned transaction in hex format. Sign the transaction and submit it to the blockchain to perform the called action.
* `amount` — amount of tokens for bond operations. DOT is used for the main network, KSM for Kusama, and WND for Westend.
* `createdAt` — timestamp of the transaction in the ISO 8601 format.

2. [Sign and broadcast](/docs/signing-transaction-polkadot) the `unsignedTransaction` to the Polkadot network.

### 2. Create withdrawal request

1. Send a POST request to [api/v1/polkadot/\{network}/staking/pool/withdraw-unbonded](/reference/polkadot-pool-withdraw-unbonded).

   Example request (for `westend`):

<CodeGroup>
  ```bash curl theme={null}
  curl --request POST \
    --url https://api.p2p.org/api/v1/polkadot/westend/staking/withdrawal-unbonded \
    --header 'accept: application/json' \
    --header 'authorization: Bearer <token>' \
    --header 'content-type: application/json' \
    --data '
  {
  "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
  "poolId": "1"
  }'
  ```

  ```typescript TypeScript theme={null}
  const response = await fetch("https://api.p2p.org/api/v1/polkadot/westend/staking/withdrawal-unbonded", {
    method: "POST",
    headers: {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
      "poolId": "1"
    }),
  });
  const data = await response.json();
  console.log(data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      "https://api.p2p.org/api/v1/polkadot/westend/staking/withdrawal-unbonded",
      headers={
          "Authorization": "Bearer <token>",
          "Content-Type": "application/json",
      },
      json={
          "stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
          "poolId": "1"
      },
  )
  print(response.json())
  ```

  ```go Go theme={null}
  package main

  import (
  	"bytes"
  	"encoding/json"
  	"fmt"
  	"io"
  	"net/http"
  )

  func main() {
  	payload := map[string]interface{}{
  		"stashAccountAddress": "5H6ryBWChC5w7eaQ4GZjo329sEnhvjetSr6MBEt42mZ5tPw5",
  		"poolId": "1",
  	}
  	body, _ := json.Marshal(payload)
  	req, _ := http.NewRequest("POST", "https://api.p2p.org/api/v1/polkadot/westend/staking/withdrawal-unbonded", bytes.NewBuffer(body))
  	req.Header.Set("Authorization", "Bearer <token>")
  	req.Header.Set("Content-Type", "application/json")
  	resp, _ := http.DefaultClient.Do(req)
  	defer resp.Body.Close()
  	respBody, _ := io.ReadAll(resp.Body)
  	fmt.Println(string(respBody))
  }
  ```
</CodeGroup>

* `stashAccountAddress` — main stash account address which keeps tokens for bonding.
* `poolId` — ID of the nomination pool in which you participate.

Example response:

<CodeGroup>
  ```json theme={null}
  {
    "result": {
     "unsignedTransaction": "0xac0406000b00487835a302032c6eca5cdaa3e87d7f8e06d10015bf0508b52d301c8991af113d5cf49a53553f",
     "createdAt": "2023-08-15T15:07:54.795Z"
    }
    }
  ```
</CodeGroup>

* `unsignedTransaction` — unsigned transaction in hex format. Sign the transaction and submit it to the blockchain to perform the called action.
* `createdAt` — timestamp of the transaction in the ISO 8601 format.

2. [Sign and broadcast](/docs/signing-transaction-polkadot) the `unsignedTransaction` to the Polkadot network.


## Related topics

- [Getting Started](/docs/staking-polkadot.md)
- [Staking API reference](/reference/polkadot-staking-bond.md)
