I am writing a ICO code which should have the following functionalities

  1. To save the address of every investor and
  2. To retrieve all the investors address and the amount invested


  1. What is the best way to do it ? Any code snippet will be a great help.

  2. Lets assume there are 30000 investors.

    2.a Is it possible to save those in the state variable ?

    2.b Is it possible to get all the 30000 investor address and their amount using any online tool like MEW / Etherscan.io (Read contract) ?


Functionally, this is rather trivial to implement. Something like this:

contract Test {

   address[] investors;
   mapping(address => uint256) private balances;

   function saveAddress() payable public {
       balances[msg.sender] = msg.value;

Here msg.sender refers to the one who is sending the contract Ether and msg.value is the amount of Ether sent. Note that your function has to be payable to be able to receive Ethers.

If you don't need to be able to retrieve the list of investors, you can even drop the investors variable - balances mapping will contain investment information per investor, but you can't get a list of investors from it.

For reading you don't need any code in your contract - all data in smart contracts is directly readable even without any explicit code. You can use any web3 library for it.

Saving 30000 addresses with their balances will cost some gas. But if the data is stored whenever someone invests in the ICO, the gas cost is payed by the investor so you don't really need to worry about that.

And yes, you can use also any online tool like MEW/Etherscan to read the data.

  • While retreving from MEW / Etherscan.. will it return all the 30000 address..
    – iappmaker
    Dec 19 '18 at 7:33
  • Will there be any be I while retreving such huge data online
    – iappmaker
    Dec 19 '18 at 7:35
  • I guess retrieval will give you all the data at once, but not 100% sure about this - will depend also on which service you use. Read documentation of the respective services to find out how they actually provide the data. Dec 19 '18 at 7:37
  • Sorry to add it now.. I need both address and their amount
    – iappmaker
    Dec 19 '18 at 7:40
  • Modified answer to suit your needs. Dec 19 '18 at 7:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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