I have a smart contract deployed in which there is a variable A whose value is updated through a public function fun_update(). I want to get all the addresses which updated that variable A through the function fun_update().
How to do it without storing those addresses?


You can generate an event with the address and the recover the generated events.

event A_updated(address indexed updater);

function fun_update(uint newA) public {
    A = newA;
    emit A_updated(msg.sender);

  • I need to this for many functions like update, delete and others. And these functions will be called often. So is it good to do this for all? It will take a lot of space and gas to store them as logs of events. Isn't it? – krritik Sep 7 '20 at 13:40
  • @Ritikkumar It is not free, you have to pay something but it is cheaper than using storage. For example LOG4 opcode is 1875 gas. – Ismael Sep 7 '20 at 17:19
  • Ok Thanks I got it what you said. One last doubt if it's take less gas to store data in logs than in the storage. Still why storage is preferred to store most of the data in the blockchain? – krritik Sep 7 '20 at 17:57
  • @Ritikkumar There are several reasons: 1/ they cannot be accessed from a contract, 2/ they cannot be deleted and/or modified. Depending on the problem you may use one of them or both. – Ismael Sep 7 '20 at 18:23
  • 1
    Thanks for the insights. Sorry for the 2), I misunderstood something. Now it's clear. – krritik Sep 15 '20 at 13:29

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.