I've the following contract function:

/*Solidity Code, inside my contract*/
function isGranted(address _user, address _content) view external returns (bool) {
    return (grantedAccess[_user][_content]);

That works on Remix IDE without any problem.

Then I wrote a Web3JS frontend

this.catalog = (this.web3.eth.contract(this.props.catalog.abi)).at(this.props.catalog.address);
            this.web3.eth.defaultAccount, //Parameter1
            this.state.address, //Parameter2
        (err, res) => { //Callback
                this.setState(this.setState({userHasRightAccess: res}));
            } else {

But the execution returns Error: Invalid number of arguments to Solidity function. I tried to add the other optional parameter to Web3js function but the error remains. Any idea/solution?

(I don't use Truffle or any more framework. Web3JS version is "0.19.0")

Edit: I've update the library to 0.20.6 version


The problem was that an argument was undefined. I'll added a check and now works


I would suggest checking that both parameters:
this.web3.eth.defaultAccount, //Parameter1 this.state.address, //Parameter2 actually have values at the point that you pass them into this.catalog.isGranted.

You can do this by just calling console.log with them just before you enter the web3 function - I've seen this issue when one of the parameters is undefined.

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.