1
votes

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!

2

2 Answers

1
votes

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().

0
votes

yeah you can use events in smart contracts functions to save every interaction with the smart contract then use web3 and get all the events that happened on the smart contract like that you get all the records of the previous state .