7

I want a list of all ethereum address which have my ERC20 token in their account. Anyone have an idea how to get list address. beause i want give divided to each account which have my ERC20 token.

8
  • You can use the events to get the address list or use a new array for storing addresses in your contract. Commented Feb 22, 2018 at 6:06
  • From which event I get? Commented Feb 22, 2018 at 6:12
  • Do you have a Transfer event in your contract specifying fromAddress,toAddress,tokenCount params?Can you please paste the code? Commented Feb 22, 2018 at 6:15
  • yes i have Transfer and tokenCount Commented Feb 22, 2018 at 6:36
  • function transfer(address _to, uint256 _value) public returns (bool success) { validateTransfer(msg.sender, _to,_value); //assign total sale token count if(address(saleToken) == _to) { saleToken.setTotalToken(_value); } return super.transfer(_to, _value); } Commented Feb 22, 2018 at 6:37

1 Answer 1

5

Do it using your Transfer event in your contract.

    var myEvent = contract.Transfer({},{fromBlock: 0, toBlock: 'latest'});
    myEvent.get((error, result) => {
               console.log(result);
      });

use fromBlock param as 5933218 ,the block in which contract created

4
  • But issues my token contract and ico contract are two different contracts. so i am not getting Transfer event. do you have any idea about this how get all address? Commented Feb 23, 2018 at 4:54
  • @sagarjethi you have to get the instance of token contract in your js and do the above code to fetch the event log. Commented Feb 23, 2018 at 4:55
  • contractObj = new web3.eth.Contract(CONTRACT_ABI, contractAddress); contractObj.getPastEvents('Transfer' || 'allEvents', { fromBlock: 0, toBlock: 'latest' },function(err,res){ console.log(err,res); }); Commented Feb 24, 2018 at 6:25
  • contractObj.Transfer({},{ fromBlock: 0, toBlock: 'latest' },function(err,res){ console.log(err,res); }); Commented Feb 24, 2018 at 6:49

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.