Skip to content

Instantly share code, notes, and snippets.

@miohtama
Created January 28, 2021 11:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miohtama/02a72595375b826c53debf4847aaae76 to your computer and use it in GitHub Desktop.
Save miohtama/02a72595375b826c53debf4847aaae76 to your computer and use it in GitHub Desktop.
How to get the total cost of approve() function calls on Ethereum blockchain
-- Web3.utils.keccak256("approve(address,uint256)").slice(0, 10);
-- '0x095ea7b3'
WITH txdata as (
SELECT tx.hash as txid, 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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment