0

I have the following constructor:

constructor(address _payee) public {
    payer = msg.sender;
    payee = _payee;
}

And this function in my JavaScript tests:

beforeEach(async () => {
    contract = await Contract.new(payee);
});

However, I get an error:

Error: Contract contract constructor expected 1 arguments, received 2

I made sure I cleared the build folder and I had recompiled the contracts with truffle compile --all before.

How can I pass msg.sender and payee? There are no problems with these constructor params when deploying the contract using the migrations deployer.

Using ganache 1.2.1 and truffle 4.1.13.

2 Answers 2

0

That should work. I suspect the problem is elsewhere.

It might depend on your versions, but my test files use beforeEach(async function () { - a bit different syntax. Make sure that's not an issue for you.

Are you importing the Contract correctly with something like const Contract = artifacts.require('MyContract');? (by the way I'm not sure if you get problems with using exactly the name Contract for the variable name - use another name to be sure.

1
  • Thanks for confirming the code should work! Apparently it was about ganache. The syntax is different as I'm using es8 and haha yeah I'm not actually using Contract as the contract name. I simplified the nomenclature for the SO question. Jul 29, 2018 at 18:23
0

Apparently, I simply had to restart ganache. There was an old version of the contract deployed, and most likely that caused incompatibilities.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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