Add convenience method to TransactionReceipt for parsing events
See original GitHub issueAPI:
receipt.parseEvents(objectOrString) ⇒ Result<LogDescription>
Use:
const tokenAmount = ethers.utils.parseEther('10')
const wallet = new ethers.Contract(address , abi , signer)
const receipt = await (await wallet.deposit(tokenAmount)).wait()
const transferEvents = receipt.parseEvents('transfer(address to, uint amount)')
assert(tokenAmount.eq(transferEvents[0].amount))
This would allow for validating events are properly triggered on external contracts in 3 lines of code. (Or potentially a single line for the crazy people out there)
assert(tokenAmount.eq((await (await wallet.deposit(tokenAmount)).wait()).parseEvents('transfer(address to, uint amount)')[0].amount))
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:6 (1 by maintainers)
Top Results From Across the Web
ethers.js Add convenience method to TransactionReceipt for parsing ...
The method is already available on the contract.interface object (see decodingEventLog or parseLog), but the events will already have been decoded for you,...
Read more >Everything You Ever Wanted to Know About Events and Logs ...
There's a couple of ways we're going to answer that. ... Events give you a way to add relevant logging data to the...
Read more >Implement contract events (LOG) API · Issue #421 · ethereum ...
We are lacking of convenient LOG tracking API. It is currently implemented as JSON RPC filters, but we need to add this as...
Read more >How do I parse the transaction receipt log with web3.js?
I would like to parse the log section of the receipt but can't find a function in web3 to do so. Does it...
Read more >Documentation - Ethers.js
Most developers will find the parsing methods more convenient for decoding event data, as they will automatically detect the matching event.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Please note that
contractInterface.parseLog(log)
will throw if the event doesn’t not exist in thecontractInterface
. This is possible if contract makes a call to another contract (for e.g. ERC20 contract) that triggers an event from that contract.Not sure how I missed this issue before, but I’m trying to clean up the issues a bit and stumbled across it.
You can already accomplish this. The method is already available on the
contract.interface
object (see decodingEventLog or parseLog), but the events will already have been decoded for you, so you should be able to usereceipt.events.filter((e) => (e.name === "transfer"))
to pull all the transfer events out of a Contract’s TransactionReceipt.Does that work for you?