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) {
        } 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("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?

  • Um.. you are calling getRecords. That method is not defined. Aug 18 '17 at 10:38
  • Really sorry, that was awful. Thanks for pointing me to it. Guess I should take a break!
    – mcansado
    Aug 18 '17 at 10:45

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!


You also may have this error in case of wrong argument type. Me for example always forgot to use .address to pass contract address as argument instead of contract JS object.

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.