Skip to content

Instantly share code, notes, and snippets.

@rvrsh3ll
Created February 18, 2021 18:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rvrsh3ll/b4ee1bbd3da46bce1a6bbbac1b8ebc03 to your computer and use it in GitHub Desktop.
Save rvrsh3ll/b4ee1bbd3da46bce1a6bbbac1b8ebc03 to your computer and use it in GitHub Desktop.
Google BigQuery Ethereum Addresses
#standardSQL
with double_entry_book as (
-- debits
select to_address as address, value as value
from `bigquery-public-data.crypto_ethereum.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.crypto_ethereum.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.crypto_ethereum.transactions` as transactions
join `bigquery-public-data.crypto_ethereum.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.crypto_ethereum.transactions`
)
select address, sum(value) as balance
from double_entry_book
where value > 1 AND value < 5000
group by address
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment