I'm writing a user interface in Javascript and I'm using the web3.js library.
I have the transaction hash of a confirmed transaction. I would like to get an array of all events emitted by that transaction.
I don't necessarily need all events, just the ones emitted by my smart contract by the execution of that transaction.
Can this be done using web3.js? What's a good way to accomplish this?
Best Answer
If you're using Web3 v1 then you can use
web3.eth.getTransactionReceipt(tx)
. It returnslogs
property as a part of a result.You can categorize events by looking at their
topics
property.Sample
getTransactionReceipt
result: