3

I am getting the error Error: Invalid number of arguments to Solidity function for the constructor of my contract and no idea why.

I just upgraded to Truffle 4.0.0 beta and using the truffle develop test environment instead of testrpc. These tests used to pass, but now they are giving me errors.

Contract constructor

function MyContract(
        bytes _eventName, 
        bytes32[] _eventResultNames, 
        uint256 _eventBettingEndBlock,
        uint256 _decisionEndBlock,
        uint8 _averageBlockTime,
        uint256 _arbitrationOptionMinutes) 
        public
        payable
    {
        ...
    }

Mocha test class

const params = {
        _eventName: "test",
        _eventResultNames: ["first", "second", "third"],
        _eventBettingEndBlock: 100,
        _decisionEndBlock: 120,
        _averageBlockTime: 10,
        _arbitrationOptionMinutes: 1440
    };
const baseReward = Utils.getBigNumberWithDecimals(10, nativeDecimals);

let myContract;

beforeEach(async function() {
        myContract = await MyContract.new(...Object.values(params), { from: creator, value: baseReward });
    });

Error message

1) Contract: MyContract New MyContract inits the MyContract with the correct values:
     Error: Invalid number of arguments to Solidity function
      at Object.InvalidNumberOfSolidityArgs (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:43993:16)
      at SolidityFunction.validateArgs (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:357969:22)
      at SolidityFunction.toPayload (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:357985:10)
      at SolidityFunction.call (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:358026:24)
      at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:326504:16
      at Promise (<anonymous>)
      at /usr/local/lib/node_modules/truffle/build/cli.bundled.js:326495:18
      at <anonymous>

How do I fix this error?

1

Delete your build folder, then run the command. The reset command might work for some, didn't for me, might be a Mac thing. npm run truffle migrate --reset --compile-all 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. if you prefer the global approach try truffle migrate --reset --compile-all

  • Ya I figured this out eventually as well. I don't think the --compile-all actually recompiles it lol. – The Nomad Nov 8 '17 at 4:22
1

I experienced this issue yesterday. It seems to be a bug in the Truffle 4.0.0 beta. I rollback to the latest stable version 3.4.11 and it fixed the issue.

npm uninstall -g truffle

npm install -g truffle

EDIT: The project needs to be rebuilt/redeployed:

truffle migrate --reset --compile-all
  • I have actually already tried rolling back, but my tests still don't pass. Did you do anything special other than those two commands? – The Nomad Oct 3 '17 at 12:42
  • I just rerun the migration with the parameter reset and compile-all: truffle migrate --reset --compile-all . I think the JSON build file has to be regenerated. – Greg Jeanmart Oct 3 '17 at 12:44
  • truffle migrate --reset --compile-all worked! Thank you! For some reason, calling truffle compile -all then truffle migrate --reset didn't fix it... – The Nomad Oct 3 '17 at 13:37
-1

Unfortunately the above suggested answer didn't work. Try deleting the build folder and then compile deploy

truffle migrate --reset

I had the same issue, the compiled code is corrupted. It works for the first time only and the subsequent compile corrupts the build. Hope it helps.

-1

Try deleting the build folder and run

truffle migrate --reset

I had the same issue, the compiled code was corrupted. Hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.