2

So I want to get the token holders of a token like this: https://ropsten.etherscan.io/token/0xfa68d281e7ff1a8e9393428ba0abe8961cf342cb#balances

Via my Ethereum node. I tried: https://github.com/ethereum/wiki/wiki/JavaScript-API#contract-events but it returns empty.

What method / function do I use to get all the token holders of a specific token?

3 Answers 3

3

In general you need support from the contract to be able to query for existing token holders.

If the token is ERC-20 compliant then you can retrieve all Transfer events generated by the contract. Then sender and recipient can be token holders, to ensure that you have to check if their balance is non zero.

If the token contract do not to generate events, then you have to trace every transfer and transferFrom to determine if the transfer was successful or not using debug.traceTransaction or similar.

2
  • can you advise how to retrieve all the Transfer events on a given block using json rpc? I imagine I have to use eth_getLogs but I dont know what the parameters would be. Thanks
    – Diego
    Mar 1, 2018 at 19:48
  • @Diego It is better if you create a new question.
    – Ismael
    Mar 2, 2018 at 5:12
2

Using QuickBlocks: https://www.youtube.com/watch?v=c_KNulh3PF4&t=2s to build a cap table of an ERC20 token.

1

I was looking through my old questions and figured I would answer. Note that this answer is mainly about ERC20 tokens.

Basically you have to get the contracts ABI and set it to the contract address like so:

var golemContract = eth.contract(erc20ABI).at(golemAddress);

Then you can interact like:

var golemBalance = golemContract.balanceOf('your_eth_address');

Here is a git repo with an example: https://github.com/bokkypoobah/TokenTrader/blob/master/scripts/getGNTBalances

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.