Hi, I’m Dung Huynh Duc . Nice to meet you.

About Me

I’m a full stack developer. I’m a fast learner and self-taught coder. I often take my time for researching and learning about hot and trending technology.

tx receipt
abi decoder

#TIL 28 - Decode receipt logs with ethers

blog_hero_#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) =>
        topics: log.topics,
        data: log.data,
  logger.info('decodedLogs', JSON.stringify(decodedLogs, null, 2));
  return decodedLogs.filter(Boolean);