question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Warnings raised when there are Events with the same name but different inputs?

See original GitHub issue

On ethers 5.0.2

Given the following ABI with two Transfer events with different inputs:

{
  "abi": [
    {
      "anonymous": false,
      "inputs": [
        {
          "indexed": true,
          "name": "from",
          "type": "address"
        },
        {
          "indexed": true,
          "name": "to",
          "type": "address"
        },
        {
          "indexed": false,
          "name": "value",
          "type": "uint256"
        },
        {
          "indexed": false,
          "name": "data",
          "type": "bytes"
        }
      ],
      "name": "Transfer",
      "type": "event"
    },
    {
      "anonymous": false,
      "inputs": [
        {
          "indexed": true,
          "name": "from",
          "type": "address"
        },
        {
          "indexed": true,
          "name": "to",
          "type": "address"
        },
        {
          "indexed": false,
          "name": "value",
          "type": "uint256"
        }
      ],
      "name": "Transfer",
      "type": "event"
    }
  ]
}

In contract form this would look like:

contract Test {
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Transfer(address indexed from, address indexed to, uint value, bytes data);
}

When calling the above contract, ethers@5.02 logs the following warning:

Duplicate definition of Transfer 
(Transfer(address,address,uint256,bytes), 
  Transfer(address,address,uint256))

Source: https://github.com/ethers-io/ethers.js/blob/d817416bae2fbc7adb8391fd038613241b7ab8ba/packages/contracts/src.ts/index.ts#L630-L637

Why do we warn users for having Events with duplicate names? I would expect that the intention is to check for duplicate Event signatures, for example:

  • [Transfer(address,address,uint256,bytes), Transfer(address,address,uint256)] is OK 👍 since they have different event signatures.
  • [Transfer(address,address,uint256,bytes), Transfer(address,address,uint256,bytes)] is NOT OK 👎 because they have duplicate event signatures.

Is this because of the events API expecting an event name?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
ricmoocommented, Sep 7, 2020

The main reason is because of how you would access them. If you have a single Transfer event, then you could use contract.events.Transfer to get the Transfer fragment. But if there are multiple, you need to use contract.events["Transfer(address, address,uint256"] for example.

Many of these issues go away in v6 which will use a Proxy, but for now this is something there isn’t a great way around. You can always lower the Logger logLevel to error if the console logs are too much an issue. 😃

1reaction
lukehutchcommented, May 29, 2022

Well could you please at least create a setting for disabling this warning on ES3? The user should be able to decide whether they care about it or not. I have hundreds of lines of this warning in my test output, and that obscures legitimate test output.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Events: change, input, cut, copy, paste
Let's cover various events that accompany data updates. Event: change. The change event triggers when the element has finished changing.
Read more >
Warnings in Python - GeeksforGeeks
Usually, a warning occurs when there is some obsolete of certain programming elements, such as keyword, function or class, etc. A warning in...
Read more >
Advanced Callbacks | Dash for Python Documentation | Plotly
Useful when multiple inputs can trigger the callback at the same time, or multiple properties of the same component can trigger the callback....
Read more >
In Python, how does one catch warnings as if they were ...
To handle warnings as errors simply use this: import warnings warnings.filterwarnings("error"). After this you will be able to catch warnings same as errors ......
Read more >
Event handling (overview) - Event reference - MDN Web Docs
Programmers can create event handler code that will run when an event ... Warning: A third approach for setting event handlers using HTML ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found