-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I parse event logs? #487
Comments
The easiest way to do this, if you are not using the Contract API, is to use the Interface object API:
Which will output (given your logs):
Note the |
I think we are close. I now get the following output:
Note that this output is produced based on the changes that were made to create the following script:
What could I be doing wrong here? |
You forgot the ( |
Is there any good way to convert a This is my current attempt to fetch Events from the last
But at the end I'm getting a set of |
Oh, you'd like the I may only add it to the v5 branch though, which should be available for public beta later today. :) |
These have been added to v5. If you try it out, let me know how they work for you. Please feel free to re-open or continue discussion (I monitor closed issues) if you have any problems. Thanks! :) |
Oh, that’s just what |
In case anyone's looking for how to extract an event from a specific transaction, here's the code I managed to get working based on the suggestions on this thread. const receipt = await ethers.provider.getTransactionReceipt("0x0c8300a14a08fffe209dfe5961b3027b1321428184365751b89c4ac6056c28e4");
let abi = [ "event Donation(address donor, uint256 value, uint256 tokenID)" ];
let iface = new ethers.utils.Interface(abi);
let log = iface.parseLog(receipt.logs[1]); // here you can add your own logic to find the correct log
const {donor, value, tokenID} = log.args; |
Somehow, my results from parseLog was split in an args array without name, only numerical index and value, and in eventFragement.inputs with name, but without value. Context: This is with the Contract API, reading historical logs.
That I call like this
Hope this is useful for those who come from google :) |
@kimborgen That should not happen, the Result object from contract.queryFilter ( const filter = contract.filters.EventName()
const events = await contract.queryFilter(filter)
const {param1, param2} = events[0].args; |
If you're using the contracts API, you can also use the contract's interface itself.
|
I found this simple solution: const transaction = await contract.transfer(to, value);
const receipt = await transaction.wait(1);
let log = receipt?.logs.find((log) => credsLifeContract.interface.parseLog(log as any)?.name === 'Transfer') as EventLog;
console.log(log); |
=> In ethers version - 6.7.1 |
@kfazil The EventLog has an args property: https://docs.ethers.org/v6/api/contract/#EventLog |
I got the same problem with 'args' property which I'm trying to get:
error: code:
ethers@6.7.1 |
Yes, the type args doesn’t exist on It’s a Typing issue. You can use |
I have a smart contract that emits events whenever the following line of code in the contract is called:
emit Transfer(from, to, value);
The script that is used to list these events is shown below:
The output is the following:
What I am wondering is how do I decode the output of this script to get from, to, value from the event that was originally emitted?
The text was updated successfully, but these errors were encountered: