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

ethers-v6: event listener signatures don't match actual runtime types #906

Closed
markszente opened this issue Dec 6, 2024 · 1 comment
Closed

Comments

@markszente
Copy link

Possibly related: #867

Let's say we have a contract that emits the following event:

event ChatSessionCreated(bytes32 indexed chatHash, address indexed creator);

When trying to listen for this event, we can either do contract.addListener("ChatSessionCreated", (...args) => console.log(args)) without any filtering or typed listener signature. As expected, args would be an array of three elements, eg:

[
    "0xa60e5807d70cd5626a8610b0383bc50a61b47ec59709cd05af02aad20a2a52f8",
    "0x1f1672F6e282032777AB6Cb4719423cBdA0AE1AB",
    { /* object removed for brevity  */ }
]

If I add two event listeners, like below, it also works, printing the same array twice:

const filter = contract.filters.ChatSessionCreated()

await contract.addListener("ChatSessionCreated", async (...args) => {
            console.log({ args });
        });
        
await contract.on(filter, async (...args) => console.log({ args }));

All good so far. However, if I only add this, thing start to break. Despite having typing for the listener, args is an array only containing the object. The listener signature doesn't make a difference, either. Typings are wrong:

const filter = contract.filters.ChatSessionCreated()

await contract.on(filter, async (hash, creator, ...args) => 
          console.log({ hash, creator })); // hash here is the object, creator is undefined!

To complicate things further, if I use two listeners again, but this time using filtering, only the "plain" listener will get the expected array of length 3. The filtered listener will only receive the object in the array:

const filter = contract.filters.ChatSessionCreated(someHash)

await contract.addListener("ChatSessionCreated", async (...args) => {
            console.log({ args }); // length 3, as expected
        })
await contract.on(filter, async (...args) => console.log({ args })); //length 1!

Not sure whether it's a TypeChain or Ethers issue.

@markszente
Copy link
Author

Definitely not a TypeChain issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant