I have a mapping variable in my solidity code which maps address to name. I want to maintain the history/log of every change that happens in this mapping. What is the best possible solution to it?

2 Answers 2


Define a change event like

event MyMapChange(address _addr, string _newName);

and then, on each change, emit one like this:

emit MyMapChange(myAddr, myNewName);

Events get stored on the blockchain and can be queried, i.e. you can request request history, and also you can subscribe to new events, and even filter them by field values. To enable field filtering, you need to add indexed keyword to no more than 3 of the fields defined in your event, like this:

event MyMapChange(address indexed _addr, string _newName);

Check this related question and answers: How can I view event logs for an ethereum contract?

  • Although this is probably the most commonly used approach, there are some indications that events might be pruned, check this question ethereum.stackexchange.com/questions/6519/… Sep 24, 2018 at 21:00
  • @KwahuNashoba, Events are permanent, the logs are part of the tx receipts. Even in the link you provide is described that events are permanent.
    – Jaime
    Dec 16, 2018 at 10:28
  • Yes, I stand corrected! Dec 27, 2018 at 17:52

@Gagan, I think you need a combination of Mapping,Struct and Array. Please refer the below URL may be it is relevant to your problem:

Creating dynamic arrays

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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