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

Staking on the Sui network using the Staking API consists of the following main steps:

1. Create a staking request.
2. Sign and broadcast the transaction.

[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/sui/\{network}/staking/stake](/reference/sui-staking-stake).

    Example request (for `testnet` network):

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

      ```typescript TypeScript theme={null}
      const response = await fetch(
        "https://api-test.p2p.org/api/v1/sui/testnet/staking/stake",
        {
          method: "POST",
          headers: {
            "accept": "application/json",
            "Authorization": "Bearer <token>",
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            sender: "0x696f4402d7151fb49e52b629de3ce3098f3dda7721a7425c000b4f26653709e3",
            amount: 1000000000,
            gasPrice: 1000,
            gasBudget: 500000000,
          }),
        }
      );
      const data = await response.json();
      console.log(data);
      ```

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

      response = requests.post(
          "https://api-test.p2p.org/api/v1/sui/testnet/staking/stake",
          headers={
              "accept": "application/json",
              "Authorization": "Bearer <token>",
              "Content-Type": "application/json",
          },
          json={
              "sender": "0x696f4402d7151fb49e52b629de3ce3098f3dda7721a7425c000b4f26653709e3",
              "amount": 1000000000,
              "gasPrice": 1000,
              "gasBudget": 500000000,
          },
      )
      print(response.json())
      ```

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

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

      func main() {
      	payload := map[string]interface{}{
      		"sender":    "0x696f4402d7151fb49e52b629de3ce3098f3dda7721a7425c000b4f26653709e3",
      		"amount":    1000000000,
      		"gasPrice":  1000,
      		"gasBudget": 500000000,
      	}
      	body, _ := json.Marshal(payload)
      	req, _ := http.NewRequest("POST", "https://api-test.p2p.org/api/v1/sui/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, _ := http.DefaultClient.Do(req)
      	defer resp.Body.Close()
      	respBody, _ := io.ReadAll(resp.Body)
      	fmt.Println(string(respBody))
      }
      ```
    </CodeGroup>

    * `sender` — staker account address.
    * `amount` — amount of tokens to stake in MIST (1 SUI = 10⁹ MIST).
    * `gasPrice` — price per unit of gas in MIST for processing the Sui transaction.
    * `gasBudget` — maximum gas limit for the transaction.

    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.

    Check your staking position and status by sending 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, which is required to perform a withdrawal later.

      * `amount` — amount of tokens to stake in MIST (1 SUI = 10⁹ MIST).

      * `status` — staking transaction status:

        * `pending` — stake has been submitted and is awaiting activation. Activation may take up to 12 hours depending on validator configuration.
        * `active` — stake is active and earning rewards.
        * `unstaked` — stake has been withdrawn.
  </Step>
</Steps>


## Related topics

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