0

In my contract I have two functions with the same name, but with different number of parameters, like so:

function computeVote(uint sku, uint sellerId, uint8 _rating) public {...}

and

function computeVote(uint sku, uint sellerId, uint8 _productRating, uint8 _sellerRating) public {...}

So far so good.

But in my tests, if I call the first function like this:

await contract.computeVote(1, 1, 1, {from: this.accounts[1]});

I get an error saying Error: Invalid number of arguments to Solidity function.

If I comment out the second function, it works.

0
1

The functions have a different signature and therefore generate a different function ID. So there shouldn't be any problems with function ID collisions.

You can try this easier in Remix, for example:

pragma solidity ^0.4.24;

contract Test {
    uint256 num;

    function computeVote(uint sku, uint sellerId, uint8 _rating) public {
        num = sku + sellerId + _rating;
    }

    function computeVote(uint sku, uint sellerId, uint8 _productRating, uint8 _sellerRating) public {
        num = sku + sellerId + _productRating + _sellerRating;
    }

    function getNum() public view returns (uint256) {
        return num;
    }
}

If it doesn't work in your environment (works just fine in Remix) then there's probably some problem with your environment. Unfortunately I can't directly tell you what the problem is. Maybe things haven't compiled correctly or so?

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