Skip to main content
1 of 2
RafiAlhamd
  • 755
  • 1
  • 6
  • 13

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

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)?

RafiAlhamd
  • 755
  • 1
  • 6
  • 13