4

Is there a way for me to get the total number of elements in a mapping in Solidity?

Ramon
  • 141
  • 1
  • 3

2 Answers2

5

You can't. There is no way to know how many entries there are in a mapping.

If you need to keep tract of the mapping's elements you can use a separate array which holds extra information about the mapping elements

Lauri Peltonen
  • 29,391
  • 3
  • 20
  • 57
0

You cannot do it as @Lauri mentioned. You can check how to do it manually in my answer here.