#TIL 28 - Decode receipt logs with ethers
import { ethers } from 'ethers';
// create an interface with your abi
const iface = ACX__factory.createInterface(abi);
function decodeLogsByEsther(
logs: Log[],
contractAddress: string,
): Array<ethers.utils.LogDescription & { values?: any }> {
logger.info('decodeLogsByEsther', logs);
const decodedLogs = logs
.filter((log) => log.address.toLowerCase() === contractAddress.toLowerCase()) // only check log if from same smart contract address
.map((log) =>
iface.parseLog({
topics: log.topics,
data: log.data,
}),
);
logger.info('decodedLogs', JSON.stringify(decodedLogs, null, 2));
return decodedLogs.filter(Boolean);
}