Replies: 4 comments 2 replies
-
I just remember with TypeChain we can also use |
Beta Was this translation helpful? Give feedback.
-
@farreldarian |
Beta Was this translation helpful? Give feedback.
-
UPDATE 10 months later10 months back we didn't have viem, but now the I think this discussion can be closed |
Beta Was this translation helpful? Give feedback.
-
I still needed this type helper so I did eventually find it. For those interested, Viem exports import { GetEventArgs } from "viem";
type EventArgs = GetEventArgs<
typeof abi,
"EventName",
{ IndexedOnly: false }
>; |
Beta Was this translation helpful? Give feedback.
-
Hi,
I have an idea on
ExtractEventArgs
utility types that might solves common problem on typing event.Motivation
Coming from wagmi and TypeChain, as far as I know there isn't any way to extract fully typed event(s) from logs inside transaction receipt, assuming the contract/ABI has already been known. There are actually two possible solutions for this,
The first solution might do the job, but we still need to hardcode the event name and manually cast to the desired event. Meanwhile the second solution which uses
AbiType
under the hood only facilitates "watching events" use-case, I still haven't found the AbiType's solution to type event from logs.Solution
Therefore, I'm experimenting on
ExtractEventArgs
utility type that is used to extractAbiEvent
's arguments by convertingAbiEvent.inputs
to a typed object. It also works alongside theExtractAbiEvent
.Here's an example that parses ERC20 events.
Screen.Recording.2023-01-04.at.17.06.42.mov
Here's an example to type ethers LogDescription.
Screen.Recording.2023-01-04.at.17.18.12.mov
From the example above, I still need to cast to
any
first since I just quickly use TypeChain's generated code. In future, this helper type could be integrated to any upcoming wagmi features that provide automatic type inference. Something likegetContractInferface(<abi>)
orpaseLogs(<abi>)
.It's also possible to improve the current
event
orargs
that's currently still uses array. However, this might have some reasons that I'm not aware of why wagmi chose to use array instead of object.Let me know what you guys think, happy to add a PR if this is useful.
Edited
Here's a better example on parsing log
Beta Was this translation helpful? Give feedback.
All reactions