Getting Started

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

  1. Approve token management with the Polygon smart contract.
  2. Create a stake transaction.
  3. Sign and send the transaction to the network.

Get an authentication token to start using Staking API.

A request example is provided using cURL.

1. Approve Token Management

Allow the Polygon smart contract to manage tokens by obtaining approval. Any amount can be approved, but it is preferable to specify the exact amount ready to stake.

Send a POST request to /api/v1/polygon/staking/approve. Use https://api.p2p.org for production.

Example request:

curl --request POST \
		 --url https://api.p2p.org/api/v1/polygon/staking/approve \
     --head 'accept: application/json' \
     --head 'Authorization: Bearer <token>' \
     --head 'Content-Type: application/json' \
     --data '
{
  "amount": "100000000000000000",
  "stakerAddress": "0x39D02C253dA1d9F85ddbEB3B6Dc30bc1EcBbFA17"
}
'
  • amount — amount of tokens in Wei (1 MATIC = 10^18 Wei) to approve for staking.
  • stakerAddress — staker account address.

Example response:

{
  "result": {
    "serializeTx": "0x02f86505800214830186a094499d11e0b6eac7c0593d8fb292dcbbf815fb29ae80b844095ea7b300000000000000000000000000200ea4ee292e253e6ca07dba5edc07c8aa37a3000000000000000000000000000000000000000000000000016345785d8a0000c0",
    "to": "0x499d11E0b6eAC7c0593d8Fb292DCBbF815Fb29Ae",
    "gasLimit": "0.0000000000001",
    "data": "0x095ea7b300000000000000000000000000200ea4ee292e253e6ca07dba5edc07c8aa37a3000000000000000000000000000000000000000000000000016345785d8a0000",
    "value": "0.0",
    "chainId": 1,
    "type": 2,
    "maxFeePerGas": "0.00000000000000002",
    "maxPriorityFeePerGas": "2"
  }
}
  • serializeTx — serialized unsigned transaction.
  • to — recipient address for this transaction.
  • gasLimit — maximum gas 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.
  • typeEIP-2718 type of this transaction envelope.
  • maxFeePerGas — maximum price per unit of gas this transaction will pay for the combined 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 block's base fee. This added fee is used to incentivize miners to prioritize this transaction.

2. Create Stake Transaction

To create a stake transaction, delegate tokens to P2P validator by sending a POST request to /api/v1/polygon/staking/delegate.

Example request:

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"
}
'
  • amount — amount of tokens in Wei (1 MATIC = 10^18 Wei) to delegate.
  • stakerAddress — staker account address.

Example response is the same as in the Approve Token Management step.

3. Sign and Send Transaction

Construct a signature and send the transaction to the Ethereum network. All the required data can be retrieved from the previous step within the serializeTx object.

Check an example of how to sign and send a transaction to the Ethereum network.

What's Next?