0

I am going to get all ehtereum wallet addresses with positive balance. I tried to get addresses with a method to get transaction. I have got transaction from blocknumber(0~ Inf). Using web3 and following code:

block_number = 0
while True:
    tx = web3.eth.getTransaction(block_number)
    if not tx:
        break
    ...
    block_number += 1

But above running time is too slow. If anyone know how to get all addresses by another way, please help me.

0

You could potentially query the blocks locally that would save you a significant amount of time assuming you have a full node.

| improve this answer | |
  • Thanks. But your answer doesn't help me. I am going to all addresses of the ehtereum net. And I must know their balance. – Coder HHC Jul 5 '18 at 13:41
0

You are essentially trying to build a core component of a block explorer. Some related questions might be useful as background, like: How do block explorers actually work?

Note that even this brute-force approach of iterating all transaction recipients does not produce all account addresses, because of "internal transactions." See: How to get contract internal transactions

Even the subset of accounts you get by this iteration approach will be a very slow process. There's a lot of data to crunch through. But you can speed it up a bit by getting all the transactions in a block at once with:

block = w3.eth.getBlock(block_number, full_transactions=True)
for txn in block.transactions:
   # add txn.to to the set of recipients

API docs

That will at least save you a bunch of round-trip calls to your node, because you only have to call your node once per block rather than once per transaction.

| improve this answer | |
0

This task is not solvable with pure Web3 API. You may obtain balance of a particular address, but you cannot effectively iterate over all the addresses with (potentially) non-zero balances. Iterating through all the transactions and checking their "to" addresses will not do what you want, as an address may obtain ether in different ways, and not all these ways require the address to appear in "to" field of some transaction.

For example, there are 8893 addresses that obtained ether in Genesis block. Also, ether may be sent to an address by a smart contract.

In order to obtain list of all addresses having non-zero balances, you may use Google BigQuery like this:

SELECT `address`, `eth_balance`
FROM `bigquery-public-data.crypto_ethereum.balances`
WHERE `eth_balance` != 0
# ORDER BY `eth_balance` DESC
# LIMIT 10
| improve this answer | |

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.