-
Hi there, I recently started using Viem and so far it has been great! Unfortunately I'm running into some problems trying to decode event logs. Currently, my code looks like this (I want to extract the uniqueId argument from the event): const unwatch = client.watchContractEvent({
address: config.DAO_CONTRACT_ADDRESS as any,
abi,
eventName: "PaymentProcessed",
onLogs: (logs) => {
for (const log of logs) {
const topics = decodeEventLog({
abi,
data: log.data,
topics: ... // ?
});
const uniqueId = ... // ?
}
},
}); As you can see, I'm not sure what I should put in the topics field. I tried using encodeEventTopics but I could not get the types to match. I could not find a complete example for decoding contract events. I'm not even sure if I'm doing this correctly. I would appreciate it if anyone could help me out :) |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 4 replies
-
following |
Beta Was this translation helpful? Give feedback.
-
The logs should already be decoded on |
Beta Was this translation helpful? Give feedback.
-
@jxom should this also work for watchEvent? and should it work when passing a string in to parseAbiItem to the event? (in this context I can't cast it as const) I can't seem to get it to parse the logs and provide the args variable in the logs for something like this, though it does correctly filter and pass onLogs the events: viemPublicClient.watchEvent({ On a probably-related note, I note that I can't filter on args from watchEvent in this pattern either. |
Beta Was this translation helpful? Give feedback.
It definitely does exist. Is your ABI cast to
as const
?Can you reproduce the type error in the TypeScript playground? https://www.typescriptlang.org/play
(Importing viem should automatically install it)