4

I would like to have the start of an era by eraIndex like:

const startingTime = getStartTimeOf( eraIndex );

Thank you.

1 Answer 1

7

The important point about the chain state is that it only contains information that is needed for future block execution. It is not a generalized database. Staking is a very good example - since we only do payouts for 84 eras (Kusama/Polkadot/other chains may be different) the on-chain state therefore contains the information for the last 84 eras. (Since they need to slash, make payouts, etc.)

The circle back to your question - since the timestamp for the start of a specific era is not needed for future block execution (the runtime only needs information to make future payouts/slashes and information about the current and next era to progress), there is no state entry that you can query at any time that goes from index -> time. This is basically information derived from the past state, i.e. the block where the index changed.

This is where block explorers and indexers come in handy. In their case they can follow the chain events and when receiving the session.NewSession event can check for a new era and if found, can get the timestamp of that block. (Or from activeEra)

The short version: the on-chain state has a lot of information pertinent to processing, but it generally maps back to a hash, i.e. a block at a specific point in the chain. Derived information such as timestamps and changes over time need to be extracted via indexing and storing it into a generalized database.

I'm not too familiar with the APIs that some block explorers expose, but they may have something like this indexed and query-able (I would guess that this may be there if it has been a request in the past)

1
  • Thank you, very useful as always, I really appreciate your time. In fact I want to demonstrate an account's received rewards during a period of time. I can fetch timestamped data from subscan but its almost 10 eras back. However, with on chain data utilizing stakerRewards api, we have update info but no timestamps! I think I should finally merge the two results and do some programing tricks to calculate missing timeStamps.
    – Kami
    Commented Mar 27, 2022 at 19:22

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.