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

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

1. Deactivate the staking request.
2. Create the withdrawal request.

After each operation, [sign and send the transaction](/docs/signing-transaction-solana) to the Solana network.

<Note>
  **Please note**

  It normally takes up to 3 days to unstake your Solana. This is because Solana uses a system of epochs, each of which lasts around 2.5 days.

  In order to ensure fairness and network security when you deactivate your stake, it will remain active for the remainder of the current epoch.
</Note>

<Steps>
  <Step title="Deactivate staking request">
    1. Send a POST request to [/api/v1/solana/\{network}/staking/deactivate](/reference/solana-staking-deactivate).

       Example request (for `testnet` network):

    <CodeGroup>
      ```bash curl theme={null}
      curl --request POST \
           --url https://api-test.p2p.org/api/v1/solana/testnet/staking/deactivate \
           --header 'accept: application/json' \
           --header 'authorization: Bearer <token>' \
           --header 'content-type: application/json' \
           --data '
           {
             "feePayer": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
             "stakeAccount": "6ZuLUCwVTvuQJrN1HrpoHJheQUw9Zk8CtiD3CEpHiA9E",
             "stakeAuthority": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC"
           }'
      ```

      ```typescript TypeScript theme={null}
      const response = await fetch("https://api-test.p2p.org/api/v1/solana/testnet/staking/deactivate", {
        method: "POST",
        headers: {
          "Authorization": "Bearer <token>",
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          "feePayer": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
          "stakeAccount": "6ZuLUCwVTvuQJrN1HrpoHJheQUw9Zk8CtiD3CEpHiA9E",
          "stakeAuthority": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC"
        }),
      });
      const data = await response.json();
      console.log(data);
      ```

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

      response = requests.post(
          "https://api-test.p2p.org/api/v1/solana/testnet/staking/deactivate",
          headers={
              "Authorization": "Bearer <token>",
              "Content-Type": "application/json",
          },
          json={
              "feePayer": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
              "stakeAccount": "6ZuLUCwVTvuQJrN1HrpoHJheQUw9Zk8CtiD3CEpHiA9E",
              "stakeAuthority": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC"
          },
      )
      print(response.json())
      ```

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

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

      func main() {
      	payload := map[string]interface{}{
      		"feePayer": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
      		"stakeAccount": "6ZuLUCwVTvuQJrN1HrpoHJheQUw9Zk8CtiD3CEpHiA9E",
      		"stakeAuthority": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
      	}
      	body, _ := json.Marshal(payload)
      	req, _ := http.NewRequest("POST", "https://api-test.p2p.org/api/v1/solana/testnet/staking/deactivate", 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>

    * `feePayer` — account address that will pay the fee for the transaction.
    * `stakeAccount` — account address that stores tokens for staking.
    * `stakeAuthority` — account address that can perform staking operations with staking account.

    Example response:

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

    * `feePayer` — account address that will pay the fee for the transaction.

    * `stakeAccount` — account address that stores tokens for staking.

    * `stakeAuthority` — account address that can perform staking operations with the staking account.

    * `unsignedTransaction` — unsigned transaction in Base64 encrypted 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.

    > The transaction exists for one minute.

    2. Use `unsignedTransaction` to [sign and send](/docs/signing-transaction-solana) the signed transaction to the Solana network.
  </Step>

  <Step title="Create withdrawal request">
    1. Send a POST request to [/api/v1/solana/\{network}/staking/withdraw](/reference/solana-staking-withdraw).

       Example request (for `testnet` network):

    <CodeGroup>
      ```bash curl theme={null}
      curl --request POST \
           --url https://api-test.p2p.org/api/v1/solana/testnet/staking/withdraw \
           --header 'accept: application/json' \
           --header 'authorization: Bearer <token>' \
           --header 'content-type: application/json' \
           --data '
           {
             "feePayer": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
             "stakeAccount": "6ZuLUCwVTvuQJrN1HrpoHJheQUw9Zk8CtiD3CEpHiA9E",
             "withdrawAuthority": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
             "recipient": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
             "amount": 1002282880
           }'
      ```

      ```typescript TypeScript theme={null}
      const response = await fetch("https://api-test.p2p.org/api/v1/solana/testnet/staking/withdraw", {
        method: "POST",
        headers: {
          "Authorization": "Bearer <token>",
          "Content-Type": "application/json",
        },
        body: JSON.stringify({
          "feePayer": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
          "stakeAccount": "6ZuLUCwVTvuQJrN1HrpoHJheQUw9Zk8CtiD3CEpHiA9E",
          "withdrawAuthority": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
          "recipient": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
          "amount": 1002282880
        }),
      });
      const data = await response.json();
      console.log(data);
      ```

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

      response = requests.post(
          "https://api-test.p2p.org/api/v1/solana/testnet/staking/withdraw",
          headers={
              "Authorization": "Bearer <token>",
              "Content-Type": "application/json",
          },
          json={
              "feePayer": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
              "stakeAccount": "6ZuLUCwVTvuQJrN1HrpoHJheQUw9Zk8CtiD3CEpHiA9E",
              "withdrawAuthority": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
              "recipient": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
              "amount": 1002282880
          },
      )
      print(response.json())
      ```

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

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

      func main() {
      	payload := map[string]interface{}{
      		"feePayer": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
      		"stakeAccount": "6ZuLUCwVTvuQJrN1HrpoHJheQUw9Zk8CtiD3CEpHiA9E",
      		"withdrawAuthority": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
      		"recipient": "C83GxcNFTC2tK22rLCCrLKYRkckbNVGsjethN5iswgfC",
      		"amount": 1002282880,
      	}
      	body, _ := json.Marshal(payload)
      	req, _ := http.NewRequest("POST", "https://api-test.p2p.org/api/v1/solana/testnet/staking/withdraw", 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>

    * `feePayer` — account address that will pay the fee for the transaction.
    * `stakeAccount` — account address that stores tokens for staking.
    * `withdrawAuthority` — account address that can perform withdrawal operations with the staking account.
    * `recipient` — account address to which tokens will be sent.
    * `amount` — amount of tokens to withdraw in lamports (1 SOl = 10⁹ lamports).

    Example response:

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

    * `feePayer` — account address that will pay the fee for the transaction.

    * `stakeAccount` — account address that stores tokens for staking.

    * `stakeAuthority` — account address that can perform staking operations with the staking account.

    * `unsignedTransaction` — unsigned transaction in Base64 encrypted 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.

    > The transaction exists for one minute.

    2. Use `unsignedTransaction` to [sign and send](/docs/signing-transaction-solana) the signed transaction to the Solana network.
  </Step>
</Steps>


## Related topics

- [Staking API reference](/reference/solana-staking-stake.md)
