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 section.
Key Polygon-specific details
chain
— always set topolygon
for Polygon-related requests.network
— environment in which the transaction is processed (mainnet
only).stakerAddress
— Ethereum-compatible account address initiating staking, unstaking, or withdrawal transactions.amount
— amount of tokens to delegate/undelegate in MATIC (expressed as a decimal, not wei).- Flow uses EIP-1559 (type 2) transactions.
- Staking, unstaking, and withdrawal require interaction with smart contracts via prepared transactions.
Staking Flow
1. Approve Token Management
Before staking, you must approve the staking contract to transfer your MATIC tokens.
Send 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 MATIC to approve for staking (as a decimal string).stakerAddress
— 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
— (string) hex-encoded unsigned transaction (EIP-1559 format). Sign and broadcast this transaction.to
— target contract address for approval.gasLimit
— gas limit for the transaction.data
— encoded transaction calldata for the approval method.value
— value in wei to send (usually "0").=chainId
— Polygon chain ID (mainnet: 137).=type
— transaction type (always 2 for EIP-1559).maxFeePerGas
— max total fee per gas unit (in wei).maxPriorityFeePerGas
— max priority fee per gas (in wei)
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
— always"polygon"
.network
— always"mainnet"
.stakerAddress
— sender address (must match signing key).signedTransaction
— hex-encoded signed transaction.
Example response:
{
"error": null,
"result": {
"extraData": {
"transactionHash": "0x2423921ace5d44e1df4f61a966917b738ae1dd3eaad085efc6eef4275e454088",
"signedTransaction": "<SIGNED_TX_HEX>",
"stakerAddress": "0x368F823e4dfe271dc820f4Ea14689917bf8e4a21",
"sentAt": "2025-04-23T17:21:11.991Z"
}
}
}
transactionHash
— hash of the broadcasted approval transaction.signedTransaction
— signed transaction sent to the network.stakerAddress
— sender address.sentAt
— timestamp (ISO 8601).
3. Create Staking (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
— always"polygon"
.network
— always"mainnet"
.stakerAddress
— address initiating the delegation.amount
— amount of MATIC to delegate (decimal string).
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"
}
}
}
unsignedTransactionData
— hex-encoded unsigned delegation transaction.extraData
— transaction parameters:to
— target contract address.gasLimit
— gas limit.data
— transaction calldata for delegation.value
— value in wei.chainId
,type
,maxFeePerGas
,maxPriorityFeePerGas
— EIP-1559 transaction details.
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
— always"polygon"
.network
— always"mainnet"
.stakerAddress
— address initiating the undelegation.extra.amount
— amount to undelegate (decimal string).
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"
}
}
}
unsignedTransactionData
— hex-encoded unsigned undelegation transaction.extraData
— parsed transaction parameters for reference.
2. Sign and Send Transaction
Use unsignedTransactionData
to sign and send the transaction following the Polygon-specific signing logic.
3. Create Withdrawal Request
After submitting an undelegate transaction, you must wait for the unbonding period (typically ~80 epochs) before withdrawal is possible.
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
— always"polygon"
.network
— always"mainnet"
.stakerAddress
— address initiating the withdrawal.
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"
}
}
}
unsignedTransactionData
— hex-encoded unsigned withdrawal transaction.extraData
— transaction parameters as above.
4. Sign and Send Transaction
Use unsignedTransactionData
to sign and send the transaction following the Polygon-specific signing logic.
What's Next?
Updated 1 day ago