0

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");
    }
}
2
  • Can you add the contract function which doesn't work ("defaultMessage()" if I understand correctly) ? – clement Nov 7 '20 at 15:49
  • @clement I've added my contract code to my post. Please take a look! Thank you. – May Thanzin Nov 7 '20 at 15:59
0

my problems have been solved when I change my solidity version from ^0.5.11 to ^0.4.18 . Hope anyone who have similar problem with me will able to solve it.

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.