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

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

1. List stakes for your account address.
2. Create a withdrawal request.
3. Sign and broadcast the transaction.

Request examples are provided using [cURL](https://curl.se/).

<Steps>
  <Step title="Get list stakes">
    To identify which stake to withdraw, send a GET request to [/api/v1/sui/\{network}/transaction/stake-list/\{address}](/reference/sui-transaction-get-stake-list).

    Example request (for `testnet` network):

    <CodeGroup>
      ```bash curl theme={null}
      curl --request GET
      		 --url 'https://api-test.p2p.org/api/v1/sui/testnet/transaction/stake-list/0x696f4402d7151fb49e52b629de3ce3098f3dda7721a7425c000b4f26653709e3' \
      		--header 'Authorization: Bearer <token>'
      ```

      ```typescript TypeScript theme={null}
      const response = await fetch("https://api-test.p2p.org/api/v1/sui/testnet/transaction/stake-list/0x696f4402d7151fb49e52b629de3ce3098f3dda7721a7425c000b4f26653709e3", {
        method: "GET",
        headers: {
          "Authorization": "Bearer <token>",
        },
      });
      const data = await response.json();
      console.log(data);
      ```

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

      response = requests.get(
          "https://api-test.p2p.org/api/v1/sui/testnet/transaction/stake-list/0x696f4402d7151fb49e52b629de3ce3098f3dda7721a7425c000b4f26653709e3",
          headers={
              "Authorization": "Bearer <token>",
          },
      )
      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/sui/testnet/transaction/stake-list/0x696f4402d7151fb49e52b629de3ce3098f3dda7721a7425c000b4f26653709e3", nil)
      	req.Header.Set("Authorization", "Bearer <token>")
      	resp, _ := http.DefaultClient.Do(req)
      	defer resp.Body.Close()
      	respBody, _ := io.ReadAll(resp.Body)
      	fmt.Println(string(respBody))
      }
      ```
    </CodeGroup>

    * `network` — Sui network: `mainnet` or `testnet`.
    * `address` — staker account address.

    Example response:

    <CodeGroup>
      ```json theme={null}
      {
          "error": null,
          "result": {
            "validatorAddress": "0xab4fb3eeaa7b0ab4f91eedab33adf140c6750e60ca5e44b3df82491937d7bab4",
            "stakerAddress": "0x696f4402d7151fb49e52b629de3ce3098f3dda7721a7425c000b4f26653709e3",
            "stakes": [
              {
                "stakeId": "0x5d920b8fca6a6043d898ab1a9a8ab167d8aa323fe2b9e76a27312f7f16e20a67",
                "amount": 1000000000,
                "status": "Pending"
              }
            ]
          }
        }
      ```
    </CodeGroup>

    * `validatorAddress` — validator address.

    * `stakerAddress` — staker account address.

    * `stakes` — detailed information on each stake:

      * `stakeId` — identifier of the stake, required to perform a withdrawal.
      * `amount` — amount of tokens to stake in MIST (1 SUI = 10⁹ MIST).
      * `status` — staking transaction status. You can withdraw at any time while the stake status is either `pending` or `active`.
  </Step>

  <Step title="Create withdrawal request">
    Initiate the withdrawal process by sending a POST request to [/api/v1/sui/\{network}/staking/withdraw](/reference/sui-staking-withdraw).

    Example response:

    <CodeGroup>
      ```bash curl theme={null}
      curl --request
      	 	 --url 'https://api-test.p2p.org/api/v1/sui/testnet/staking/withdraw' \
      		--header 'accept: application/json' \
      		--header 'Authorization: Bearer <token>' \
      		--header 'Content-Type: application/json' \
      		 --data '{
        		 "sender": "0x696f4402d7151fb49e52b629de3ce3098f3dda7721a7425c000b4f26653709e3",
        		 "gasPrice": 1000,
        		 "gasBudget": 10000000,
        		 "stakeId": "0x5d920b8fca6a6043d898ab1a9a8ab167d8aa323fe2b9e76a27312f7f16e20a67"
      		 }'
      ```

      ```typescript TypeScript theme={null}
      const response = await fetch("https://api-test.p2p.org/api/v1/sui/testnet/staking/withdraw", {
        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/sui/testnet/staking/withdraw",
          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/sui/testnet/staking/withdraw", 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>

    * `sender` — staker account address.
    * `gasPrice` — price per unit of gas in MIST for processing the Sui transaction.
    * `gasBudget` — maximum gas limit for the transaction.
    * `stakeId` — identifier of the stake to withdraw from, obtained through the previous step.

    Example response:

    <CodeGroup>
      ```json theme={null}
      {
          "error": null,
          "result": {
            "unsignedTransaction": "0x000003000800ca9a3b00000000010100000000000000000000000000000000000000000000000000000000000000050100000000000000010020ab4fb3eeaa7b0ab4f91eedab33adf140c6750e60ca5e44b3df82491937d7bab4020200010100000000000000000000000000000000000000000000000000000000000000000000030a7375695f73797374656d11726571756573745f6164645f7374616b650003010100020000010200696f4402d7151fb49e52b629de3ce3098f3dda7721a7425c000b4f26653709e3024af02b603f7d65cced30be6ed44300d7d9d66522940e501e1a2083cfc25429e5a60bd0140000000020abca58a9797ecf7cc82596d71b4a154f8dd14b18e3190beee205b905611fbfa29c6ca3ef6b075ab6294342fe06c323768659879813e0544d3fd25a7db7875cca440000180000000020405515b0e64b00c04ebdb0517c2a1f07f3e32cba49adf4ea87d4daadc265c1f0696f4402d7151fb49e52b629de3ce3098f3dda7721a7425c000b4f26653709e3e8030000000000000065cd1d0000000000..."
          }
        }
      ```
    </CodeGroup>

    * `unsignedTransaction` — serialized unsigned transaction in the hexadecimal format. Sign the transaction and submit it to the blockchain to perform the called action.
  </Step>

  <Step title="Sign and send transaction">
    Use `unsignedTransaction` from the previous step to [sign and send](/docs/signing-transaction-sui) the signed transaction to the Sui network. The withdrawal is immediate and processed within seconds.
  </Step>
</Steps>


## Related topics

- [Sign and Send Transaction](/docs/signing-transaction-sui.md)
- [Staking API reference](/reference/sui-staking-stake.md)
