Clarity on extracting log event data from a transaction receipt? #3447
grapevinegizmos
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Having a lot of trouble figuring out the logic behind the structure of the TransactionReceipt return when you call a contract function using ethers.js.
In my case, I have a "factory contract" which creates a clone of another contract, and returns the resulting new contract address in an emitted event called "NewNFT":
event NewNFT(address newNFT, string name);
I need to be able to capture and return the address of the newly created contract so I am awaiting on the ContractReceipt returned when I call the
makeNFT
function, which turns out to be quite complicated.What I would like to understand is why there are actually 3 "log" objects returned in the Contract receipt, and why I can only seem to retrieve the emitted data from the 3rd of those log objects. (Also I see that there are 3 event object under the
events
key of the receipt, but don't see an obvious way to get at those values from ethers.js.). This is what I am using and it seems to work . . .But why it is in logs[2], not logs[0] (or logs[1]?***. And why do I need to look at the "logs" key of the receipt instead of the "events" key?
If I index any of the fields in the event, the format of the log seems to change completely. I can't really find a clear explanation of the how the transaction receipt is put together, I had to figure all of this out by trial and error and logging the results, but would like to understand more generally how these things work.
I frankly wish there was a "getEvent" function on TransactionReceipt so you could write something like
receipt.getEventValue("newNFT")
and get a value with out all the rigamarole, but perhaps in somel ater release. . .Beta Was this translation helpful? Give feedback.
All reactions