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 Date Format
const FROM_TIMESTAMP = 1672531200; // 1st Jan 2023
const TO_TIMESTAMP = 1685574000; // 1st Jun 2023
- Example
- Example Result
- JSON-RPC
- JSON-RPC Output
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();
})();
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 { 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();
})();
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"
}