I am using ganache and truffle for building DApp,

In my smart contract, I have declared one mapping variable, now in function I am assigning some value to that mapping variable. Every time I am assigning different values to that mapping variable.

Now, I want that what are the different values which has been assigned to that mapping variable till now means fetching the history of that mapping variable. So how to that, is there any way to fetch all the details of state variables (mapping in my case) ?

  • Contract needs it for something, or client needs it for something? Apr 17, 2018 at 0:23

1 Answer 1


Possible, but not seamless

The single best (and recommended) way of doing this is to emit an event that contains the information you are interested in, this event will then be iterable outside of the contract.

If you are not able to do this (for example you have already deployed and have live code), there's a (slightly harder) novel way of manually stepping through the blockchain and processing transactions to your contract here:

Iterating over all public values of a mapping in web3

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.