0

Is there a way to find/export all addresses with a balance above a certain number in Ether?

Any service/API provider is available for above requirement?

  • Ethereum means ICO tokens also? Or only ether? – Jitendra Kumar. Balla Feb 13 '18 at 3:58
  • For the moment Only ether. – Sandesh Sidana Feb 13 '18 at 4:02
  • Updated my ans with explanation. mark is accepted if its resolved your qus. – Jitendra Kumar. Balla Feb 13 '18 at 4:24
0

Yes you can. I am attaching below code for doing the same:

web3.eth.getAccounts(function(error, accounts){
if(error){
    console.log("error")
    return;
 }
  console.log(accounts);
  for(var index=0;index<accounts.length;index++){
       getBalance(accounts[index]);
  }
});

function getBalance(var account){
    var balance = web3.eth.getBalance(account); 
    balance = web3.toDecimal(balance);
    if(balance > web3.toWei(1,'ether')){
         console.log("Address"+ account + " and balance is " +web3.toWei(balance,'ether'));
    }
}

Explanation for above code:

web3.eth.getAccounts is a asyc method, using this method you can get all the accounts in connected ether network based on your Web3.providers.HttpProvider. You can also call web3.eth.accounts, but I'll not recommend.

web3.eth.getBalance(account); method will returns balance. Do check currently I am checking 1 ether, you can replace value as per your requirement.

Updated:

Web3.providers.HttpProvider is for connecting any eth node that might be local or test or main net.

You can connect to ether main net using HTTPProvider by following 2 ways:

  1. 3rd party providers like infura.io provides services for connecting to Eth mainnet, Ropsten, Rinkeby. Refer below link for more details https://blog.infura.io/getting-started-with-infura-28e41844cc89
  2. Run your node, I know this is cost effective but you will get trusted verified network data.
  • Using web3.eth.getAccounts method, you can only get those accounts which are associated to your Web3.providers.HttpProvider. I want to retrieve all accounts which are created on block-chain by anyone. Similar to this - etherscan.io/accounts – Sandesh Sidana Feb 13 '18 at 4:44
  • @Sandesh updated my ans – Jitendra Kumar. Balla Feb 13 '18 at 5:17
  • Through web3.getAccounts method you can only get those accounts which are running on your node. I need to fetch all addresses on network. – Sandesh Sidana Feb 13 '18 at 6:24
  • Iterating over all non-zero-balance addresses via RPC/web3 would take (almost literally) forever - it's just too slow. It would take even longer using Infura because of their rate limiting. You'd need to read the state data directly (by parsing the .ldb database files), and to do that quickly and efficiently you'd need to run a full node. I don't think there's a simple way to do what you're asking. – Richard Horrocks Feb 13 '18 at 9:00
0

I figured out a way to achieve the above. Although it is very time talking but still useful. We need to crawl over all blocks starting from 0 to the latest block number and from each block get the transactions details and record the addresses.

Following is the script:
   var blockNum = 0;
     Loop---(While/for) run until latest block get fetched
     var block = blockNum++;
     var block = await web3.eth.getBlock(block);
     if (!block)
          break;
     console.log('block', block, 'transactions', block.transactions.length);
     for(var i = 0; i < block.transactions.length; i++) {
               var tx = await web3.eth.getTransaction(block.transactions[i]);
               if (parseInt(tx.value) > 0) {
               addresses[tx.to] = true;
               }
          }

     var positiveAddresses = [];
     for (address in addresses) {
          try {
               let balance = await web3.eth.getBalance(address);
               if (balance > 0) {
               positiveAddresses.push(address);
               }
          } catch (err) {
          console.log(err);
           }
           }
          console.log(positiveAddresses);
          }


The above will print all the address having balance greater than zero.

  • That's going to take a very long time... You're checking every transaction ever made (over RPC). Also, it's going to give you an array containing lots of duplicate addresses. In the time it takes to run that command you could become an expert in how the state tries are laid out, and learn how to parse them in a fraction of the time :-) – Richard Horrocks Feb 13 '18 at 10:01
  • I Know. Even I don't want to iterate over each transaction ever made on block chain. If you know better technique than this then please elaborate. – Sandesh Sidana Feb 13 '18 at 10:52
0

TrueBlocks (disclosure my project) does exactly this. It scrapes every single piece of data and builds a non-duplicative IPFS-sharable index of every address appearance anywhere on the Ethereum chain. From there one could extract all addresses and from there balances. It takes two days to run against a local fully synced tracing or archive node. It’s really not feasible against Infura because Infura is astonishingly slow compared to a local node.

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.