Suppose, your contract has something like

if (_balances[account] >= someNumber) {
    _balances[account] = _balances[account] - _balances[account]/10;

What is the gas cost of this operation? I guess, if the mapping _balances has a lot of entries, let's say millions of entries, then a search in such mappings could cost a lot of gas. Is it possible to estimate how much gas the above code consumes given the length of _balances? (Note that I'm not interested in the actual $ cost, but the amount of gas units regardless of gas price)

  • What type is _balances?
    – Ismael
    Feb 26, 2023 at 1:42

1 Answer 1


Check out the gas cost bellow. It should be the same regardless of how many users they are there. Mapping works a bit differently then list and it doesn't iterate through the multiple number of data like you would have to in case if a list. There is a reason why mappping data is not iterable.

enter image description here

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.