0

I want to get the value from the first indexed parameter of the TokensTransferred event from the transaction logs which can look like this. You can see that the TokensTransferred event has the first indexed parameter as bytes32[]. I want to get values from this array.

I tried out this solution but it gave the error that Interface is not a constructor. Does anyone know what I am doing wrong? How can I get the values from the bytes32[] that are emitted from the event in Ethers.js?

I am trying to get the array like this:

contract.on('TokensTransferred',(messageId)=>{
        console.log("Message Id: ",messageId);
        const iface = new ethers.utils.Interface(fromNetwork?.abi);

        console.log("Decoded Message Ids: ",iface.parseLog([messageId?.hash]));
  }

but still this is giving me this error:

TypeError: Cannot read properties of undefined (reading '0')
    at Interface.parseLog 

1 Answer 1

0

If you're seeing an error Interface is not constructor, it might be worthwhile to check for any typos or mistakes in the const iface = new ethers.Interface(abi); line of the solution (maybe 9th line).
Alternatively, the issue might be due to a change in the specifications of ethers.js because of version differences. Here, it appears to be structured under a hierarchy like this.
new ethers.utils.Interface(abi);

2
  • Now I am getting another error, I have added my code snippet with the error above. Nov 21, 2023 at 10:55
  • There seems to be an issue with the part iface.parseLog([messageId?.hash]). The argument for the parseLog() function should be log data, not an array. Similar to the original solution, the data needs to be obtained from transaction receipts or similar sources. For reference on what data to pass as an argument, you might find this document or this source helpful. Nov 21, 2023 at 12:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.