Avail
Introduction
The Avail integration aligns with the general Getting Started process, with network-specific parameters highlighted below. parameters and network-specific logic.
Key Avail-Specific Details
chain
— always set to avail for Avail-related requests.network
— specifies the environment (testnet
ormainnet
).stakerAddress
— the account address responsible for staking, unstaking, and withdrawal operations.rewardDestinationType
— specifies where rewards are sent. Common value:account
.rewardDestination
— address to receive staking rewards.targets
— the validator account(s) for staking operations.
Unsigned Transactions — use Avail-specific signing logic for unsignedTransactionData
. For details, refer to Transaction Signing.
Quick Steps for Avail
Staking Flow
- Create a Stake Transaction: Refer to Create Stake Transaction to send the transaction details.
- Sign and Broadcast Transaction: Use Avail-specific signing logic as outlined in Transaction Signing.
Unstaking Flow
- Create Unstake Transaction: Refer to Create an Unstake Transaction to send the transaction details.
- Sign and Broadcast Transaction: Use Avail-specific signing logic as outlined in Transaction Signing.
- Create Withdrawal Transaction: Refer to the Create Withdrawal Transaction section for request structure.
- Sign and Broadcast Transaction: Use Avail-specific signing logic as outlined in Transaction Signing.
Unified API + Avail Integration Workflow
Staking Flow
Step 1. Create Staking Transaction
Send a POST request to https://api-test.p2p.org/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": "avail",
"network": "testnet",
"stakerAddress": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG",
"amount": "1000"
}'
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"
}
}
}
Step 2. Sign and Broadcast transaction
Use unsignedTransactionData
to sign the transaction.
Send a POST request to https://api-test.p2p.org/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"
}'
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"
}
}
}
Unstaking Flow
Step 1: Create an Unstake Transaction
Send a POST request to https://api-test.p2p.org/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
}
}'
Example response:
{
"error": null,
"result": {
"stakerAddress": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG",
"unsignedTransactionData": "0x34040a0217000050efe2d6e41a1b",
"createdAt": "2024-12-19T13:25:51.320Z",
"extraData": {
"amount": 500
}
}
}
Step 2. Sign and Broadcast Unstake Transaction
Sign and broadcast the transaction as outlined above.
Step 3. Create Withdrawal Transaction
Send a POST request to https://api-test.p2p.org/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"
}'
Example response:
{
"error": null,
"result": {
"stakerAddress": "5DHyW8yCpJEAzFm1jyk5qbNXicd3Dg1tyNAEcPVLjTBCQEgG",
"unsignedTransactionData": "0x1c040a0300000000",
"createdAt": "2024-12-19T13:36:13.979Z",
"extraData": {}
}
}
Step 4. Sign and Broadcast Withdrawal Transaction
Sign and broadcast the transaction as outlined above.
What's Next?
Updated 1 day ago