ethers.js: Misleading error when too many arguments or missing arguments
Describe the Feature
Currently, if there is an invalid argument count, then ethers v6 throws an error that says “no matching function”. However, it can point the dev to look in the wrong direction, i.e. check if ABI being passed is correct.
Error: no matching fragment (operation="fragment", code=UNSUPPORTED_OPERATION, version=6.0.5)
But if a more helpful error is thrown, it can be helpful to immediately point out that the issue is in the arguments somewhere, similar to the error in ethers v5 which says expected argument count is 1 but passed is 2.
Error: too many arguments: passed to contract (count=2, expectedCount=1, code=UNEXPECTED_ARGUMENT, version=contracts/5.5.0)
Code Example
await dai.balanceOf(ZeroAddress)
// works
await dai.balanceOf(ZeroAddress, 0)
// Error: no matching fragment (operation="fragment", code=UNSUPPORTED_OPERATION, version=6.0.5)
await dai.balanceOf()
// Error: no matching fragment (operation="fragment", code=UNSUPPORTED_OPERATION, version=6.0.5)
About this issue
- Original URL
- State: closed
- Created a year ago
- Comments: 19 (7 by maintainers)
Commits related to this issue
- Include the missing fragment key and args when no matching Contract method or event is present (#3809). — committed to ethers-io/ethers.js by ricmoo a year ago
- [Snyk] Upgrade ethers from 5.7.2 to 6.8.0 (#175) <p>This PR was automatically created by Snyk using the credentials of a real user.</p><br /><h3>Snyk has created this PR to upgrade ethers from 5.7.... — committed to Woodpile37/EIPs by Woodpile37 8 months ago
- [Snyk] Upgrade ethers from 5.7.2 to 6.8.0 (#201) <p>This PR was automatically created by Snyk using the credentials of a real user.</p><br /><h3>Snyk has created this PR to upgrade ethers from 5.7.... — committed to Woodpile37/EIPs by Woodpile37 8 months ago
- Include the missing fragment key and args when no matching Contract method or event is present (#3809). — committed to Woodpile37/ethers.js by ricmoo a year ago
- Include the missing fragment key and args when no matching Contract method or event is present (#3809). — committed to Woodpile37/ethers.js by ricmoo a year ago
Good catch. I’ll get this in over the next week. 😃
Just randomly visited this,
The error you got is because you did not pass a parameter.
It would be “await smartContract.test(0);”
The parameter type is uint256 as you can see the abi down below
I’m using v6.7.0 and this error just popped up. I got it for the same reason: passing less params than required by a function.