0

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) ?

Riya Soni
  • 99
  • 10

1 Answers1

2

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

jalooc
  • 105
  • 3
supakaity
  • 1,468
  • 7
  • 16