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.

[ethers-v5] Error generating code for events with tuples

See original GitHub issue

When an event definition includes a tuple among its arguments, the generated code in the corresponding .d.ts file is invalid for the ethers-v5 target.

I have reproduced this problem using the latest code from the master branch (matches tag @typechain/ethers-v5@6.0.3). I have simply added an event with a tuple to the examples/ethers-v5/abi/dai.json file, as shown in this fork’s commit.

Namely, I included an event definition as such in examples/ethers-v5/abi/dai.json:

  {
    "anonymous": false,
    "inputs": [
      { "indexed": true, "internalType": "address", "name": "src", "type": "address" },
      {
        "indexed": false,
        "name": "data",
        "type": "tuple",
        "components": [
          { "name": "index", "type": "uint256" },
          { "name": "name", "type": "string" }
        ]
      }
    ],
    "name": "Tuple",
    "type": "event"
  }

Then the generated code in the examples/ethers-v5/types/ethers-contracts/Dai.d.ts is:

    Tuple(
      src: string | null,
      data: null
    ): TypedEventFilter<
      [string, [BigNumber, string], { index: BigNumber; name: string }] & {
        src: string;
        data: [BigNumber, string] & { index: BigNumber; name: string };
      }
    >;

Which leads to the following error when running yarn typecheck within examples/ethers-v5

$ yarn typecheck
yarn run v1.22.5
$ tsc --noEmit
types/ethers-contracts/Dai.d.ts:837:8 - error TS2314: Generic type 'TypedEventFilter<EventArgsArray, EventArgsObject>' requires 2 type argument(s).

837     ): TypedEventFilter<
           ~~~~~~~~~~~~~~~~~
838       [string, [BigNumber, string], { index: BigNumber; name: string }] & {
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
841       }
    ~~~~~~~
842     >;
    ~~~~~


Found 1 error.

error Command failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

At first glance, it seems to me that the correct output would be to switch the position of , and & as follows:

    Tuple(
      src: string | null,
      data: null
    ): TypedEventFilter<
      [string, [BigNumber, string]& { index: BigNumber; name: string }] , {  // <---- switched `&` and `,` here
        src: string;
        data: [BigNumber, string] & { index: BigNumber; name: string };
      }
    >;

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
krzkaczorcommented, Mar 16, 2021

@zemse don’t worry - I am on it. Focus on your exams so you have more time to help us in the future 😆

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error: filtering with tuples or arrays not supported · Issue #1057
But ethers.js doesn't seem to filter the array of Hashes present. Solidity code: event onSubmission(bytes32[] indexed docHash); Node...
Read more >
invalid bignumber string ethers - You.com | The AI Search ...
ethers js exits with this error=> invalid BigNumber value ... dethcrypto/TypeChain[ethers-v5] Error generating code for events with tuples#353.
Read more >
error in getting latest 10 past events using ethers v5
I am trying to get latest 10 past events using ethers.js (v5.5.4). below is my code: const provider = new ethers.providers.
Read more >
ABI Formats - ethers
For production code it is recommended to inline the Human-Readable ABI as it makes it easy to see at a glance which methods,...
Read more >
Documentation - Ethers.js
A Contract is an abstraction of program code which lives on the Ethereum ... Short example of manually creating filters for an ERC-20...
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