0

I'm building a simple explorer and I would like to list events emitted by contracts. Since I can't know the ABI of each contract, is it possible to get past events from a contract using Web3?
If I knew the ABI, I would do something like this:

var myContract = new web3.eth.Contract(ABI, address);

myContract.getPastEvents('allEvents', {
    filter: {...},
    fromBlock: 0,
    toBlock: 'latest'
}, (error, events) => { console.log(events); })
.then((events) => {
    console.log(events) // same results as the optional callback above
});

But of course I can't instantiate a contract without its interface. I wonder how explorers such as Etherscan do this.

0

You can use 'web3.eth.getPastLogs({fromBlock: , address: }, (err, result))'

The result will contain Objects where the events are in the 'topics', but you can't decode the events without the ABI.

EDIT: topics is an array with the first element the event name and the following elements are the parameters

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.