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

Most upvoted comments

Good catch. I’ll get this in over the next week. 😃

mapping(uint256 => address) public test;

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


[
	{
		"inputs": [
			{
				"internalType": "uint256",
				"name": "",
				"type": "uint256"
			}
		],
		"name": "test",
		"outputs": [
			{
				"internalType": "address",
				"name": "",
				"type": "address"
			}
		],
		"stateMutability": "view",
		"type": "function"
	}
] 

This has been address in v6.6.5. The error now includes the key and the arguments passed to help identify what the problem is.

Let me know if you have any more suggestions.

Thanks! 😃

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.