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

Contracts with toString() functions panic when deployed #2054

Closed
RyanRHall opened this issue Sep 16, 2021 · 7 comments
Closed

Contracts with toString() functions panic when deployed #2054

RyanRHall opened this issue Sep 16, 2021 · 7 comments
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.

Comments

@RyanRHall
Copy link

Describe the bug
ethers fails to deploy contracts with a toString() function. (I was developing a library, but I assume normal contracts have the same issue). There are probably other function names that conflict with native js functions. valueOf() is likely another one.

Reproduction steps
Create a contract with a toString() function

library MyLibrary {
    function toString(uint256 value) public returns(string){
        // ...
    }
}

Then, attempting to deploy that contract using ethers and hardhat...

const myLibFactory = await ethers.getContractFactory('MyLibrary')
const myLib = await myLibFactory.deploy() // errors

yields this error message:

TypeError: uniqueNames[name_1].push is not a function
at /.../@ethersproject/contracts/src.ts/index.ts:717:35

Environment:
Hardhat 2.4.1, ethers 5.4.6

@RyanRHall RyanRHall added the investigate Under investigation and may be a bug. label Sep 16, 2021
@zemse
Copy link
Collaborator

zemse commented Sep 16, 2021

Can be reproduced with

new ethers.Contract(
  '0x0000000000000000000000000000000000000000', 
  ['function toString() external']
)

@ricmoo ricmoo added bug Verified to be an issue. on-deck This Enhancement or Bug is currently being worked on. and removed investigate Under investigation and may be a bug. labels Oct 16, 2021
@ricmoo
Copy link
Member

ricmoo commented Oct 20, 2021

This should be fixed in 5.5.0. Please try it out and let me know if you still have any issues.

1 similar comment
@ricmoo
Copy link
Member

ricmoo commented Oct 20, 2021

This should be fixed in 5.5.0. Please try it out and let me know if you still have any issues.

@ricmoo ricmoo added fixed/complete This Bug is fixed or Enhancement is complete and published. and removed on-deck This Enhancement or Bug is currently being worked on. labels Oct 20, 2021
@pepperstepper
Copy link

Upgrading from 5.4.5 to 5.5.1 solved this issue for me!

@oceanbluu
Copy link

trying to read valueOf function from a contract using version 5.5.2 with:

let myContract = new ethers.Contract(address, abi, provider);
let value = await myContract.valueOf(xxxx, xxxx);

.. that doesnt seem to fly. im noob though, but spent few hours on this without finding any fault in my code.
I suspect valueOf is a keyword and it wrecks it.
Visual Studio Code marks the await word with "await has no effect on this type of expression", and upon running the code it returns some big object that seems way off expected result VSC's warning message goes away if I change the function name away from "valueOf".

@ricmoo
Copy link
Member

ricmoo commented Dec 28, 2021

The method valueOf is an existing JavaScript method on objects.

You must use the fully qualified method to access this name:

await contract["valueOf(address,uint256)"](addr, val)

as an example, if your method took in an address and uint.

@RyanRHall
Copy link
Author

Closing, as this seems to be fixed in 5.5.X. Thank you @ricmoo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Verified to be an issue. fixed/complete This Bug is fixed or Enhancement is complete and published.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants