Get Staker Rewards Earned
This can be used in two ways:
- Query the amount of staking rewards earned over all time. This takes in as input the address or public key of the account.
- Query the amount of staking rewards earned over a period of time. This takes in as input the address or public key of the account, and a start and end timestamp for the duration to search within.
await api.query.getStakerRewardsEarned(<address>)
OR
await api.query.getStakerRewardsEarned(<publicKey>, FROM_TIMESTAMP, TO_TIMESTAMP)
important
You can get the AVN_GATEWAY_URL here.
Get Staker Rewards Earned Over All Time
- Example
- Example Result
- JSON-RPC
- JSON-RPC Output
const AVN_API = require("avn-api");
const AVN_GATEWAY_URL = "<node_url>";
const options = {
suri: "<account_suri>",
};
const API = new AVN_API(AVN_GATEWAY_URL, options);
async function main() {
await api.init();
let result = await api.query.getStakerRewardsEarned(API.address());
console.log(result);
}
(async () => {
await main();
})();
13920000000000
REQUEST
POST <https://AVN_GATEWAY_URL/query>
HEADERS
Content-Type: application/json Authorization': bearer <awtToken>
JSON-RPC Example
curl https://AVN_GATEWAY_URL/query \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: bearer <awtToken>" \
-d '{"jsonrpc":"2.0", "method":"getStakerRewardsEarned", "params":{"accountId":"5DAgxV...DdMr"}, "id":1}'
note
result - string integer value of the rewards earned from staking for all time.
{
"jsonrpc": "2.0",
"id": 1,
"result": "13920000000000"
}
Get Staker Rewards Within A Specific Window
- Example
- Example Result
- JSON-RPC
- JSON-RPC Output
const AVN_API = require("avn-api");
const AVN_GATEWAY_URL = "<node_url>";
const options = {
suri: "<account_suri>",
};
const API = new AVN_API(AVN_GATEWAY_URL, options);
async function main() {
await api.init();
const FROM_TIMESTAMP = 1672531200; // 1st Jan 2023
const TO_TIMESTAMP = 1685574000; // 1st Jun 2023
let result = await api.query.getStakerRewardsEarned(API.publicKey(), FROM_TIMESTAMP, TO_TIMESTAMP);
console.log(result);
}
(async () => {
await main();
})();
13920000000000
REQUEST
POST <https://AVN_GATEWAY_URL/query>
HEADERS
Content-Type: application/json Authorization': bearer <awtToken>
JSON-RPC Example
curl https://AVN_GATEWAY_URL/query \
-X POST \
-H "Content-Type: application/json" \
-H "Authorization: bearer <awtToken>" \
-d '{"jsonrpc":"2.0", "method":"getActiveEra", "params":{"accountId":"5DAgxV...DdMr", "fromTimestamp":"1672531200", "toTimestamp":"1685574000"}, "id":1}'
note
result - string integer value of the staking rewards earned over a specified period of time.
{
"jsonrpc": "2.0",
"id": 1,
"result": "13920000000000"
}