What
Decode transaction receipt event logs using contract ABI with ethers.js.
Why
Logs are hex-encoded. Need ABI to parse them into readable event data.
How
import { ethers } from "ethers";
const iface = new ethers.utils.Interface(abi);
function decodeLogs(logs: Log[], contractAddress: string) {
return logs
.filter(
(log) => log.address.toLowerCase() === contractAddress.toLowerCase(),
)
.map((log) => iface.parseLog({ topics: log.topics, data: log.data }))
.filter(Boolean);
}