Skip to main content
5 of 5
added 2 characters in body

Why calling to methods from Web3 using call() give errors although set functions with send() work

I'm new to solidity and I'm just testing some examples from tutorials.

The problem is that I can't call get functions although I can call set function.

I'm using Remix IDE for smart contract, Geth for client and React.js for UI.

How can I solve these errors. Whenever I call get functions to show outputs, I get these errors:

Error: Returned values aren't valid, did it run Out of Gas? You might also see this error if you are not using the correct ABI for the contract you are retrieving data from, requesting data from a block number that does not exist, or querying a node which is not fully synced.
    at ABICoder.push../node_modules/web3-eth-abi/lib/index.js.ABICoder.decodeParameters (index.js:286)
    at Contract.push../node_modules/web3-eth-contract/lib/index.js.Contract._decodeMethodReturn (index.js:470)
    at Method.outputFormatter (index.js:760)
    at Method.push../node_modules/web3-core-method/lib/index.js.Method.formatOutput (index.js:147)
    at sendTxCallback (index.js:523)
    at index.js:293
    at XMLHttpRequest.request.onreadystatechange (index.js:98)

This is my set function and get function written in App.js:

async setData(e) {
  e.preventDefault();
  const accounts = await web3.eth.getAccounts();
  const account = accounts[0];
  const gas = await RemixContract.methods
    .setMessage(this.state.message)
    .estimateGas();
  await RemixContract.methods
    .setMessage(this.state.message)
    .send({ from: account, gas })
    .then((res) => console.log(res))
    .catch((e) => console.log(e));
}

async getDefaultData() {
  await RemixContract.methods
    .defaultMessage()
    .call()
    .then((res) => console.log("response " + res))
    .catch((e) => console.log(e));
}

This is the contract code I am trying to run.

pragma solidity ^0.5.11;

contract RemixContract {
    string message;

    constructor() public {
        message = "Hello ZeptoBook";
    }

    function getMessage() public view returns(string memory) {
        return message;
    }

    function setMessage(string memory _message) public {
        require(_message =="hi");
        message = _message;
    }

    function defaultMessage() public pure returns(uint256 num, string memory str){
        return (999, "This is RemixContract Default Message");
    }
}