1

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)

1 Answer 1

3

With 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

7
  • I want to get nominator reward by nominator address not by block hash ? how to do?
    – Rose
    Commented Oct 6, 2022 at 15:22
  • If you don't know the blockHash you can query the events of all blocks and filter with the nominator address. See how to query all events: polkadot.js.org/docs/api/examples/promise/system-events
    – Alex Bean
    Commented Oct 6, 2022 at 15:57
  • Is there any way to get nominator reward from nominator address during selected era? I think browsing events is too time consuming.
    – Heindrick
    Commented Dec 15, 2022 at 16:58
  • Hello @AlexBean I can get stash account and reward amount from event. How can I get validator account address and era number? So, this reward is which era's reward and which validator rewarded.
    – Heindrick
    Commented Dec 23, 2022 at 4:36
  • Check this to get the era: polkadot.js.org/docs/api/start/api.query.other/…
    – Alex Bean
    Commented Dec 23, 2022 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.