Search code examples
ethereumweb3js

Web3JS Ethereum Contract Storage History


I have the following question, lets say a transaction calls a Smart Contract's function, which changes the contract's state on Ethereum Mainnet. E.g. a counter variable was set from 0 to 1. Is there an easy way to access the previous state via Web3JS?

Thanks in advance!


Solution

  • Yes, as long as you know where in storage to look. The JSON-RPC method eth_getStorageAt lets you retrieve storage at a given location at an arbitrary block. web3.js exposes this as web3.eth.getStorageAt().