Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parseLog not decoding event args with provided api #4797

Open
viral-p opened this issue Aug 1, 2024 · 4 comments
Open

parseLog not decoding event args with provided api #4797

viral-p opened this issue Aug 1, 2024 · 4 comments
Assignees
Labels
investigate Under investigation and may be a bug. v5 Issues regarding legacy-v5

Comments

@viral-p
Copy link

viral-p commented Aug 1, 2024

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

@viral-p viral-p added investigate Under investigation and may be a bug. v5 Issues regarding legacy-v5 labels Aug 1, 2024
@ricmoo
Copy link
Member

ricmoo commented Aug 1, 2024

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
Copy link
Member

ricmoo commented Aug 1, 2024

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
Copy link
Author

viral-p commented Aug 2, 2024

looking at decodedLog.args
expected output

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

what I get

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

@maharshi365
Copy link

maharshi365 commented Oct 29, 2024

@ricmoo any updates on this issue? Found another example, Here is a minimal example

const abi = [
  {
    anonymous: false,
    inputs: [
      { indexed: true, internalType: 'string', name: 'hnId', type: 'string' },
      {
        indexed: true,
        internalType: 'address',
        name: 'wallet',
        type: 'address',
      },
    ],
    name: 'Mint',
    type: 'event',
  },
];

const topics = [
  '0x79b04a02d84fec4f53dec01c843dee92deee8a6d7dc31a65ae8c2c6b60200cf3',
  '0xfe9d5cae98771f5bbfd6b1674d82b20eb8b7fae8f2d30b5bfadeac20a861c545',
  '0x0000000000000000000000005c3d815a01e299a8475a9dcade5f75d96bdd07f5',
];

const data = '0x';

const iface = new ethers.utils.Interface(abi);

const parsed = iface.parseLog({ topics, data });

console.log('parsed', parsed);

The named parameters are present in the result of this.decodeEventLog(fragment, log.data, log.topics) but when the LogDescription object is created, the named parameters disappear. I think its somewhere in deep copy but cant localize

Interesting thing is that if i use the decodeEventLog function, the parameters are present

Using decodeEventLog

 [
  Indexed {
    _isIndexed: true,
    hash: '0xfe9d5cae98771f5bbfd6b1674d82b20eb8b7fae8f2d30b5bfadeac20a861c545'
  },
  '0x5c3d815a01E299A8475A9dcAde5f75d96BDd07F5',
  hnId: Indexed {
    _isIndexed: true,
    hash: '0xfe9d5cae98771f5bbfd6b1674d82b20eb8b7fae8f2d30b5bfadeac20a861c545'
  },
  wallet: '0x5c3d815a01E299A8475A9dcAde5f75d96BDd07F5'
]
}

Using parseLog

LogDescription {
  eventFragment: {
    name: 'Mint',
    anonymous: false,
    inputs: [ [ParamType], [ParamType] ],
    type: 'event',
    _isFragment: true,
    constructor: [Function: EventFragment] {
      from: [Function (anonymous)],
      fromObject: [Function (anonymous)],
      fromString: [Function (anonymous)],
      isEventFragment: [Function (anonymous)]
    },
    format: [Function (anonymous)]
  },
  name: 'Mint',
  signature: 'Mint(string,address)',
  topic: '0x79b04a02d84fec4f53dec01c843dee92deee8a6d7dc31a65ae8c2c6b60200cf3',
  args: [
    {
      _isIndexed: true,
      hash: '0xfe9d5cae98771f5bbfd6b1674d82b20eb8b7fae8f2d30b5bfadeac20a861c545',
      constructor: [Function]
    },
    '0x5c3d815a01E299A8475A9dcAde5f75d96BDd07F5'
  ]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
investigate Under investigation and may be a bug. v5 Issues regarding legacy-v5
Projects
None yet
Development

No branches or pull requests

3 participants