> ## 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 Sei with the P2P.org Staking API.

The withdrawal process in the Sei network using the Staking API can be done in a few steps:

1. Create an unstaking request.
2. Sign and send the transaction to the network.

<Steps>
  <Step title="Create unstaking request">
    1) Send a POST request to [/api/v1/sei/\{network}/staking/unstake](/reference/create-sei-unstake-transaction).

       Example request (for `atlantic-2` network):

    <CodeGroup>
      ```bash curl theme={null}
      curl --request POST \
           --url https://api-test.p2p.org/api/v1/sei/atlantic-2/staking/unstake \
           --header 'accept: application/json' \
           --header 'authorization: Bearer <token>' \
           --header 'content-type: application/json' \
           --data '
           {
           "delegatorAddress": "cosmos1y9wefmlpm0djkt8sseeveke0httfukg2a60g0r",
           "memo": "This is your memo message",
           "amount": 0.0001
           }'
      ```

      ```typescript TypeScript theme={null}
      const response = await fetch("https://api-test.p2p.org/api/v1/sei/atlantic-2/staking/unstake", {
        method: "POST",
        headers: {
          "Authorization": "Bearer <token>",
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          "delegatorAddress": "cosmos1y9wefmlpm0djkt8sseeveke0httfukg2a60g0r",
          "memo": "This is your memo message",
          "amount": 0.0001
        }),
      });
      const data = await response.json();
      console.log(data);
      ```

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

      response = requests.post(
          "https://api-test.p2p.org/api/v1/sei/atlantic-2/staking/unstake",
          headers={
              "Authorization": "Bearer <token>",
              "Content-Type": "application/json",
          },
          json={
              "delegatorAddress": "cosmos1y9wefmlpm0djkt8sseeveke0httfukg2a60g0r",
              "memo": "This is your memo message",
              "amount": 0.0001
          },
      )
      print(response.json())
      ```

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

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

      func main() {
      	payload := map[string]interface{}{
      		"delegatorAddress": "cosmos1y9wefmlpm0djkt8sseeveke0httfukg2a60g0r",
      		"memo": "This is your memo message",
      		"amount": 0.0001,
      	}
      	body, _ := json.Marshal(payload)
      	req, _ := http.NewRequest("POST", "https://api-test.p2p.org/api/v1/sei/atlantic-2/staking/unstake", 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` — delegator account address which keeps tokens.
    * `memo` — arbitrary text data to add to the transactions.
    * `amount` — amount of tokens to unstake in SEI.

    Example response:

    <CodeGroup>
      ```json theme={null}
      {
          "error": null,
          "result": {
            "amount": 0.0001,
            "currency": "sei",
            "validatorAddress": "cosmosvaloper132juzk0gdmwuxvx4phug7m3ymyatxlh9734g4w",
            "delegatorAddress": "cosmos1y9wefmlpm0djkt8sseeveke0httfukg2a60g0r",
            "transactionData": {
              "messages": [
                {
                  "typeUrl": "/cosmos.staking.v1beta1.MsgUndelegate",
                  "value": {
                    "delegatorAddress": "cosmos1y9wefmlpm0djkt8sseeveke0httfukg2a60g0r",
                    "validatorAddress": "cosmosvaloper132juzk0gdmwuxvx4phug7m3ymyatxlh9734g4w",
                    "amount": {
                      "denom": "usei",
                      "amount": "100"
                    }
                  }
                }
              ],
              "fee": {
                "amount": [
                  {
                    "amount": "16384",
                    "denom": "usei"
                  }
                ],
                "gas": "655324"
              },
              "memo": "This is your memo message",
              "encodedBody": "0a9c010a252f636f736d6f732e7374616b696e672e763162657461312e4d7367556e64656c656761746512730a2d636f736d6f733179397765666d6c706d30646a6b74387373656576656b653068747466756b67326136306730721234636f736d6f7376616c6f7065723133326a757a6b3067646d77757876783470687567376d33796d796174786c68393733346734771a0c0a057561746f6d1203313030120b546865206d657373616765",
              "encodedAuthInfo": "0a500a460a1f2f636f736d6f732e63727970746f2e736563703235366b312e5075624b657912230a2103b0c7ac278e1941ac0b65d6bd45d541cae58aa584058fbbd822311b8718708c0e12040a020801180212140a0e0a057561746f6d1205313633383410dcff27"
            },
            "createdAt": "2023-11-03T10:10:05.407Z"
          }
        }
      ```
    </CodeGroup>

    * `amount` — amount of tokens to stake.

    * `currency` — currency of tokens:

      * `sei` — Sei native staking token.
      * `usei` — 1 SEI = 10⁶ uSEI.
      * `msei` — 1 SEI = 10³ mSEI.

    * `validatorAddress` — validator address to which tokens are delegated.

    * `stashAccountAddress` — delegator stash account address which keeps tokens.

    * `rewardDestinationAddress` — reward destination account address.

    * `createdAt` — timestamp of the transaction in the ISO 8601 format.

    `transactionData` is the list of data fields to be used to construct the staking transactions:

    * `messages`:

      * `typeUrl` — Sei network operation type.
      * `delegatorAddress` — delegator address.
      * `validatorAddress` — validator address.
      * `amount` — amount of tokens to unstake.
      * `denom` — currency of tokens.

    * `fee` — fee charged for the transaction.

      * `amount` — amount of tokens.
      * `denom` — currency of tokens: `sei`, `usei`, or `msei`.
      * `gas` — amount of gas spent for the transaction.

    * `memo` — arbitrary text data to add to the transactions.

    * `encodedBody` — processable transaction data encoded in the hexadecimal format.

    * `encodedAuthInfo` — authorization data, including fee, encoded in the hexadecimal format.
  </Step>

  <Step title="Sign and send transaction">
    Use `transactionData` to [sign and send](/docs/signing-transaction-sei) the signed transaction to the Sei network.

    To check the transaction status, send a GET request to [/api/v1/sei/\{network}/transaction/status/\{transactionHash}](/reference/get-sei-transaction-status).

    Example request (for `atlantic-2` network):

    <CodeGroup>
      ```bash curl theme={null}
      curl --request GET \
           --url https://api-test.p2p.org/api/v1/sei/atlantic-2/transaction/status/ADD7B2791E1959075D1836D4BCC71ED256CCD724459F9BD8862D85E205075D47 \
           --header 'accept: application/json' \
           --header 'authorization: Bearer <token>' \
           --header 'content-type: application/json'
      ```

      ```typescript TypeScript theme={null}
      const response = await fetch("https://api-test.p2p.org/api/v1/sei/atlantic-2/transaction/status/ADD7B2791E1959075D1836D4BCC71ED256CCD724459F9BD8862D85E205075D47", {
        method: "GET",
        headers: {
          "Authorization": "Bearer <token>",
          "Content-Type": "application/json",
        },
      });
      const data = await response.json();
      console.log(data);
      ```

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

      response = requests.get(
          "https://api-test.p2p.org/api/v1/sei/atlantic-2/transaction/status/ADD7B2791E1959075D1836D4BCC71ED256CCD724459F9BD8862D85E205075D47",
          headers={
              "Authorization": "Bearer <token>",
              "Content-Type": "application/json",
          },
      )
      print(response.json())
      ```

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

      import (
      	"fmt"
      	"io"
      	"net/http"
      )

      func main() {
      	req, _ := http.NewRequest("GET", "https://api-test.p2p.org/api/v1/sei/atlantic-2/transaction/status/ADD7B2791E1959075D1836D4BCC71ED256CCD724459F9BD8862D85E205075D47", nil)
      	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>

    * `transactionHash` — hash of the transaction.

    Example response:

    <CodeGroup>
      ```json theme={null}
      {
            "error": null,
            "result": {
                "status": "success",
                "blockId": 18575267,
                "fee": 0.005952,
                "gas": {
                    "used": 202947,
                    "wanted": 238047
                },
                "transactionHash": "ADD7B2791E1959075D1836D4BCC71ED256CCD724459F9BD8862D85E205075D47"
            }
        }
      ```
    </CodeGroup>

    * `status` — transaction status: `success`, `failed`.

    * `blockId` — unique identifier of the block in which the transaction has been included.

    * `fee` — total fee in ATOM charged for processing the transaction.

    * `gas` — computational effort required to execute the transaction, measured in gas units.

      * `used` — amount of gas spent for the transaction.
      * `wanted` — maximum gas limit that the transaction initiator was willing to consume for the transaction.

    * `transactionHash` — hash of the transaction.
  </Step>
</Steps>


## Related topics

- [Sign and Broadcast Transaction](/docs/signing-transaction-sei.md)
- [Staking API reference](/reference/create-sei-stake-transaction.md)
