I would like to have the start of an era by eraIndex like:
const startingTime = getStartTimeOf( eraIndex );
Thank you.
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)