Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save miohtama/3e618703fe55ec6699709571cec86790 to your computer and use it in GitHub Desktop.
Save miohtama/3e618703fe55ec6699709571cec86790 to your computer and use it in GitHub Desktop.
Get all ERC-20() transactions using BigQuery public dataset
-- Get all approve() transaction
-- Web3.utils.keccak256("approve(address,uint256)").slice(0, 10);
-- '0x095ea7b3'
WITH txdata as (
SELECT tx.hash as txid, tx.block_timestamp as block_timestamp, cast(tx.receipt_gas_used as numeric) * cast(tx.gas_price as numeric) as cost FROM
bigquery-public-data.crypto_ethereum.transactions as tx
where
tx.input
LIKE "0x095ea7b3%")
SELECT (SUM(cost) / POWER(10, 18)) as eth_cost from txdata;
-- Verify Google data is good.
-- Get the last approve() transaction in Google dataset.
-- Check txid on Etherscan and should be around 5 minutes ago.
WITH txdata as (
SELECT tx.hash as txid, tx.block_timestamp as block_timestamp, cast(tx.receipt_gas_used as numeric) * cast(tx.gas_price as numeric) as cost FROM
bigquery-public-data.crypto_ethereum.transactions as tx
where
tx.input
LIKE "0x095ea7b3%")
SELECT txid as last_txid FROM txdata ORDER BY block_timestamp DESC LIMIT 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment