'How to access the data from the previous block of Ethereum block chain through the block number?

I am new to block chain. Suddenly I got a question did we can able to access the previous block data from the Ethereum block chain by block number.

For example I have created a block1, block2.

block1 has data 'apple' after that I have changed the data to 'banana' so new block is created block 2. I know if we call the get data function then it going to give output banana but in case I want to access the data from the block1 through the block number as 1 how to access it?

There is any way to access the data from previous block it there please help my question to solve.

Thanks.



Solution 1:[1]

You can access previous state at a specific block using offchain tools. For example the web3js method call() (docs) allows you to specify a block number that you want to query.

However, onchain contracts do not have access to previous blocks.

Solution 2:[2]

The Graph Protocol can help index historical information if you need to access to it laster.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Petr Hejda
Solution 2 kraphty23