ethers-io / ethers.js

Complete Ethereum library and wallet implementation in JavaScript.
https://ethers.org/
MIT License
7.87k stars 1.82k forks source link

parseLog not decoding event args with provided api #4797

Open viral-p opened 1 month ago

viral-p commented 1 month ago

Ethers Version

5.7.2

Search Terms

No response

Describe the Problem

with the provided ABI, parseLog output should include an args field that is an object containing the event args with named fields. Instead the output is an array, without names mapped to fields.

Code Snippet

const abi = [
  {
    anonymous: false,
    inputs: [
      {
        indexed: true,
        internalType: 'string',
        name: 'aggregatorId',
        type: 'string',
      },
      {
        indexed: true,
        internalType: 'address',
        name: 'sender',
        type: 'address',
      },
    ],
    name: 'Swap',
    type: 'event',
  },
];
const topics = [
  '0xbeee1e6e7fe307ddcf84b0a16137a4430ad5e2480fc4f4a8e250ab56ccd7630d',
  '0xa8dc30b66c6d4a8aac3d15925bfca09e42cac4a00c50f9949154b045088e2ac2',
  '0x000000000000000000000000df39cc227e0ab58f89d2b042a7b837a067945f3d',
];
const data = '0x';

const iface = new ethers.utils.Interface(abi);
const decodedLog = iface.parseLog({ topics, data });
console.log(decodedLog);

const logFragment = iface.getEvent(decodedLog.signature);
console.log(logFragment);

Contract ABI

[
  {
    anonymous: false,
    inputs: [
      {
        indexed: true,
        internalType: 'string',
        name: 'aggregatorId',
        type: 'string',
      },
      {
        indexed: true,
        internalType: 'address',
        name: 'sender',
        type: 'address',
      },
    ],
    name: 'Swap',
    type: 'event',
  },
]

Errors

No response

Environment

No response

Environment (Other)

No response

ricmoo commented 1 month ago

Have you tried console.log(logFragment.sender)? Keep in mind that the console.log cannot access dynamic values of a Proxy, but they are there. Its just a limitation of console.log and how Proxy objects work.

ricmoo commented 1 month ago

Oh sorry. Just noticed this is for v5. That did not use proxy, so they should be present. I will test this once I’m at a computer.

viral-p commented 1 month ago

looking at decodedLog.args expected output

 {
    aggregatorId: '0xa8dc30b66c6d4a8aac3d15925bfca09e42cac4a00c50f9949154b045088e2ac2',
sender:  '0xDF39cc227E0aB58f89d2B042A7B837a067945F3d'
  }

what I get

  [
  {
    _isIndexed: true,
    hash: '0xa8dc30b66c6d4a8aac3d15925bfca09e42cac4a00c50f9949154b045088e2ac2',
    constructor: [Function: Indexed] { isIndexed: [Function (anonymous)] }
  },
  '0xDF39cc227E0aB58f89d2B042A7B837a067945F3d'
]