Skip to main content
Version: 2.4

Get Staker Rewards Earned

This can be used in two ways:

  1. Query the amount of staking rewards earned over all time. This takes in as input the address or public key of the account.
  2. 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

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();
})();

Get Staker Rewards Within A Specific Window

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();
})();