Watch for Contract Events
const Web3Data = require("
[email protected]")
// Create the Web3Data instances passing in your API Key (Get one! -> amberdata.io/onboarding)
const w3d = new Web3Data('UAK6c0e7804a7b03c53b1312d579517ec05')
const contractAddress = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48" // <- USDC
// Init websocket connection
w3d.connect()
// Start listening for address logs
w3d.on({eventName:'address:logs', filters: {"address": contractAddress} },
async data => {
// Get the human readable text signature of the event (use slice to get the first 4 bytes of the sig)
const sig = await w3d.signature.getSignature(data.topics[0].slice(0, 10))
// Construct a nice logging message to signal a new event
const eventMessage =
`event ${sig[0].textSignature} at ${new Date(data.timestamp).toLocaleString()} in block ${data.blockNumber}`
// Log to console
console.log(sig && sig.length > 0 ? eventMessage : `sig ${sig} not found`)
})
no comments