Undelegate $MATIC
The undelegation process in Polygon takes time to complete.
It is a two step process:
- Unbonding transaction — This starts the unbonding of the specified number of MATIC tokens.
- Claim transaction — This claims MATIC back into the delegating address once the unbonding period is complete.
In the following guide we will illustrate how to unstake MATIC.
Step 1 - Initiate Flow
Endpoint : flow
Method : POST
Request
Body
service_code* -string: Service code, use service endpoint to get the servicecode.flow* -string: The operation to performundelegate.callback_url-string: Your callback url endpoint to get update ofstatefrom our systems.
Request Sample
{
"service_code": "polygon-pos",
"flow": "undelegate"
}
Response
id-string: Flow ID.service_code-string: Current flow service code.flow-string: Current flow name.inquiry_id-string: ID For next Request Step Inquiry.inquiry_identifier-string: Next step identifier name.staking-assign-data: Next you need to assign the staking data.state-string: Current state of your flow.inputs-Array<Object>: Next step inputs.data-Object: Stored data of your flow.created_at-Timestamp RFC3339: Time when flow created.updated_at-Timestamp RFC3339: Last flow updated.expired_at-Timestamp RFC3339: Maximum time you have to finish the process before flow dropped by system, will always increment by your last action +2 hours.
Success Sample
{
"status": 1,
"status_service": "00",
"status_number": "F000001",
"status_code": "SSSSSS",
"message": "success",
"data": {
"id": "4f5bae01-2c11-490a-a61f-4ddde296dbd1",
"service_code": "staking-matic",
"flow": "undelegate",
"inquiry_id": "bdf6dd09-8b15-4653-b010-03dded42e788",
"inquiry_identifier": "create-undelegate-tx",
"state": "initialized",
"inputs": [
{
"type": "string",
"name": "delegator_address",
"display": "Delegator Address",
"description": "Delegator address",
"validations": [
{
"type": "string",
"options": {}
}
],
"array": 0,
"default_val": null,
"visibility": 1
},
{
"type": "string",
"name": "validator_code",
"display": "Validator Code",
"description": "Validator code",
"validations": [
{
"type": "string",
"options": {}
}
],
"array": 0,
"default_val": null,
"visibility": 1
},
{
"type": "decimal",
"name": "amount",
"display": "Amount",
"description": "Amount",
"validations": [
{
"type": "presence",
"options": {}
},
{
"type": "numericality",
"options": {
"greater_than": "0"
}
}
],
"array": 0,
"default_val": null,
"visibility": 1
},
{
"type": "integer",
"name": "maximum_shares_to_burn",
"display": "Maximum Shares To Burn",
"description": "Maximum shares to burn",
"validations": [
{
"type": "numericality",
"options": {
"allow_nil": "1",
"greater_than_or_equal_to": "0"
}
}
],
"array": 0,
"default_val": null,
"visibility": 1
},
{
"type": "integer",
"name": "max_slippage_percentage",
"display": "Max Slippage Percentage",
"description": "Max slippage percentage",
"validations": [
{
"type": "numericality",
"options": {
"allow_nil": "1",
"greater_than_or_equal_to": "0",
"less_than_or_equal_to": "100",
"only_integer": "1"
}
}
],
"array": 0,
"default_val": null,
"visibility": 1
},
{
"type": "string",
"name": "gas_limit",
"display": "Gas Limit",
"description": "Gas limit",
"validations": [
{
"type": "numericality",
"options": {
"allow_blank": "1",
"greater_than": "0",
"only_integer": "1"
}
}
],
"array": 0,
"default_val": null,
"visibility": 1
},
{
"type": "string",
"name": "gas_price",
"display": "Gas Price",
"description": "Gas price in Gwei",
"validations": [
{
"type": "numericality",
"options": {
"allow_blank": "1",
"greater_than": "0"
}
},
{
"type": "precision",
"options": {
"allow_blank": "1",
"max": "9"
}
}
],
"array": 0,
"default_val": null,
"visibility": 1
}
],
"data": {},
"created_at": "2024-03-12T18:12:42Z",
"updated_at": "2024-03-12T18:12:42Z",
"expired_at": "2024-03-12T20:12:42Z"
}
}
Step 2 - Create Undelegate Transaction
Endpoint : flow/{:id}/next
Method : POST
Request
Body
inquiry_id* -string: Your inquiry id from step 1data-object* : Wrapped data objectvalidator_code-string: Validator code, use validator endpoint to get the validatorcode, we will set it automatically if you not send it.delegator_address* -string: Address which you want to use to undelegate.amount* -float64: Amount of Matic Token you want to undelegate.max_shares_to_burn-string: The minimum number of shares of the delegation pool to be minted. If the exchange rate results in fewer shares being minted, the transaction will fail.max_slippage_percentage-float64: The maximum slippage you are willing to accept.gas_limit-float64: Set Gas Limit for transaction, if not provided, we will us onchain suggested price.gas_price-float64: Set Gas Price for transaction, if not provided, we will us onchain suggested price.
Sample Endpoint Request : flow/269407c3-315f-4006-95e2-30f2e70891cc/next
Request Sample
{
"inquiry_id":"bdf6dd09-8b15-4653-b010-03dded42e788",
"data": {
"delegator_address": "0xC5933308625306c2dAB7602b52b80dceEa133532",
"validator_code": "NOBIMMT01",
"amount": 1.25
}
}
Response
id-string: Flow ID.service_code-string: Current flow service code.flow-string: Current flow name.inquiry_id-string: ID For next Request Step Inquiry.inquiry_identifier-string: Next step identifier name.staking-undelegate-tx: Next will be undelegate tx.
state-string: Current state of your flow.inputs-Array<Object>: Next step inputs.data-Object: Stored data of your flow.created_at-Timestamp RFC3339: Time when flow created.updated_at-Timestamp RFC3339: Last flow updated.expired_at-Timestamp RFC3339: Maximum time you have to finish the process before flow dropped by system, will always increment by your last action +2 hours.
Success Sample
{
"status": 1,
"status_service": "00",
"status_number": "F000001",
"status_code": "SSSSSS",
"message": "success create data",
"data": {
"id": "4f5bae01-2c11-490a-a61f-4ddde296dbd1",
"service_code": "staking-matic",
"flow": "undelegate",
"inquiry_id": "e94868d6-c5a1-4f32-92c9-61177e6974b6",
"inquiry_identifier": "staking-undelegate-sign",
"state": "initialized",
"inputs": [
{
"type": "string",
"name": "signed_tx_payload",
"display": "Signed Tx Payload",
"description": "Signed transaction payload",
"validations": [
{
"type": "presence",
"options": {}
},
{
"type": "signed_transaction",
"options": {}
}
],
"array": 0,
"default_val": null,
"visibility": 0
}
],
"data": {
"amount": "1.25",
"callback_url": "",
"claim_tx": "",
"delegator_address": "0xC5933308625306c2dAB7602b52b80dceEa133532",
"exchange_rate": "",
"exchange_rate_precision": "",
"gas_limit": "",
"gas_price": "",
"max_slippage_percentage": "",
"maximum_shares_to_burn": "",
"undelegate_tx": "0x02f868801f8002830493e094b929b89153fc2eed442e81e5a1add4e2fa39028f80b844c83ec04d0000000000000000000000000000000000000000000000001158e460913d00000000000000000000000000000000000000000000000000001158e460913d0000c0808080",
"validator_address": "0xb929B89153fC2eEd442e81E5A1add4e2fa39028f",
"validator_code": "NOBIMMT01"
},
"created_at": "2024-03-12T18:12:42Z",
"updated_at": "2024-03-12T18:12:42Z",
"expired_at": "2024-03-12T20:12:42Z"
}
}
Step 2.1 - Submit Signed Undelegate Transaction
Endpoint : flow/{:id}/next
Method : POST
Request
Body
inquiry_id* -string: Your inquiry id from step 1data* -object: Wrapped data objectsigned_tx_payload* -string: Signed transaction payload
Sample Endpoint Request : flow/269407c3-315f-4006-95e2-30f2e70891cc/next
Request Sample
{
"inquiry_id":"e94868d6-c5a1-4f32-92c9-61177e6974b6",
"data": {
"signed_tx_payload":"0x02f8a8011f8002830493e094b929b89153fc2eed442e81e5a1add4e2fa39028f80b844c83ec04d0000000000000000000000000000000000000000000000001158e460913d00000000000000000000000000000000000000000000000000001158e460913d0000c080a0107dc880476c1dbc9df0bf935bad5a4215372b7d00dd8cbc6c7877331bf5f591a033eea1693ffa8bf798dc325c2e60519fda929800ef352b63f5cd09afec0086c9"
}
}
To retry the undelegate signing transaction, just resubmit the inquiry.
Response
id-string: Flow ID.service_code-string: Current flow service code.flow-string: Current flow name.state-string: Current state of your flow.data-Object: Stored data of your flow.created_at-Timestamp RFC3339: Time when flow created.updated_at-Timestamp RFC3339: Last flow updated.expired_at-Timestamp RFC3339: Maximum time you have to finish the process before flow dropped by system, will always increment by your last action +2 hours.
Success Sample
{
"status": 1,
"status_service": "00",
"status_number": "F000001",
"status_code": "SSSSSS",
"message": "success create data",
"data": {
"id": "4f5bae01-2c11-490a-a61f-4ddde296dbd1",
"service_code": "staking-matic",
"flow": "undelegate",
"inquiry_id": "36b907d3-eef8-4970-b20e-b747a52f69f9",
"inquiry_identifier": "staking-claim-tx",
"state": "initialized",
"inputs": [
{
"type": "string",
"name": "gas_limit",
"display": "Gas Limit",
"description": "Gas limit",
"validations": [
{
"type": "numericality",
"options": {
"allow_blank": "1",
"greater_than": "0",
"only_integer": "1"
}
}
],
"array": 0,
"default_val": null,
"visibility": 1
},
{
"type": "string",
"name": "gas_price",
"display": "Gas Price",
"description": "Gas price in Gwei",
"validations": [
{
"type": "numericality",
"options": {
"allow_blank": "1",
"greater_than": "0"
}
},
{
"type": "precision",
"options": {
"allow_blank": "1",
"max": "9"
}
}
],
"array": 0,
"default_val": null,
"visibility": 1
}
],
"data": {
"amount": "1.25",
"callback_url": "",
"claim_tx": "",
"delegator_address": "0xC5933308625306c2dAB7602b52b80dceEa133532",
"exchange_rate": "",
"exchange_rate_precision": "",
"gas_limit": "",
"gas_price": "",
"max_slippage_percentage": "",
"maximum_shares_to_burn": "",
"undelegate_tx": "0x02f868801f8002830493e094b929b89153fc2eed442e81e5a1add4e2fa39028f80b844c83ec04d0000000000000000000000000000000000000000000000001158e460913d00000000000000000000000000000000000000000000000000001158e460913d0000c0808080",
"validator_address": "0xb929B89153fC2eEd442e81E5A1add4e2fa39028f",
"validator_code": "NOBIMMT01"
},
"created_at": "2024-03-12T18:12:42Z",
"updated_at": "2024-03-12T18:12:42Z",
"expired_at": "2024-03-12T20:12:42Z"
}
}
Step 3 - Create Claim Transaction
Undelegate need 80 checkpoints to complete, after the undelegate process complete, to get your matic back to your wallet, you need to claim it.
Endpoint : flow/{:id}/next
Method : POST
Request
Body
inquiry_id* -string: Your inquiry id from step 1data-object: Wrapped data objectgas_limit-float64: Set Gas Limit for transaction, if not provided, we will us onchain suggested price.gas_price-float64: Set Gas Price for transaction, if not provided, we will us onchain suggested price.
Sample Endpoint Request : flow/269407c3-315f-4006-95e2-30f2e70891cc/next
Request Sample
{
"inquiry_id":"36b907d3-eef8-4970-b20e-b747a52f69f9",
"data": {
"delegator_address": "0xC5933308625306c2dAB7602b52b80dceEa133532",
"validator_code": "NOBIMMT01"
}
}
To refresh the undelegate transaction, just resubmit the inquiry.
Response
id-string: Flow ID.service_code-string: Current flow service code.flow-string: Current flow name.inquiry_id-string: ID For next Request Step Inquiry.inquiry_identifier-string: Next step identifier name.staking-claim-sign: Next flow will be signing and broadcast tx.
state-string: Current state of your flow.inputs-Array<Object>: Next step inputs.data-Object: Stored data of your flow.created_at-Timestamp RFC3339: Time when flow created.updated_at-Timestamp RFC3339: Last flow updated.expired_at-Timestamp RFC3339: Maximum time you have to finish the process before flow dropped by system, will always increment by your last action +2 hours.
Success Sample
{
"status": 1,
"status_service": "00",
"status_number": "F000001",
"status_code": "SSSSSS",
"message": "success create data",
"data": {
"id": "4f5bae01-2c11-490a-a61f-4ddde296dbd1",
"service_code": "staking-matic",
"flow": "undelegate",
"inquiry_id": "23b9a176-1d13-4d4d-ba6e-13a2b935296e",
"inquiry_identifier": "staking-claim-sign",
"state": "initialized",
"inputs": [
{
"type": "string",
"name": "signed_tx_payload",
"display": "Signed Tx Payload",
"description": "Signed transaction payload",
"validations": [
{
"type": "presence",
"options": {}
},
{
"type": "signed_transaction",
"options": {}
}
],
"array": 0,
"default_val": null,
"visibility": 0
}
],
"data": {
"amount": "1.25",
"callback_url": "",
"claim_tx": "0x02f84780208002830493e094b929b89153fc2eed442e81e5a1add4e2fa39028f80a4e97fddc20000000000000000000000000000000000000000000000000000000000000001c0808080",
"delegator_address": "0xC5933308625306c2dAB7602b52b80dceEa133532",
"exchange_rate": "",
"exchange_rate_precision": "",
"gas_limit": "",
"gas_price": "",
"max_slippage_percentage": "",
"maximum_shares_to_burn": "",
"undelegate_tx": "0x02f868801f8002830493e094b929b89153fc2eed442e81e5a1add4e2fa39028f80b844c83ec04d0000000000000000000000000000000000000000000000001158e460913d00000000000000000000000000000000000000000000000000001158e460913d0000c0808080",
"validator_address": "0xb929B89153fC2eEd442e81E5A1add4e2fa39028f",
"validator_code": "NOBIMMT01"
},
"created_at": "2024-03-12T18:12:42Z",
"updated_at": "2024-03-12T18:12:42Z",
"expired_at": "2024-03-12T20:12:42Z"
}
}
Step 3.1 - Submit Signed Undelegate Transaction
Endpoint : flow/{:id}/next
Method : POST
Request
Body
inquiry_id* -string: Your inquiry id from step 1data* -object: Wrapped data objectsigned_tx_payload* -string: Signed transaction payload
Sample Endpoint Request : flow/269407c3-315f-4006-95e2-30f2e70891cc/next
Request Sample
{
"inquiry_id":"23b9a176-1d13-4d4d-ba6e-13a2b935296e",
"data": {
"signed_tx_payload":"0x02f88701208002830493e094b929b89153fc2eed442e81e5a1add4e2fa39028f80a4e97fddc20000000000000000000000000000000000000000000000000000000000000001c080a070474a40f7ec4cb7508fe2ab09802d6bb2d1c78ce793479e52e06df132a46db0a03f860d7540f73092233958429db15212aa5ff7ec4f981735c4afde72a79cd9f1"
}
}
To retry the undelegate signing transaction, just resubmit the inquiry.
Response
id-string: Flow ID.service_code-string: Current flow service code.flow-string: Current flow name.state-string: Current state of your flow.data-Object: Stored data of your flow.created_at-Timestamp RFC3339: Time when flow created.updated_at-Timestamp RFC3339: Last flow updated.expired_at-Timestamp RFC3339: Maximum time you have to finish the process before flow dropped by system, will always increment by your last action +2 hours.
Success Sample
{
"status": 1,
"status_service": "00",
"status_number": "F000001",
"status_code": "SSSSSS",
"message": "success create data",
"data": {
"id": "4f5bae01-2c11-490a-a61f-4ddde296dbd1",
"service_code": "staking-matic",
"flow": "undelegate",
"state": "initialized",
"data": {
"amount": "1.25",
"callback_url": "",
"claim_tx": "0x02f84780208002830493e094b929b89153fc2eed442e81e5a1add4e2fa39028f80a4e97fddc20000000000000000000000000000000000000000000000000000000000000001c0808080",
"delegator_address": "0xC5933308625306c2dAB7602b52b80dceEa133532",
"exchange_rate": "",
"exchange_rate_precision": "",
"gas_limit": "",
"gas_price": "",
"max_slippage_percentage": "",
"maximum_shares_to_burn": "",
"undelegate_tx": "0x02f868801f8002830493e094b929b89153fc2eed442e81e5a1add4e2fa39028f80b844c83ec04d0000000000000000000000000000000000000000000000001158e460913d00000000000000000000000000000000000000000000000000001158e460913d0000c0808080",
"validator_address": "0xb929B89153fC2eEd442e81E5A1add4e2fa39028f",
"validator_code": "NOBIMMT01"
},
"created_at": "2024-03-12T18:12:42Z",
"updated_at": "2024-03-12T18:12:42Z",
"expired_at": "2024-03-12T20:12:42Z"
}
}