3

I would like to determine the number of blocks produced in a given era index.

In polkadot.app there is a query to get reward points in an era:

Staking Query: erasRewardsPoints(EraIndex).

How can I determine the number of blocks produced in one specific Era? Is there any query for that? If not, if I traverse the blocks, is the Era index included in the block data? I can not find it.

Thanks very much.

enter image description here

1 Answer 1

4

If not, if I traverse the blocks, is the Era index included in the block data?

Right, the era is not in the block data itself, so you'd have to fetch each block. At the end of each era, end_era gets called and emits an EraPaid event. You can use this as the boundary between eras, and if you check the block height of the event for era N against N - 1 then you get the number of blocks in era N.

6
  • Hi @joepetrowski. How can I check the block height of the era N?
    – Heindrick
    Commented Dec 19, 2022 at 9:11
  • An era will map to a range of blocks. For past blocks/eras, you will need to index the EraPaid events and block height at which each is emitted. For future eras, the best you can do is predict a maximum block number for the start of a future era. Since block production slots may be skipped, the actual block number when that future era starts could be lower. Commented Dec 19, 2022 at 12:35
  • How can I index EraPaid events for past eras? Actually, I am going to index events for selected past era, so I need to know start, end block number of selected era. Could you explain in detail?
    – Heindrick
    Commented Dec 19, 2022 at 17:26
  • Any idea @joepetrowski?
    – Heindrick
    Commented Dec 20, 2022 at 1:41
  • Fetch every block and store the events in your own database. Commented Dec 20, 2022 at 11: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.