> ## 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.

# Getting Started

> Stake on Solana programmatically with the P2P.org Staking API.

Staking in the Solana network using the Staking API consists of several main steps:

1. Create a staking request.
2. Sign and send the transaction to the network.

[Get an authentication token](/docs/authentication) to start using Staking API.

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

```mermaid theme={null}
sequenceDiagram
    participant Client
    participant P2P API
    participant Blockchain
    Client->>P2P API: Create stake transaction
    P2P API-->>Client: Unsigned transaction
    Client->>Client: Sign transaction locally
    Client->>P2P API: Broadcast signed transaction
    P2P API->>Blockchain: Submit transaction
    Blockchain-->>P2P API: Transaction hash
    P2P API-->>Client: Transaction status
```

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

    Example request (for `testnet` network):

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

      ```typescript TypeScript theme={null}
      const response = await fetch(
        "https://api-test.p2p.org/api/v1/solana/testnet/staking/stake",
        {
          method: "POST",
          headers: {
            "Accept": "application/json",
            "Authorization": "Bearer <token>",
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            feePayer: "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf",
            fromPublicKey: "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf",
            amount: "1002282880",
            stakeAuthority: "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf",
            withdrawAuthority: "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf",
          }),
        }
      );
      ```

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

      response = requests.post(
          "https://api-test.p2p.org/api/v1/solana/testnet/staking/stake",
          headers={
              "Accept": "application/json",
              "Authorization": "Bearer <token>",
              "Content-Type": "application/json",
          },
          json={
              "feePayer": "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf",
              "fromPublicKey": "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf",
              "amount": "1002282880",
              "stakeAuthority": "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf",
              "withdrawAuthority": "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf",
          },
      )
      ```

      ```go Go theme={null}
      import (
          "bytes"
          "net/http"
      )

      body := []byte(`{
        "feePayer": "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf",
        "fromPublicKey": "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf",
        "amount": "1002282880",
        "stakeAuthority": "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf",
        "withdrawAuthority": "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf"
      }`)

      req, _ := http.NewRequest("POST",
          "https://api-test.p2p.org/api/v1/solana/testnet/staking/stake",
          bytes.NewBuffer(body))
      req.Header.Set("Accept", "application/json")
      req.Header.Set("Authorization", "Bearer <token>")
      req.Header.Set("Content-Type", "application/json")

      resp, err := http.DefaultClient.Do(req)
      ```
    </CodeGroup>

    * `feePayer` — account address that will pay the fee for the transaction.
    * `fromPublicKey` — account address from which the staking account will be created.
    * `amount` — amount of tokens to stake in lamports (1 SOL = 10⁹ lamports). The minimum amount is `1002282880`.
    * `stakeAuthority` — account address that can perform staking operations with the staking account. If not specified, rights will be taken from the `fromPublicKey` parameter.
    * `withdrawAuthority` — account address that can perform withdrawal operations with the staking account. If not specified, rights will be taken from the `fromPublicKey` parameter.

    Example response:

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

    * `feePayer` — account address that will pay the fee for the transaction.
    * `fromPublicKey` — account address from which the staking account will be created.
    * `stakeAccount` — account address that stores tokens for staking.
    * `stakeAuthority` — account address that can perform staking operations with the staking account.
    * `withdrawAuthority` — account address that can perform withdrawal operations with the staking account.
    * `amount` — amount of tokens to stake in lamports (1 SOL = 10⁹ lamports). The minimum amount is `1002282880`.
    * `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.
  </Step>

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

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

    Example request (for `testnet` network):

    <CodeGroup>
      ```bash theme={null}
      curl --request GET \
           --url https://api-test.p2p.org/api/v1/solana/testnet/account/staking?stakeAuthorities=7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf&withdrawAuthorities=7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf \
           --header 'accept: application/json' \
           --header 'authorization: Bearer <token>' \
           --header 'content-type: application/json'
      ```
    </CodeGroup>

    * `stakeAuthorities` — list of account addresses that can perform staking operations with staking accounts.
    * `stakeAccounts` — list of staking account addresses.
    * `withdrawAuthorities` — list of account addresses that can perform withdrawal operations with the staking accounts.
    * `status` — staking account status: `active`, `inactive`, `activating`, `deactivating`.

    Example response:

    <CodeGroup>
      ```json theme={null}
      {
          "result": {
            "accounts": [
              "amount": 2282881,
              "stakeAccount": "1298uXQBW2azVA33UonLu2RoouDWkNqsV1rMUrQAy1SN",
              "withdrawAuthority": "7E5LgJx7w7AfoeA5YgLPZFdBptz18nhdT7hxZuDA9aQf",
              "stakeAuthority": "AaMC5y1RofbY3unyrahRzyCzsesp7rfGuaGegbAg1Hxb",
              "voteAccount": "FKsC411dik9ktS6xPADxs4Fk2SCENvAiuccQHLAPndvk",
              "status": "active"
            ]
          }
        }
      ```
    </CodeGroup>

    * `accounts` — list of stake accounts.

      * `amount` — amount of tokens to stake in lamports (1 SOL = 10⁹ lamports).
      * `stakeAccount` — account address that stores tokens for staking.
      * `stakeAuthority` — account address that can perform staking operations with the staking account.
      * `withdrawAuthority` — account address that can perform withdrawal operations with the staking account.
      * `voteAccount` — vote account address.
      * `status` — stake account status: `active`, `inactive`, `activating`, `deactivating`.
  </Step>
</Steps>


## Related topics

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