How can I get events from a transaction receipt using Wagmi?

1.1k Views Asked by At

Ethers.js has ContractReceipt which extends TransactionReceipt that includes an array of events from the transaction: https://github.com/ethers-io/ethers.js/blob/master/packages/contracts/src.ts/index.ts#L99

Is it possible to get this array using Wagmi? The docs say that wagmi now returns the Viem TransactionReceipt instead of Ethers, and it doesn't look like it has ContractReceipt: https://github.com/wagmi-dev/viem/blob/136c4022c3ab4020f37333876bed788a111bff47/src/types/transaction.ts#L12

1

There are 1 best solutions below

0
On

I figured it out:

You need to parse the logs yourself from the Wagmi/Viem transaction receipt. I modified the answer in this post: https://github.com/ethers-io/ethers.js/issues/487

const iface = new ethers.utils.Interface(deployment.abi);
const parsed = iface.parseLog(testReceiptData.logs[0]);
console.log('parsed', parsed);

The events will be present in logged under args.