1

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.catalog.isGranted(
            this.web3.eth.defaultAccount, //Parameter1
            this.state.address, //Parameter2
        (err, res) => { //Callback
            if(!err){
                console.log(res);
                this.setState(this.setState({userHasRightAccess: res}));
            } else {
                console.error(err);
            }
        })

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

2

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

1

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.