I'm still new to ethereum development, and when trying to execute call() on a created contract, I'm receiving varying results. Sometimes the call works, and other times it returns the 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.

Every time I execute the call it's with the same code. The ABI contains the function, and the contract address is returned from another contract method execution. Sometimes restarting the local Besu node makes it work and other times it doesn't.

I'm lost on what is the actual problem or how to fix it. Last time I encountered this error, there was a problem with the ABI, but that's not the case this time. Another time the address was the issue, but I can track the address being passed correctly from the contract creation to the input in the function.

ABI contains the function:

      "inputs": [],
      "name": "timeLeft",
      "outputs": [
          "internalType": "uint256",
          "name": "",
          "type": "uint256"
      "stateMutability": "view",
      "type": "function"

Solidity function:

    function timedOut() public view returns(bool) {
        return block.timestamp - creationTime >= timeoutInSeconds;

    function timeLeft() public view returns(uint256) {
        if(timedOut()) {
            return 0;
        } else {
            return timeoutInSeconds - (block.timestamp - creationTime);

Front end JS call:

    async getTimeLeft() {
        await this.setupIfNot();
        console.log(await this.contract.methods.timeLeft());
        let time = await this.contract.methods.timeLeft().call();
        time = parseInt(time);
        console.log("dkljf: " + time);
        return time;

When logging await this.contract.methods.timeLeft() it returns the transaction object that clearly shows call() as an available function. Because of the varying results with no code changes, I'm really confused and not sure what to do to fix it.

UPDATE: I've narrowed down the issue. When it breaks (which seems to be random) the call() function is not returning anything. I ran a direct JSON-RPC call using curl, and the chain is receiving the transaction (I ran it in verbose mode and verified that it was being sent), but nothing is being returned when it breaks. Not zero or null, nothing at all is being returned. I know what is wrong, but I still don't know why it's not returning anything, so if anyone can provide help I'd appreciate it.


The solution was to call a "cleanup" function on page load that did state cleanup on the contract before attempting to do other contract calls. As stated, there was no ABI issue nor a gas issue, but I guess state data was not what the JS expected, and calling the cleanup function prior to calling the other needed function made sure valid data was returned.

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.