-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Error: Invalid number of arguments to Solidity function, when correct number of arguments is passed to a contract method #1043
Comments
Possibly related to: #925 |
It expects a callback, and for send transaction an object as last parameter. Can please retest, also you are sending strings and not valid bytes as parameters, so there is a type mismatch between your input and your ABI |
@frozeman You mean like this?
I do that in my real code, i just cut that out for brevity. Regarding the type mismatch: Well, it worked before, i assumed web3 (or truffle / truffle-contract) would handle type conversion internally. |
I dont know what truffle adds or changed on the contract object... |
I tested locally and doesnt give me this parameter error, so it seems that this is related to truffle. @tcoulter any idea? |
Might be us. I'll take a look! |
@tcoulter Little update: The problem seems to only occur inside truffles migration files. I use migrations to add some data to the development chain for testing purposes. As mentioned above, i can get the migrations to run by adding the additional argument. Running my tests does not require the additional argument. This is a simplified version of my "data loading" migration file:
Am i using migrations wrong? |
Sounds like it's interpreting the last parameter, an array, as an object, and then assuming it's the tx params object. Thanks for this. Will get on it right now. |
Thanks gents, closing this issue. |
Alright, update on this. It all comes back to #995; Fortunately, web3 v0.20.2 fixes the issue. We'll upgrade Truffle to use |
Truffle v3.4.11 is out, upgrading web3 to v0.20.2. Thanks all! |
web3 is at 0.20.1 in latest beta, is this intentional? when will it be upgraded? |
Guys, Delete your build folder, then run the command.
I find it works best when running truffle locally to the folder rather than globally, due to the beta and different versions getting updated quickly recently.
|
I keep having to delete the build folder to make things work. I was having a different problem where trying to read simple info from my smart contracts would throw a Big Number error. Deleting the build folder solved it again. Doesn't feel optimal :P |
I get this error occasionally with Truffle. Deleting the |
To potentially resolve some issues like this one: web3/web3.js#1043
Still getting this error even after recompilng everyting. My solution was to use the contract object inside the truffleContract instance and call the functions from there. |
Just got this too, reason was a type mismatch (I gave a Date while a uint was expected). Poor error handling! |
Guys, this is an API that nearly EVERY Ethereum developer will end up using. Errors like this should be embarrassing. This error is awful and wastes so much time for every developer. Please give SENSIBLE ERRORS about inputs. If one is expected and not provided, vice versa, or type mismatch. Next, allow calling methods in a sensible way. None of this ordinal arguments MESS. Eg, for Or: Using ordinality in arguments is always a mess. You have to type check, and it's annoying to reflectively call things via I made an issue about both of these, separately, about a year ago, and have seen this error cited in COUNTLESS places ALL OVER THE PLACE. Nobody cares about the syntax sugar of doing |
@beether It's open source software. You're free to contribute |
@kyriediculous It's web3. It's what comes with every browser extension that supports Ethereum. Kind of hard to just not use it. @k26dr The fact that something is open source doesn't magically absolve the creators, who I'm pretty sure were compensated by the Ethererum Foundation, from implementing sensible design decisions. Furthermore, you might as well go and post your comment to every single "Issue" in all of GitHub. |
I get this issue too, with the following latest stable truffle and web3 versions:
I see this issue is closed, but don't seem to be able to find a solution for this. Can anyone please help? I'm still new to blockchain development :( |
@h36yang and whomever else it may concern, I got this same issue when working with 0x.js. What was strange was that the error only happened in the production (= minified) js build, not with the development (= unminified) JS build! Well, turns out that this piece of code in web3's
is used to validate arguments of type However, the I don't know if this relevant for your situation, but I'm just posting this here in case it helps someone else. Anyway, I think it would be better to do the Edit: There's already a submitted issue for this: #1356 . I posted my temporary fix in the issue. |
@koirikivi This bug has been around forever, kudos for digging into it -- I remember doing that months ago. I've found the most reliable workaround is to always use the web3's version of BigNumber:
BTW, can you imagine how much time it could have saved you if it gave an error like |
@beether Thanks for the tip! I agree on the point about the error messages. The "wrong number of arguments" line is confusing since that's not what's actually happening in this case. A minimal change, even without breaking the current API, would be to throw something like |
Deleting build folders and truffle migrate --reset --compile-all does not work for me! :( Can't test!! |
This happened to me too: Basically the error should read "Incorrect data types". My contract was expecting numbers and got strings so a quick Number("string) fix solved the issue. |
Hi all, I am getting this issue too but using the contract object directly instead of the truffle object i.e. web3.eth.Contract(abi, address). This is only broken now after I updated to ^1.0.0-beta.36 from an early pre beta version (0.18.4). Any ideas? |
so basically this error which has 100s of thousands of instances in google, is actually just a mistaken message? it is about argument types not number of args? |
@dcsan The majority of these reports were caused by compilation bug in Truffle 4, although there are a handful of other possible causes. But this thread has been quiet for a while... What context are you seeing it in? |
this is 2023 and i still have this error Web3ContractError: The number of arguments is not matching the methods required number. You need to pass 0 arguments. |
I have this contract:
I call the method like this:
Expected result: Transaction is successfull.
Actual result: "Error: Invalid number of arguments to Solidity function"
While debugging this, i tried adding another argument:
Expected result: "Error: Invalid number of arguments to Solidity function"
Actual result: Transaction is successfull.
This is the generated ABI:
This exact code worked, before i upgraded web3 to the latest version.
The text was updated successfully, but these errors were encountered: