Get logs after calling contract.write with viem #4573
Unanswered
pepoospina
asked this question in
Troubleshooting
Replies: 2 comments 1 reply
-
Maybe there is an automatic way to do this, but this way around should do it too import { artifacts } from 'hardhat';
import { decodeEventLog } from 'viem';
type EventType = Awaited<ReturnType<typeof decodeEventLog>>;
const getContractEventsFromReceipt = async (contractName: string, rec: TransactionReceipt): Promise<EventType[]> => {
const factoryArtifact = await artifacts.readArtifact(contractName);
if (!rec.logs) return [];
const events = rec.logs
.map((log) => {
try {
const event = decodeEventLog({
abi: factoryArtifact.abi,
data: log.data,
topics: log.topics,
strict: false,
});
return event;
} catch (e) {
return undefined;
}
})
.filter((e) => e !== undefined);
return events as unknown as EventType[];
}; |
Beta Was this translation helpful? Give feedback.
0 replies
-
Can't you use |
Beta Was this translation helpful? Give feedback.
1 reply
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.
-
I use
But the logs are not parsed as events. Is there a way to parse them? these are my contracts tests. I don't have access to abi (or I don't know how to access the abi, and hoped I should not need to do it since hardhat knows all about my contracts already)
Beta Was this translation helpful? Give feedback.
All reactions