Avail
Unified API + Avail Integration Workflow
In the following guide, the integration process for the avail
chain and testnet
network is covered. The Avail 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 Avail-specific details
chain
— always set toavail
for Avail-related requests.network
— environment in which the transaction is processed (testnet
ormainnet
).stakerAddress
— account address initiating staking, unstaking or withdrawal transactions.rewardDestinationType
— parameter which specifies where rewards are sent, the default value isaccount
.rewardDestination
— account address receiving staking rewards.targets
— validator account(s) for staking operations.
Staking Flow
1. Create Bonding Request
Send a POST request to /api/v1/unified/staking/stake.
Example request (for testnet
network):
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": "avail",
"network": "testnet",
"stakerAddress": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG",
"amount": "1000"
}'
chain
— target blockchain network, always set toavail
for Avail-related requests.network
— environment in which the transaction is processed:mainnet
for production use;testnet
for development and testing purposes.stakerAddress
— main account address which keeps tokens for bonding.amount
— amount of tokens to bond. AVAIL is used for themainnet
. Note that there is a dynamic minimum threshold to stake.
Example response:
{
"error": null,
"result": {
"amount": 1000,
"stakerAddress": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG",
"unsignedTransactionData": "0x550104010208...",
"extraData": {
"targets": ["5G6Zhgm59oujA5UW8wMu4XHFP59uenjC2xp1zshyrWVa638J"],
"rewardDestinationType": "account",
"rewardDestination": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG",
"createdAt": "2024-12-19T11:51:03.477Z"
}
}
}
amount
— amount of tokens to bond. AVAIL is used for themainnet
.stakerAddress
— main account address which keeps tokens for bonding.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:targets
— selected validator account(s) in the targets.withdrawAuthority
— account address that can perform withdrawal operations with the staking account.rewardDestinationType
— rewards destination type, by default isaccount
which means that rewards will be sent to any account specified as a transferable balance.rewardDestination
— rewards destination account address.createdAt
— timestamp of the transaction in the ISO 8601 format.
2. Sign and Send Transaction
Use unsignedTransactionData
to sign the transaction following the Avail-specific signing logic.
To broadcast the signed transaction to the Avail 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": "avail",
"network": "testnet",
"stakerAddress": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG",
"signedTransaction": "0xf1028400365b17c9f769d13458469cf2c0eb89e65bef71e3d86cbc75d07ee7b076ca706f01566c41fdc460e5a2f91003a874f2a8698d83984681b58e58d79c773dd58a80158c58eac3e9589f504d81ed1e82333957c7a06dcc30a12745186b37788e19f388b4000800000102080a00170000a0dec5adc9353603365b17c9f769d13458469cf2c0eb89e65bef71e3d86cbc75d07ee7b076ca706f0a050400b25bf90ee3ce10bce071ef48539e7f2aae424038bffb4a50e1e0d6bf961e982f"
}'
chain
— blockchain network.network
— environment in which the transaction is processed.stakerAddress
— staking account address receiving the staked tokens.signedTransaction
— signed transaction in Base64 encrypted format, which contains all transaction details required to broadcast the transaction to the network (e.g., accounts, instructions, and signatures).
Example response:
{
"error": null,
"result": {
"status": "success",
"extraData": {
"network": "testnet",
"signedTransaction": "0xf1028400365b17c9f769d13458469cf2c0eb89e65bef71e3d86cbc75d07ee7b076ca706f01566c41fdc460e5a2f91003a874f2a8698d83984681b58e58d79c773dd58a80158c58eac3e9589f504d81ed1e82333957c7a06dcc30a12745186b37788e19f388b4000800000102080a00170000a0dec5adc9353603365b17c9f769d13458469cf2c0eb89e65bef71e3d86cbc75d07ee7b076ca706f0a050400b25bf90ee3ce10bce071ef48539e7f2aae424038bffb4a50e1e0d6bf961e982f",
"blockHash": "0xd46b0f2ea6daa7f1012f7feefc1d2475405654700ea4082e376a4f173ae3b85d",
"blockId": 1145872,
"extrinsicId": 1,
"transactionHash": "0x0ad1243d382fd9782b5c51248905a388ccd992df47397feefb7d1f643e72e8dc",
"signerAccount": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG",
"createdAt": "2024-12-19T11:57:38.626Z"
}
}
}
status
— transaction status.extraData
— additional transaction details:network
— environment in which the transaction is processed.signedTransaction
— signed transaction in the hexadecimal format.blockHash
— block hash in which the transaction was included.blockId
— unique block identifier.extrinsicId
— unique extrinsic identifier.transactionHash
— signed transaction in the hexadecimal format.signerAccount
— account that signed the transaction.createdAt
— timestamp of the transaction in the ISO 8601 format.
Unstaking Flow
1. Create Unbonding 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": "avail",
"network": "testnet",
"stakerAddress": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG",
"extra": {
"amount": 500
}
}'
chain
— blockchain network.network
— environment in which the transaction is processed.stakerAddress
— account address initiating the unbonding transaction.extra
— additional transaction details:amount
— amount of tokens to unbond. AVAIL is used for themainnet
.
Example response:
{
"error": null,
"result": {
"stakerAddress": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG",
"unsignedTransactionData": "0x34040a0217000050efe2d6e41a1b",
"createdAt": "2024-12-19T13:25:51.320Z",
"extraData": {
"amount": 500
}
}
}
stakerAddress
— account address initiated the unbonding transaction.unsignedTransactionData
— unsigned transaction in Base64 encrypted format. Sign the transaction and submit it to the blockchain to perform the called action.createdAt
— timestamp of the transaction in the ISO 8601 format.extraData
— additional transaction details:amount
— amount of tokens to unbond. AVAIL is used for themainnet
.
2. Sign and Send Transaction
Use unsignedTransactionData
to sign and send the signed unbonding transaction to the Avail network following the Avail-specific signing logic.
3. Create Withdrawal Request
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": "avail",
"network": "testnet",
"stakerAddress": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG"
}'
chain
— blockchain network.network
— environment in which the transaction is processed.stakerAddress
— account address initiating the withdrawal transaction.
Example response:
{
"error": null,
"result": {
"stakerAddress": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG",
"unsignedTransactionData": "0x1c040a0300000000",
"createdAt": "2024-12-19T13:36:13.979Z",
"extraData": {}
}
}
stakerAddress
— 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.createdAt
— timestamp of the transaction in the ISO 8601 format.extraData
— additional details about the transaction.
4. Sign and Send Transaction
Use unsignedTransactionData
to sign and send the signed withdrawal transaction to the Avail network following the Avail-specific signing logic.
What's Next?
Updated 1 day ago