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.

[Bug] Static call and function calls doesn't match whats in the function property

See original GitHub issue

Issue with type generation

Using ethersv5 and typechain and hardhat

Below of is a snippet of a simple test contract:

contract YourContract {
  event SetPurpose(address sender, string purpose);
  string _purpose = 'Building Unstoppable Apps';

  constructor() {
    // what should we do on deploy?
  }

  function purpose() public view returns (string memory) {
    return _purpose;
  }

  function setPurpose(string memory newPurpose) public payable {

    _purpose = newPurpose;
    console.log(msg.sender, 'set purpose to', _purpose);
    emit SetPurpose(msg.sender, _purpose);
  }
}

Typechain generates a purpose function that has multiple return types. string and [string] as shown below.

This is what typechain generates

...
  functions: {
    purpose(overrides?: CallOverrides): Promise<[string]>;

    setPurpose(
      newPurpose: string,
      overrides?: PayableOverrides & { from?: string | Promise<string> }
    ): Promise<ContractTransaction>;
  };

  purpose(overrides?: CallOverrides): Promise<string>;

  setPurpose(
    newPurpose: string,
    overrides?: PayableOverrides & { from?: string | Promise<string> }
  ): Promise<ContractTransaction>;

  callStatic: {
    purpose(overrides?: CallOverrides): Promise<string>;

    setPurpose(newPurpose: string, overrides?: CallOverrides): Promise<void>;
  };
...

The return type of

functions: {
    purpose(overrides?: CallOverrides): Promise<[string]>;
}

does not match the static call and function call return type

  purpose(overrides?: CallOverrides): Promise<string>;

  callStatic: {
    purpose(overrides?: CallOverrides): Promise<string>;

    setPurpose(newPurpose: string, overrides?: CallOverrides): Promise<void>;
  };

Possible Cause

It seems to have to do with something with the target-ethers-v5 implementation of generateOutputTypes

https://github.com/ShravanSunder/TypeChain/blob/c0e175b3b6e8176d66bbbcc7f44e00987dd0e615/packages/target-ethers-v5/src/codegen/types.ts#L22-L28

export function generateOutputTypes(options: GenerateTypeOptions, outputs: Array<AbiOutputParameter>): string {
  if (!options.returnResultObject && outputs.length === 1) {
    return generateOutputType(options, outputs[0].type)
  } else {
    return generateOutputComplexType(outputs, options)
  }
}

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ShravanSundercommented, Jan 5, 2022
0reactions
krzkaczorcommented, Mar 11, 2022

Please repoen if this is still a problem.

Read more comments on GitHub >

github_iconTop Results From Across the Web

java - What is the reason behind "non-static method cannot be ...
You can't call something that doesn't exist. Since you haven't created an object, the non-static method doesn't exist yet. A static method ......
Read more >
Linker Tools Error LNK2019 - Microsoft Learn
A function or variable is declared but not defined. LNK2019 can occur when a declaration exists in a header file, but no matching...
Read more >
Fixing common type problems - Dart
Fixing common type problems · Undefined member · Invalid method override · Missing type arguments · Unexpected collection element type · Constructor initialization ......
Read more >
Common issues and solutions - mypy 0.991 documentation
This section has examples of cases when you need to update your code to use static typing, and ideas for working around issues...
Read more >
Code Inspections in PHP | PhpStorm Documentation - JetBrains
Functions with such a return type are not expected to return any value and must prevent the rest of the script execution by...
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