Skip to content

Instantly share code, notes, and snippets.

@0xV4L3NT1N3
Created November 6, 2024 10:06
Show Gist options
  • Select an option

  • Save 0xV4L3NT1N3/e893dfff9c6e56947c684d5b59047791 to your computer and use it in GitHub Desktop.

Select an option

Save 0xV4L3NT1N3/e893dfff9c6e56947c684d5b59047791 to your computer and use it in GitHub Desktop.
Get Total USDC Transfers Last Hour Sample
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&timestamp=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