Polygon
Unified API + Polygon Integration Workflow
In the following guide, the integration process for the polygon
chain is covered. The Polygon integration aligns with the general Unified API process but with network-specific parameters.
Get an authentication token to start using the Unified API.
Request examples are provided using cURL.
To check the integration guides for other chains, refer to the Networks Supported section.
Key Polygon-specific details
chain
— always set topolygon
for Polygon-related requests.network
— environment in which the transaction is processed:mainnet
ortestnet
.stakerAddress
— Ethereum-compatible account address initiating staking, unstaking or withdrawal transactions.amount
— amount of tokens in MATIC.
Staking Flow
1. Approve Token Management
Note that the flow uses transactions of type 2 (EIP-1559). Staking, unstaking, and withdrawal operations require interaction with smart contracts via prepared transactions.
Approve transferring your MATIC tokens to the staking contract by sending a POST request to /api/v1/polygon/staking/approve.
Example request:
curl --request POST \
--url https://api-test.p2p.org/api/v1/polygon/staking/approve \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
"amount": "1",
"stakerAddress": "0x368F823e4dfe271dc820f4Ea14689917bf8e4a21"
}'
amount
— amount of tokens in MATIC to approve staking operations.stakerAddress
— staker account address providing approval.
Example response:
{
"error": null,
"result": {
"serializeTx": "0x02f86c0180830e57e084b6687a7c830f424094455e53cbb86018ac2b8092fdcd39d8444affc3f680b844095ea7b3000000000000000000000000455e53cbb86018ac2b8092fdcd39d8444affc3f60000000000000000000000000000000000000000000000000de0b6b3a7640000c0",
"to": "0x455e53CBB86018Ac2B8092FdCd39d8444aFFC3F6",
"gasLimit": "1000000",
"data": "0x095ea7b3...",
"value": "0",
"chainId": 137,
"type": 2,
"maxFeePerGas": "3060300412",
"maxPriorityFeePerGas": "940000"
}
}
serializeTx
— serialized unsigned transaction (EIP-1559 format).to
— recipient contract address for approval.gasLimit
— maximum gas limit for the transaction.data
— transaction data.value
— amount this transaction is sending in Wei.chainId
— chain ID this transaction is authorized on, as specified by EIP-155. Polygon chain ID formainnet
is 137.type
— EIP-1559 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. Sign and Send Transaction
Use serializeTx
to sign the transaction using the Polygon-specific signing logic.
To broadcast the signed transaction to the Polygon network, send a POST request to /api/v1/unified/transaction/broadcast.
Example request:
curl --request POST \
--url https://api-test.p2p.org/api/v1/unified/transaction/broadcast \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
"chain": "polygon",
"network": "mainnet",
"signedTransaction": "<SIGNED_TX_HEX>",
"stakerAddress": "0x368F823e4dfe271dc820f4Ea14689917bf8e4a21",
"extra": {}
}'
chain
— blockchain network, always set topolygon
for Polygon-related requests.network
— environment in which the transaction is processed:mainnet
ortestnet
.signedTransaction
— signed transaction in Base64 encrypted format, which contains all transaction details (e.g., accounts, instructions, and signatures) required to broadcast the transaction to the network.stakerAddress
— staker account address initiating the staking transaction.extra
— additional request parameters.
Example response:
{
"error": null,
"result": {
"extraData": {
"transactionHash": "0x2423921ace5d44e1df4f61a966917b738ae1dd3eaad085efc6eef4275e454088",
"signedTransaction": "<SIGNED_TX_HEX>",
"stakerAddress": "0x368F823e4dfe271dc820f4Ea14689917bf8e4a21",
"sentAt": "2025-04-23T17:21:11.991Z"
}
}
}
extraData
— additional transaction details:transactionHash
— hash of the broadcasted approval transaction.signedTransaction
— signed transaction in Base64 encrypted format, which contains all transaction details (e.g., accounts, instructions, and signatures) required to broadcast the transaction to the network.stakerAddress
— staking account address initiating the delegate transaction.sentAt
— timestamp of the transaction in the ISO 8601 format.
3. Create Delegate Request
Send a POST request to /api/v1/unified/staking/stake.
Example request:
curl --request POST \
--url https://api-test.p2p.org/api/v1/unified/staking/stake \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
"chain": "polygon",
"network": "mainnet",
"stakerAddress": "0x368F823e4dfe271dc820f4Ea14689917bf8e4a21",
"amount": "1"
}'
chain
— blockchain network.network
— environment in which the transaction is processed.stakerAddress
— staker account address initiating the staking transaction.amount
— amount of tokens to delegate in MATIC.
Example response:
{
"error": null,
"result": {
"stakerAddress": "0x368F823e4dfe271dc820f4Ea14689917bf8e4a21",
"unsignedTransactionData": "0x02f86c0180830e57e084a51c350e830f42409415c2b3adca66e26b6f230b4023f52a285b7f999580b8446ab150710000000000000000000000000000000000000000000000000de0b6b3a76400000000000000000000000000000000000000000000000000000000000000000000c0",
"extraData": {
"to": "0x15C2b3AdcA66E26B6F230b4023f52a285b7f9995",
"gasLimit": "1000000",
"data": "0x6ab15071...",
"value": "0",
"chainId": 137,
"type": 2,
"maxFeePerGas": "2770089230",
"maxPriorityFeePerGas": "940000"
}
}
}
stakerAddress
— staker account address initiated the delegate transaction.unsignedTransactionData
— unsigned transaction in Base64 encrypted format. Sign the transaction and submit it to the blockchain to perform the called action.extraData
— additional transaction details:to
— recipient contract address for approval.gasLimit
— maximum gas limit for the transaction.data
— transaction data.value
— amount this transaction is sending in Wei.chainId
— chain ID this transaction is authorized on, as specified by EIP-155. Polygon chain ID formainnet
is 137.type
— EIP-1559 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.
4. Sign and Send Transaction
Use unsignedTransactionData
to sign and send the transaction following the Polygon-specific signing logic.
Unstaking Flow
1. Create Undelegate Request
Send a POST request to /api/v1/unified/staking/unstake.
Example request:
curl --request POST \
--url https://api-test.p2p.org/api/v1/unified/staking/unstake \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
"chain": "polygon",
"network": "mainnet",
"stakerAddress": "0x368F823e4dfe271dc820f4Ea14689917bf8e4a21",
"extra": {
"amount": "1"
}
}'
chain
— blockchain network.network
— environment in which the transaction is processed.stakerAddress
— staker account address initiating the undelegate transaction.extra
— additional request parameters:amount
— amount of tokens to undelegate in MATIC.
Example response:
{
"error": null,
"result": {
"stakerAddress": "0x368F823e4dfe271dc820f4Ea14689917bf8e4a21",
"unsignedTransactionData": "0x02f86c0180830e57e084a8c1ba86830f42409415c2b3adca66e26b6f230b4023f52a285b7f999580b844c83ec04d...",
"extraData": {
"to": "0x15C2b3AdcA66E26B6F230b4023f52a285b7f9995",
"gasLimit": "1000000",
"data": "0xc83ec04d...",
"value": "0",
"chainId": 137,
"type": 2,
"maxFeePerGas": "2831268486",
"maxPriorityFeePerGas": "940000"
}
}
}
stakerAddress
— staker account address initiated the undelegate transaction.unsignedTransactionData
— unsigned transaction in Base64 encrypted format. Sign the transaction and submit it to the blockchain to perform the called action.extraData
— additional transaction details:to
— recipient contract address for approval.gasLimit
— maximum gas limit for the transaction.data
— transaction data.value
— amount this transaction is sending in Wei.chainId
— chain ID this transaction is authorized on, as specified by EIP-155. Polygon chain ID formainnet
is 137.type
— EIP-1559 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. Sign and Send Transaction
Use unsignedTransactionData
to sign and send the transaction following the Polygon-specific signing logic.
3. Create Withdrawal Request
Note that it takes up to 3-4 days to prepare your tokens for unstaking as Polygon uses a system of checkpoints. The average undelegate period on Polygon is 80 checkpoints. Withdrawal is only available after the undelegate period ends.
Send a POST request to /api/v1/unified/staking/withdraw.
Example request:
curl --request POST \
--url https://api-test.p2p.org/api/v1/unified/staking/withdraw \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data '{
"chain": "polygon",
"network": "mainnet",
"stakerAddress": "0x368F823e4dfe271dc820f4Ea14689917bf8e4a21"
}'
chain
— blockchain network.network
— environment in which the transaction is processed.stakerAddress
— staker account address initiating the withdrawal transaction.
Example response:
{
"error": null,
"result": {
"stakerAddress": "0x368F823e4dfe271dc820f4Ea14689917bf8e4a21",
"unsignedTransactionData": "0x02f86c0180830e57e084a51c350e830f42409415c2b3adca66e26b6f230b4023f52a285b7f999580b8444e71d92d...",
"extraData": {
"to": "0x15C2b3AdcA66E26B6F230b4023f52a285b7f9995",
"gasLimit": "1000000",
"data": "0x4e71d92d...",
"value": "0",
"chainId": 137,
"type": 2,
"maxFeePerGas": "2770089230",
"maxPriorityFeePerGas": "940000"
}
}
}
stakerAddress
— staker account address initiated the withdrawal transaction.unsignedTransactionData
— unsigned transaction in Base64 encrypted format. Sign the transaction and submit it to the blockchain to perform the called action.extraData
— additional transaction details:to
— recipient contract address for approval.gasLimit
— maximum gas limit for the transaction.data
— transaction data.value
— amount this transaction is sending in Wei.chainId
— chain ID this transaction is authorized on, as specified by EIP-155. Polygon chain ID formainnet
is 137.type
— EIP-1559 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.
4. Sign and Send Transaction
Use unsignedTransactionData
to sign and send the transaction following the Polygon-specific signing logic.
What's Next?
Updated 19 days ago