0

I want to provide a feature to download balances in open zeppelins StandardToken

    mapping(address => uint256) balances;

Probem is I get this error :

    Internal type is not allowed for public or external functions.

How can I do it ? I imagine it has to be done in phases, like one method for downloading all the addresses, and second method to retrieve the balance for one particular user. Which leads to another question - how to iterate through the mapping and just return array of address.

EDIT:

In my usecase, I have an ESO type option where the startup's employees are given away certain number of tokens for free. This happens by invoking some function marked as "onlyOwner", by the owner. This would not be reflected in the block logs, because there is no ether being transferred to the contract. In the other answer linked, it only deals with the case where the user sent ETH to a particular address.

MD Luffy
  • 111
  • 4
  • You can't iterate over a mapping, because keys are not stored. But you can use a library like this https://github.com/ethereum/dapp-bin/blob/master/library/iterable_mapping.sol that provides that features. – Ismael Oct 22 '17 at 23:36

1 Answers1

0

Its generally a bad idea to iterate through arrays to which the size we don't know. When working with small fixed size arrays, its not really much of a problem. However, iterating through an array of balances could be extremely computationally expensive for the Ethereum Virtual Machine. Each iteration would increase the gas cost. Imagine there are 100,000 addresses stored in the array of balances, this would most certainly exceed the gas limit which is approximately 4,700,000 gas.

Zenos Pavlakou
  • 443
  • 3
  • 9