How to use api.events.staking.Rewarded.is to get reward?
Like this:
let event:IEventLike={
index:9281,
method:"staking",
section:"rewarded",
};
const nominatorReward = api.events.staking.Rewarded.is(event)
console.log(nominatorReward)
Substrate and Polkadot Stack Exchange is a question and answer site for developers building blockchains with the Substrate SDK. It only takes a minute to sign up.
Sign up to join this communityWith the block hash when the event was triggered and the index number of the event you can query all the events and parse it to find your specific event, and check the data in it.
See an example:
const blockHash = "0xaef9fe68122e5659638f426077e45dee30dc7d62f9627b3a0896fa3392ff263c";
const eventNumber = 547;
const at = await api.at(blockHash);
const events = await at.query.system.events();
console.log(events[eventNumber].event.data.toHuman());
The result of the console log is:
[ '15SpxEyZszSGKsYDqCSDgHr4CHUgx79qNwd4GW8T5AZQGCCc', '588,174,178' ]
Which is the stash account and the amount rewarded.
This code is to retrieve the information of an Event used as an example that you can find in here