Avail
Unified API + Avail Integration Workflow
In the following guide, the integration process for the avail
chain 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
— way of receiving the rewards; the default value isaccount
.rewardDestination
— account address receiving the staking rewards.targets
— validator accounts selected for staking operations.
Staking Flow
1. Create Bond 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
— blockchain network, always set toavail
for Avail-related requests.network
— environment in which the transaction is processed (mainnet
ortestnet
).stakerAddress
— account address initiating the bonding transaction.amount
— amount of tokens to bond. AVAIL is used for the mainnet network.
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 the mainnet network. -
stakerAddress
— staking account address receiving the bonded tokens. -
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
— validators selected in the targets. -
rewardDestinationType
— type of receiving the rewards:staked
— rewards will be sent to the stash account and added to the current bond (compounding rewards).stash
— rewards will be sent to the stash account as a transferable balance (not compounding rewards).controller
— rewards will be sent to the controller account.account
— default; 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 using 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
— account address initiating the bonding 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.
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 Base64 encrypted format, which contains all transaction details (e.g., accounts, instructions, and signatures) required to broadcast the transaction to the network.blockHash
— block hash in which the transaction has been 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 Unstaking 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 initiated the bonding transaction.extra
— additional request parameters:amount
— amount of tokens to unbond. AVAIL is used for the mainnet network.
Example response:
{
"error": null,
"result": {
"stakerAddress": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG",
"unsignedTransactionData": "0x34040a0217000050efe2d6e41a1b",
"createdAt": "2024-12-19T13:25:51.320Z",
"extraData": {
"amount": 500
}
}
}
stakerAddress
— account address initiating 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 the mainnet network.
2. Sign and Send Transaction
Use unsignedTransactionData
to sign and send the transaction following the Avail-specific signing logic.
3. Create Withdrawal Request
Note that the withdrawal is available only after the unbonding period of ~28 days.
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 initiating 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 transaction details.
4. Sign and Send Transaction
Use unsignedTransactionData
to sign and send the transaction following the Avail-specific signing logic.
What's Next?
Updated 7 days ago