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

Staking on the Polygon network using the Staking API consists of the following steps:

1. Approve token management with the Polygon smart contract.
2. Create a staking request.

After each operation, [sign and send the transaction](/docs/signing-transaction-polygon) to the Polygon 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 approve transaction
    P2P API-->>Client: Unsigned approve transaction
    Client->>Client: Sign transaction locally
    Client->>Blockchain: Broadcast approve transaction
    Blockchain-->>Client: Approval confirmed
    Client->>P2P API: Create delegate transaction
    P2P API-->>Client: Unsigned delegate transaction
    Client->>Client: Sign transaction locally
    Client->>Blockchain: Broadcast delegate transaction
    Blockchain-->>Client: Delegation confirmed
```

<Steps>
  <Step title="Approve token management">
    Allow the Polygon smart contract to manage tokens by obtaining approval. Any amount can be approved, but preferably specify the exact amount ready to stake.

    Send a POST request to [/api/v1/polygon/staking/approve](/reference/polygon-staking-approve). Use [https://api.p2p.org](https://api.p2p.org) for production.

    Example request:

    <CodeGroup>
      ```bash curl theme={null}
      curl --request POST \
           --url https://api.p2p.org/api/v1/polygon/staking/approve \
           --header 'accept: application/json' \
           --header 'Authorization: Bearer <token>' \
           --header 'Content-Type: application/json' \
           --data '
      {
        "amount": "1000000000000000000",
        "stakerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17"
      }'
      ```

      ```typescript TypeScript theme={null}
      const response = await fetch(
        "https://api.p2p.org/api/v1/polygon/staking/approve",
        {
          method: "POST",
          headers: {
            "accept": "application/json",
            "Authorization": "Bearer <token>",
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            amount: "1000000000000000000",
            stakerAddress: "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
          }),
        }
      );
      const data = await response.json();
      console.log(data);
      ```

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

      response = requests.post(
          "https://api.p2p.org/api/v1/polygon/staking/approve",
          headers={
              "accept": "application/json",
              "Authorization": "Bearer <token>",
              "Content-Type": "application/json",
          },
          json={
              "amount": "1000000000000000000",
              "stakerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
          },
      )
      print(response.json())
      ```

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

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

      func main() {
      	payload := map[string]interface{}{
      		"amount":        "1000000000000000000",
      		"stakerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
      	}
      	body, _ := json.Marshal(payload)
      	req, _ := http.NewRequest("POST", "https://api.p2p.org/api/v1/polygon/staking/approve", 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>

    * `amount` — amount of tokens in Wei (1 POL = 10¹⁸ Wei) to approve for staking.
    * `stakerAddress` — staker account address.

    Example response:

    <CodeGroup>
      ```json theme={null}
      {
          "result": {
            "serializeTx": "0x02f86505800214830186a094499d11e0b6eac7c0593d8fb292dcbbf815fb29ae80b844095ea7b300000000000000000000000000200ea4ee292e253e6ca07dba5edc07c8aa37a3000000000000000000000000000000000000000000000000016345785d8a0000c0",
            "to": "0x499d11E0b6eAC7c0593d8Fb292DCBbF815Fb29Ae",
            "gasLimit": "0.0000000000001",
            "data": "0x095ea7b300000000000000000000000000200ea4ee292e253e6ca07dba5edc07c8aa37a3000000000000000000000000000000000000000000000000016345785d8a0000",
            "value": "0.0",
            "chainId": 1,
            "type": 2,
            "maxFeePerGas": "0.00000000000000002",
            "maxPriorityFeePerGas": "2"
          }
        }
      ```
    </CodeGroup>

    * `serializeTx` — serialized unsigned transaction.
    * `to` — recipient address for this transaction.
    * `gasLimit` — maximum <Tooltip tip="A measure of computational effort required to execute a transaction or smart contract on a blockchain. Users must pay a gas fee, usually in the native token, to have their transactions processed by the network.">gas</Tooltip> limit for this block.
    * `data` — transaction data.
    * `value` — amount this transaction is sending in Wei.
    * `chainId` — chain ID this transaction is authorized on, as specified by [EIP-155](https://eips.ethereum.org/EIPS/eip-155).
    * `type` — [EIP-2718](https://eips.ethereum.org/EIPS/eip-2718) type of this transaction envelope.
    * `maxFeePerGas` — maximum price per unit of gas this transaction will pay for the combined [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) block's base fee and this transaction's priority fee in Wei.
    * `maxPriorityFeePerGas` — price per unit of gas in Wei, which is added to the [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559) block's base fee. This added fee is used to incentivize miners to prioritize this transaction.
  </Step>

  <Step title="Create staking request">
    To create a stake transaction, delegate tokens to P2P validator by sending a POST request to [/api/v1/polygon/staking/delegate](/reference/polygon-staking-delegate).

    Example request:

    <CodeGroup>
      ```bash curl theme={null}
      curl --request POST \
      		 --url https://api.p2p.org/api/v1/polygon/staking/delegate \
           --head 'accept: application/json' \
           --head 'Authorization: Bearer <token>' \
           --head 'Content-Type: application/json' \
           --data '
      {
        "amount": "100000000000000000",
        "stakerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17"
      }
      '
      ```

      ```typescript TypeScript theme={null}
      const response = await fetch(
        "https://api.p2p.org/api/v1/polygon/staking/delegate",
        {
          method: "POST",
          headers: {
            "accept": "application/json",
            "Authorization": "Bearer <token>",
            "Content-Type": "application/json",
          },
          body: JSON.stringify({
            amount: "100000000000000000",
            stakerAddress: "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
          }),
        }
      );
      const data = await response.json();
      console.log(data);
      ```

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

      response = requests.post(
          "https://api.p2p.org/api/v1/polygon/staking/delegate",
          headers={
              "accept": "application/json",
              "Authorization": "Bearer <token>",
              "Content-Type": "application/json",
          },
          json={
              "amount": "100000000000000000",
              "stakerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
          },
      )
      print(response.json())
      ```

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

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

      func main() {
      	payload := map[string]interface{}{
      		"amount":        "100000000000000000",
      		"stakerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17",
      	}
      	body, _ := json.Marshal(payload)
      	req, _ := http.NewRequest("POST", "https://api.p2p.org/api/v1/polygon/staking/delegate", 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>

    * `amount` — amount of tokens in Wei (1 MATIC = 10¹⁸ Wei) to delegate.
    * `stakerAddress` — staker account address.

    Example response is the same as in the approve token management step.

    To complete staking, [sign and send](/docs/signing-transaction-polygon) the transaction to the Polygon network.
  </Step>
</Steps>


## Related topics

- [Withdrawal](/docs/withdrawal-polygon.md)
- [Staking API reference](/reference/polygon-staking-approve.md)
