Using web3 I can query the balance of any fixed account with web3.eth.getBalance. Assuming I have the entire blockchain downloaded, how can I recover the list of all addresses that have a positive balance at this moment?
- 412
- 1
- 3
- 10
-
You want to check that for all address or just the addresses on your node? – Prashant Prabhakar Singh Oct 05 '17 at 14:21
-
@PrashantPrabhakarSingh I'd like all address that have a balance on the network I'm connected to (mainnet, testrpc, etc...). I think the solution involves iterating through all the blocks but I'm not sure if that's possible. – Hooked Oct 05 '17 at 19:58
-
This question may give you an idea https://ethereum.stackexchange.com/questions/8978/how-to-identify-accounts-addresses – Ismael Oct 08 '17 at 22:42
5 Answers
simple:
- get all the blocks
- from each block get all the transactions
- filter all the transactions with a
value > 0 - record the list of all the
toaddresses - filter out duplicates
filter out addresses with balance
0const Web3 = require('web3') const web3 = new Web3(new Web3.providers.HttpProvider('https://mainnet.infura.io/<InfuraToken>')) let blockNum = 0 let run = async () => { let addresses = {} while (true) { let blck = blockNum++ let block = await web3.eth.getBlock(blck) if (!block) break console.log('block', blck, 'transactions', block.transactions.length) for(let i = 0; i < block.transactions.length; i++) { let tx = await web3.eth.getTransaction(block.transactions[i]) if (parseInt(tx.value) > 0) { addresses[tx.to] = true } } } let 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) } run()
let this script run for a week or two and you'll have your result. The script requires the 1.0 version of web3 npm i web3 should do the trick. No other dependencies.
to run this simply use node scriptName.js
improvements may include finding out which addresses are contracts with eth.getCode. You could also write the result to disk instead of doing it all in memory.
- 2,203
- 21
- 36
-
2New addresses are created also when a message call is made inside some contract. To list these calls every transaction has to be executed or transaction traces must be inspected https://github.com/ethereum/go-ethereum/wiki/Management-APIs#debug_tracetransaction – medvedev1088 Feb 23 '18 at 19:51
You can get it from BigQuery https://medium.com/google-cloud/how-to-query-balances-for-all-ethereum-addresses-in-bigquery-fb594e4034a7
There are 3 ways by which an address can come into existence:
- a transaction is sent to this address
- a message call is made to this address within some contract
- a block mined where the address is specified as the coinbase (receiver of the block reward)
- a
SELFDESTRUCTis called with recipient being the address
To list all existing addresses you need to (in the corresponding order):
- list all transactions, get the destination addresses from these transactions
- execute all transactions, intercept all message calls, get the destination addresses from calls
- alternatively transaction traces can be inspected
- list all blocks, get the coinbase addresses from these blocks
Scanning the Patricia trie of an Ethereum client wouldn't work because the addresses are hashed before they are written to the trie: Getting complete state of a smart contract
- 10,996
- 5
- 35
- 63
-
1Related GitHub project: https://github.com/blockchain-etl/ethereum-etl-airflow – kenorb Jul 05 '20 at 13:31
You can find via github pymmdraza rich list, each file has more than 3gb of data.
- btc
- eth
- zec
- and some other coins
- 412
- 1
- 3
- 10
- 21
- 1
Run the following BigQuery:
with double_entry_book as (
-- debits
select to_address as address, value as value
from `bigquery-public-data.ethereum_blockchain.traces`
where to_address is not null
and status = 1
and (call_type not in ('delegatecall', 'callcode', 'staticcall') or call_type is null)
union all
-- credits
select from_address as address, -value as value
from `bigquery-public-data.ethereum_blockchain.traces`
where from_address is not null
and status = 1
and (call_type not in ('delegatecall', 'callcode', 'staticcall') or call_type is null)
union all
-- transaction fees debits
select miner as address, sum(cast(receipt_gas_used as numeric) * cast(gas_price as numeric)) as value
from `bigquery-public-data.ethereum_blockchain.transactions` as transactions
join `bigquery-public-data.ethereum_blockchain.blocks` as blocks on blocks.number = transactions.block_number
group by blocks.miner
union all
-- transaction fees credits
select from_address as address, -(cast(receipt_gas_used as numeric) * cast(gas_price as numeric)) as value
from `bigquery-public-data.ethereum_blockchain.transactions`
)
select address, sum(value) as balance
from double_entry_book
group by address
order by balance desc
limit 10 -- Remove this line for all balances.
to show top 10 ethereum addresses with a positive balance. You can run this at GCP BigQuery portal. Then export results into CSV file. Remove last limit line to find all addresses, however there are some export limits, E.g. you can export up to 16k rows to local CSV file, or up to 1G to Google Drive, or save all results as BigQuery table. Run it only few times, to avoid exceeding your free quota.
Source: https://github.com/blockchain-etl/ethereum-etl-airflow
- 1,171
- 1
- 12
- 28
You can pay a lot of money in Google cloud, or download it directly here -> https://blocklancer.net/job/476/1
Someone has made this for you. It takes a LOT of time to get the correct list of ETH addresses with full balance.
- 1
-
Top 10.000 ETH addresses ( all with balance over 750 ETH ) @ March 2020 : https://gourl.io/qyhwj – doremifasolasido Mar 17 '20 at 13:46