Created
November 6, 2024 10:06
-
-
Save 0xV4L3NT1N3/e893dfff9c6e56947c684d5b59047791 to your computer and use it in GitHub Desktop.
Get Total USDC Transfers Last Hour Sample
This file contains hidden or 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
| async function sumUSDCTransfers(chain, address) { | |
| // get the latest block | |
| const lastBlockQuery = await fetch(`https://api.etherscan.io/v2/api?chainid=${chain}&module=proxy&action=eth_blockNumber&apikey=YourApiKeyToken`) | |
| const lastBlockData = await lastBlockQuery.json() | |
| const lastBlock = Number(lastBlockData.result) | |
| // get the past hour block | |
| const hourlyBlockQuery = await fetch(`https://api.etherscan.io/v2/api?chainid=1&module=block&action=getblocknobytime×tamp=1730883600&closest=before&apikey=YourApiKeyToken`) | |
| const hourlyBlockData = await hourlyBlockQuery.json() | |
| const hourlyBlock = Number(hourlyBlockData.result) | |
| // query transactions within the last hour | |
| const query = await fetch(`https://api.etherscan.io/v2/api?chainid=${chain}&module=account&action=tokentx&contractaddress=${address}&page=1&offset=10000&startblock=${hourlyBlock}&endblock=${lastBlock}&sort=desc&apikey=YourApiKeyToken`) | |
| const data = await query.json() | |
| const transactions = data.result | |
| // sum them up | |
| let totalUSDCValue = 0 | |
| for (let i = 0; i < transactions.length; i++) { | |
| totalUSDCValue += Number(transactions[i].value) | |
| } | |
| console.log(`${totalUSDCValue / 1000000} USDC transferred on chain ${chain}`) | |
| } | |
| const chains = [ | |
| { id: 1, address: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" }, | |
| { id: 42161, address: "0xaf88d065e77c8cc2239327c5edb3a432268e5831" }, | |
| { id: 10, address: "0x0b2c639c533813f4aa9d7837caf62653d097ff85" }, | |
| { id: 8453, address: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913" }] | |
| for (const chain of chains) { | |
| sumUSDCTransfers(chain.id, chain.address) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment