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?
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?
@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: