Blockchains are known to be immutable because all transactions of cryptocurrencies and state (data) changes. However, looking at ethscan does not provide any information on the output of a smart contract function that results in a state change. Is there a way to monitor the historic values of a state and if so how to do so?


There are two ways you could potentially track how a state vatiable has changed over time:

1- The contract has been developed so that when said variable is modified its previous state is added to an array which contains all previous states.

2- the contract has been developed so when the state variable is modified it fires an Event that logs said transaction. Here's more info about how to retrieve the logs. How can I view event logs for an ethereum contract?

Both depend on the developer of the contract caring for keeping track of previous values either by storing them or logging it.

| improve this answer | |
  • Thank you so much for your answer. However, it seems to me that the contract needs to be designed in a way to keep track of changes. Otherwise, there's no way for someone to, say, spoof my contract's state history that I don't have any logs for. Is that right? – thalsky Oct 27 '17 at 19:39
  • What I'm trying to say is that there's no way for someone (not even the developer/owner of the contract) to access the history of a state variable (what values it has had over time) if the developer of the contract didn't code for that (in the form of logs or some kind of internal logic). – pabloruiz55 Oct 27 '17 at 20:11
  • Does this make smart contracts "mutable" since there's no capability to verify the states? Also, given the method invocation history which includes input variables, I could potentially retrieve historical value of each transaction following the stack trace? – thalsky Oct 31 '17 at 19:57
  • Immutability of a smart contract refers to the fact that you can't modify the contract once deployed. If you didn't code functions that allow modifying a particular state variable, said variable will also become immutable. – pabloruiz55 Oct 31 '17 at 20:25

There's a third method. You can scan the chain looking for transactions on the contract and querying the state of that variable at each transaction of interest. I'm not saying it's easy--in fact, it's exceptionally difficult given the way the data is stored--but you could do it. I call this idea "off-chain monitoring" of smart contracts.

| improve this answer | |
  • Thank you so much for your answer. Does this "off-chain monitoring" method imply that in order to query a state's value after the 10th change transaction, you have to start from the first transaction on till you get to the 10th? In other words, you replay the methods that modified the state value? – thalsky Oct 27 '17 at 19:43
  • My understanding is that the state of the contract is something that happens after all transactions are executed and is stored in memory of nodes. – atok Feb 24 '18 at 12:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.