When using a storage variable, a Solidity smart contract can access only its latest value. The updates of this variable throughout the blockchain are hidden and only the up-to-date state is accessible.

However, is it possible to know (in solidity) the block a variable was last updated at?

For example:

// Instance variable
uint v;

In a transaction in block 1000:

v = 0x1234;

In a transaction in block 1200:

v = 0xabcd;


uint a = v; // a == 0xabcd
// Imaginary function, it does not exist
getLastUpdateBlock(v).number; // 1200

Note: despite of its name, Get latest update time-stamp of contract variable actually refers to all transactions that refer to a variable. Maintaining all these changes would be costly, thus the answer ("not possible") is not surprising. However, keeping only the block of the last update would "just" roughly double the memory usage (var alone becomes var + block hash). So I think asking this specific question is worth a try.

  • 1
    There's no built-in support for this, but you could of course keep track of this yourself in the contract. – user19510 Mar 13 '18 at 7:41
  • In ethereum.stackexchange.com/questions/23356/…, it is said that the history of a variable is not accessible, which makes sense. However, the question here is only about the last update. So even if I suspect the answer to be "this is not possible", I think it would be good to have this stated once for all as a googlizable piece of information :) – philippe_b Mar 13 '18 at 7:41
  • @smarx Thank you. In addition to the unavailability of such helper, I guess the block info is not part of the pruned state? – philippe_b Mar 13 '18 at 7:44
  • @Ismael I explicitly mentioned this Q/A in a previous comment. I don't consider this one as a duplicate because it only refers to the latest modification, a piece of information that might be available at relatively lost cost (compared to keeping the whole history and making it accessible). – philippe_b Mar 14 '18 at 6:37
  • @Ismael I didn't realize the question was marked as duplicate, so I added a note. – philippe_b Mar 14 '18 at 6:43

Browse other questions tagged or ask your own question.