question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add convenience method to TransactionReceipt for parsing events

See original GitHub issue

API:

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:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
zemsecommented, Sep 21, 2020

Please note that contractInterface.parseLog(log) will throw if the event doesn’t not exist in the contractInterface. This is possible if contract makes a call to another contract (for e.g. ERC20 contract) that triggers an event from that contract.

1reaction
ricmoocommented, Apr 21, 2021

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 use receipt.events.filter((e) => (e.name === "transfer")) to pull all the transfer events out of a Contract’s TransactionReceipt.

Does that work for you?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found