0

I have a public contract variable: uint public bidEnd, and I'm getting its value using web3js like so:

new web3.eth.Contract(json, address).methods.bidEnd().call(function(err, res){
    console.log("err is ", err);
    console.log(res);
};

And it's printing the following in the console:

err is  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 require.decodeParametersWith (index.js:299)
    at require.decodeParameters (index.js:286)
    at Contract.global._decodeMethodReturn (index.js:471)
    at Method.outputFormatter (index.js:761)
    at Method.formatOutput (index.js:148)
    at sendTxCallback (index.js:524)
    at cb (util.js:703)
    at Item.run (browser.js:154)
    at drainQueue (browser.js:124)

What am I doing wrong and how to fix this?

5
  • You should share the code of bidEnd
    – Xavier59
    Commented Jul 23, 2021 at 10:05
  • bidEnd is a public variable. Solidity compiler creates getters automatically for public variables Commented Jul 23, 2021 at 10:06
  • From the error message the function returns something that isn't expected by the js code, so likely the call failed. What blockchain are you using? public testnet, ganache, private network. Do any other function work?
    – Ismael
    Commented Jul 24, 2021 at 20:15
  • No functions were working until I re-deployed the contracts Commented Jul 25, 2021 at 4:05
  • @lampbottle There isn't enough code to test. The function outputFormatter appears in the stack trace so it looks like something went wrong while reading the result, so either the contract reverted and returned something that doesn't match the expected output or the abi is wrong/old and web3 fails when decoding the returned output.
    – Ismael
    Commented Jul 27, 2021 at 2:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.