2

I am trying to get a descending list of biggest token holders like is displayed on etherscan. I could not locate an api to do this. I looked at EtherScan and EthPlorers api but did not see anything pertaining to this.

Does anyone know how i can do this in java?

  • I am working on a token explorer, currently I extract ERC20 tokens only. My project is extracting data at more deeper level than Etherscan, for example I am linking the event to internal transaction, this way you can separate transfer() and transferFrom() transactions while Etherscan can't do this. If you want , we can work together, its an open source project – Nulik Sep 03 '18 at 16:47
  • and btw, golang is cooler than Java for server programming, you should take a look at it, in the future it has all the chances to become the number #2 programming language after C/C++ – Nulik Sep 03 '18 at 16:50

3 Answers3

2

To get a descending list of all token holders you need to customize your own api by saving all token holders in an array and their respective tokens. Other than that you can use third party solution :-

https://etherscan.io/token/

Though you can find tokens at particular address by creating an api :-

const contractInstance = web3.eth.contract(abiData).at(contract_addr);
contractInstance.balanceOf.call(data.public_key, (err, result) => {

if (result) {            
next(null, result);        
}

else if (err && err.message)
{

next(err.message, null);      
}       
else {          
 next('Unable to sendRawTransaction', null);    
 }
Raghav Sood
  • 4,040
  • 2
  • 11
  • 20
Puneet Kumar
  • 611
  • 6
  • 24
0

This is code in java

OkHttpClient client = new OkHttpClient();

Request request = new Request.Builder() .url("https://api.chainbase.online/v1/token/top-holders?page=1&limit=20") .get() .addHeader("accept", "application/json") .build();

Response response = client.newCall(request).execute();

also node.js bwlow

const sdk = require('api')('@chainbase/v1.0#29qpir2wli0bsgcm');

sdk.getTopTokenHolders({page: '1', limit: '20'}) .then(({ data }) => console.log(data)) .catch(err => console.error(err));

https://docs.chainbase.com/reference/gettoptokenholders

Zhengxue
  • 26
  • 2
0

I do not have exact answer how to do it in Java, but I have close answer how to do it Python. You should be able to replicate this solution using web3j from Python web3.py logic.

ERC-20 tokens do not maintain an iterable list of current token holders, the used mapping type allows you only to check for a known address - balance. To get a list of all token holders, you need to process this offline and build it yourself from blockchain data.

I have created a standalone tool which collects ERC-20 token holders and transactions to SQLite database

  • Take a token contract address

  • Iterate over all Transfer events for token using eth_getLogs JSON-RPC API

  • Build a local database of these events

  • Allow you to use SQL to query any account balance on any point of time (block num)

The tool maintains a local SQLite database. The subsequent command runs scan the new blocks, since last run, and write the new transactions to the database. Exporting this from SQL based on a timestamp should be quite easy.

You can find the command line application execution example how to build the token holder database here

The core Python logic is here.

There are some quirks here and there: for example detecting mint / creation event for some tokens is not straightforward. Thus, you will may negative balance on the account receiving initial total supply if you rely on Transfer event only.

Mikko Ohtamaa
  • 22,269
  • 6
  • 62
  • 127