[Ethereum] Smart Contract Error: Returned values aren’t valid, did it run Out of Gas

remixrinkebysolidityweb3js

Deployed a contract using Remix IDE to Rinkeby testnet.

Etherscan contract address and code is here.

contract SimpleCounter {
    int counter;

    constructor() public {
        counter = 0;
    }

    function getCounter() public view returns (int){
        return counter;
    }

    function increment() public {
        counter += 1;
    }

    function decrement() public {
        counter -= 1;
    }
}

JavaScript client code:


    var contract;

    $(document).ready(function(){
        initContract();
        getCounterValue();
    })

    function initContract(){
        web3 = new Web3(web3.currentProvider);

        var address = "0xc6482382047fb50e8e7b4658425c9756b28f995c";
        var abi = [
                    ...
                    ];

        console.log('Create contract...');
        contract = new web3.eth.Contract(abi, address);
        console.log(contract)

    } //initContract()


    function getCounterValue(){
        console.log('getCounter()...');
        contract.methods.getCounter().call().then((result) => {
            console.log(result);
        }).catch(function(err){
            console.log('err...\n'+err);
        });
    }

Error:

Create contract…

(index):86 o {_requestManager: e, givenProvider:
MetamaskInpageProvider, providers: {…}, _provider:
MetamaskInpageProvider, …}

(index):94 getCounter()…

(index):99 err…

Error: Returned values aren't valid, did it run Out of Gas?

NOTE:

This works fine in Remix IDE (chrome).
I'm able to increment/decrement/getCounter… with compiler version:0.4.25+commit.59dbf8f1.Emscripten.clang
.

Why does it fail, when accessing it using 'dist/web3.min.js' of Web3.js (Branch 1.0)?

Best Answer

I fixed the similar error by deleting .json files from build/contracts folder and then running truffle migrate in the terminal.

However, the error occurred in Visual Studio Code, not Remix IDE. It appeared after running truffle migrate --reset.

I'd like to add to this comment, after you delete .json files from build/contracts folder the problem persisted until I deleted files from the trash🗑 😅 So make sure trash is empty

Related Topic