I can see how to do so from the subscan api but I am interested in understanding how to query this data from the chain itself. Ie via a storage function or by another means

1 Answer 1


Substrate exposes an RPC endpoint which provide the blockhash for any block: https://polkadot.js.org/docs/substrate/rpc#getblockhashblocknumber-blocknumber-blockhash


For example:

> curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "chain_getBlockHash"}' http://localhost:9933/


This information can also be found inside of the System Pallet in runtime storage:

/// Map of block numbers to block hashes.
#[pallet::getter(fn block_hash)]
pub type BlockHash<T: Config> =
    StorageMap<_, Twox64Concat, T::BlockNumber, T::Hash, ValueQuery>;

But note, this data is pruned, so only BlockHashCount number of items will exist at any time. To get all of the data in this way, you will need an archive node with the state of all the previous blocks.

So the RPC endpoint is probably your best bet!


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.