Skip to main content
Version: 4.0.0

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

Example Date Format

const FROM_TIMESTAMP = 1672531200; // 1st Jan 2023
const TO_TIMESTAMP = 1685574000; // 1st Jun 2023
const { AvnApi, SetupMode, SigningMode } = require("avn-api");
const AVN_GATEWAY_URL = "https://gateway.testnet.aventus.network";

const singleUserOptions = {
suri: "0x5392ca60a61aea99fce14358798de93c1bc11c3696a905718738c71fae539c24", // this is from the generated example account
setupMode: SetupMode.SingleUser,
signingMode: SigningMode.SuriBased,
};

const avnSdk = new AvnApi(AVN_GATEWAY_URL, singleUserOptions);

async function main() {
await avnSdk.init();
const api = await avnSdk.apis();

let result = await api.query.getStakerRewardsEarned(
"replace with user's address"
);
console.log(result);
}

(async () => {
await main();
})();

Get Staker Rewards Within A Specific Window

const { AvnApi, SetupMode, SigningMode, NonceCacheType } = require("avn-api");
const AVN_GATEWAY_URL = "https://gateway.testnet.aventus.network";

const singleUserOptions = {
suri: "0x5392ca60a61aea99fce14358798de93c1bc11c3696a905718738c71fae539c24", // this is from the generated example account
setupMode: SetupMode.SingleUser,
signingMode: SigningMode.SuriBased,
};

const avnSdk = new AvnApi(AVN_GATEWAY_URL, singleUserOptions);

async function main() {
await avnSdk.init();
const api = await avnSdk.apis();

const FROM_TIMESTAMP = 1672531200; // 1st Jan 2023
const TO_TIMESTAMP = 1685574000; // 1st Jun 2023

let result = await api.query.getStakerRewardsEarned(
"replace with user's public key",
FROM_TIMESTAMP,
TO_TIMESTAMP
);
console.log(result);
}

(async () => {
await main();
})();