Given I want to return a mapping from a function, which is impossible, therefore I return each of the mapping's item in a function by a corresponding ID, like this answer suggests : How to return a mapping type?

Given I want to iterate over all existing IDs in a mapping in order to retrieve all user assets, how long does it take to call a single iteration ?

  • You cannot iterate over a mapping in solidity, unless you hold the key types in a collection such as an array and access their corresponding value in the mapping one-by-one. Commented Jan 12, 2018 at 11:51
  • @HarryWright This is exactly what I asked, one-by-one, I know my IDs will be, say, 1-10, because say I want to delete from my mapping, I need to delete from the array, and that is inefficient.
    – Random
    Commented Jan 12, 2018 at 11:52
  • As a followup of my previous question ethereum.stackexchange.com/questions/35790/…
    – Random
    Commented Jan 12, 2018 at 11:58


Your Answer

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

Browse other questions tagged or ask your own question.