Created
September 10, 2023 07:03
-
-
Save miguelmota/2563482195c4b777c4d77af392a56614 to your computer and use it in GitHub Desktop.
JavaScript get etherscan logs by topic for contract address
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
async function getEtherscanLogs (chain: string, fromBlock: number, toBlock: number, address: string, topic0: string, topic1?: string) { | |
const baseUrl = 'https://api-goerli.etherscan.io' | |
let url = `${baseUrl}/api?module=logs&action=getLogs&address=${address}&fromBlock=${fromBlock}&toBlock=${toBlock}&topic0=${topic0}&page=1&offset=0&apikey=YourApiKeyToken` | |
if (topic1) { | |
url += `&topic0_1_opr=and&topic1=${topic1}` | |
} | |
const res = await fetch(url) | |
const json = await res.json() | |
const logs = json.result | |
return logs | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment