solidity web3js contract-invocation – Error: Invalid number of arguments to Solidity function

contract-invocationnodejssolidityweb3js

I have the following code in a contract

contract UserBasic {
    bytes32 test;
    function getBytes() constant returns(bytes32) {
        return test;
    }
    function setBytes(bytes32 _bytes) {
        test = _bytes;
    }
}

And the following in my node app (as part of an object)

getBytes: function getBytes(contractAddress) {
    // Fetching the contract related data
    const input = fs.readFileSync('contracts/UserBasic.sol').toString();
    const output = solc.compile(input);
    const bytecode = output.contracts[':UserBasic'].bytecode;
    const abi = JSON.parse(output.contracts[':UserBasic'].interface);
    const contract = web3.eth.contract(abi).at(contractAddress);
    // Interaction with the contract
    contract.getRecords.call((err, res) => {
        // Log transaction to explore
        if (err) {
            console.log(err);
        } else {
            console.log("Raw Bytes: " + res);
            const hex = res;
            const padded = web3.toAscii(hex);
            const firstNull = padded.indexOf('\x00');
            const id = padded.slice(0, firstNull);
            console.log(id);
            console.log("Treated Bytes: " + id);
        }
    });
}

When I click the button in my user interface to trigger setBytes everything works. But getBytes returns an error

Error: Invalid number of arguments to Solidity function

The function doesn't take any arguments and I'm not passing any either so I don't understand where the error is coming from. Can anyone point me to it?

Best Answer

Looks like its just that you've just renamed the getBytes as getRecords at some point, and so in your node app when you call getRecords you are getting the error as it is undefined!

Related Topic