Created
April 2, 2021 10:00
-
-
Save miohtama/3e618703fe55ec6699709571cec86790 to your computer and use it in GitHub Desktop.
Get all ERC-20() transactions using BigQuery public dataset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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