1

I assume that the address-balance mapping array in ERC20 is considered as a storage variable. So say if 1 million users start to use token A, then there would be 1 million entries in the balance array which is expensive to hold in the storage section. How can this be optimized to reduce gas costs?

2 Answers 2

2

Ethereum uses Merkle Patricia tree for storage, which provides logarithmic lookup time, therefore the cost of storing a large number of elements does not matter much. In any case, the gas costs of lookup (or other operations) will be paid for by the user who initiated the transaction, not the token contract owner.

0

Array's in solidity are initialized to the value 0 for all addresses when created. As long as you don't iterate through the whole array, you should be okay. Instead you should store the list of used addresses so that you can easily access all needed addresses at a later point ie: give refunds to everyone who donated to a contract

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.