Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created September 10, 2023 07:03
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
JavaScript get etherscan logs by topic for contract address
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