Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to fix the err:Returned values aren't valid, did it run Out of Gas?Returned values aren't valid, did it run Out of Gas? #3466

Closed
Li6lac opened this issue Apr 13, 2020 · 7 comments
Labels
1.x 1.0 related issues

Comments

@Li6lac
Copy link

Li6lac commented Apr 13, 2020

I get this error when I call just a 'get' function from a deployed contracted.This happens in real geth private blockchain and ropsten.I'm confused for a few weeks.Thanks for giving some suggestion.
My web3 is 1.2.6 and solcjs is 0.5.0+
the whole error message is 👍
{
err: 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.decodeParameters (/home/lilac/WebstormProjects/web3_learn2/node_modules/web3-eth-abi/src/index.js:239:15)
at Contract._decodeMethodReturn (/home/lilac/WebstormProjects/web3_learn2/node_modules/web3-eth-contract/src/index.js:557:22)
at Method.outputFormatter (/home/lilac/WebstormProjects/web3_learn2/node_modules/web3-eth-contract/src/index.js:910:46)
at Method.formatOutput (/home/lilac/WebstormProjects/web3_learn2/node_modules/web3-core-method/src/index.js:167:54)
at sendTxCallback (/home/lilac/WebstormProjects/web3_learn2/node_modules/web3-core-method/src/index.js:596:33)
at /home/lilac/WebstormProjects/web3_learn2/node_modules/web3-core-requestmanager/src/index.js:147:9
at XMLHttpRequest.request.onreadystatechange (/home/lilac/WebstormProjects/web3_learn2/node_modules/web3-providers-http/src/index.js:110:13)
at XMLHttpRequestEventTarget.dispatchEvent (/home/lilac/WebstormProjects/web3_learn2/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22)
at XMLHttpRequest._setReadyState (/home/lilac/WebstormProjects/web3_learn2/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14)
at XMLHttpRequest._onHttpResponseEnd (/home/lilac/WebstormProjects/web3_learn2/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14)
at IncomingMessage. (/home/lilac/WebstormProjects/web3_learn2/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61)
at IncomingMessage.emit (events.js:323:22)
at endReadableNT (_stream_readable.js:1204:12)
at processTicksAndRejections (internal/process/task_queues.js:84:21),
val: undefined
}

I'm a real new learner.Thanks for help.

@cgewecke
Copy link
Collaborator

@Li6lac Could you provide a simple example of the code (both JS and Solidity) that triggers this error so someone can reproduce the problem and debug?

It would also be helpful to know the version info of the Geth client you're using.

You might also see this error if you are not using the correct ABI for the contract you are retrieving data from

This is a really common cause of that error fwiw - perhaps you are making calls to the wrong address or not creating the contract with the correct ABI.

@Li6lac
Copy link
Author

Li6lac commented Apr 13, 2020

Thanks for reply.
For ropsten:
contract is easy enough :

pragma solidity ^0.5.0;
contract MyContract {
    string value;
    constructor() public {
        value = "myValue";
    }
    function get() public view returns(string memory ) {
        return value;
    }
    function set(string memory _value) public {
        value = _value;
    }
}

set() works well,but get() meets the error.
web3js is: use transaction to call function set() of contrac,function set()
is almost the same except for web3.eth.getTransactionCount() to send data by a tanscation.

var Tx     = require('ethereumjs-tx').Transaction
const Web3 = require('web3')
const web3 = new Web3('https://ropsten.infura.io/v3/My_INFURA_API_KEY')
//const account1 = 'my account1 address'
//const account2 = 'my account2 address'
//const pk1 = 'my pk1'
//const pk2 = 'my pk2'
//const privateKey1 = Buffer.from(pk1, 'hex')
//const privateKey2 = Buffer.from(pk2, 'hex')
const contractAddress = '0x30951343d6d80d2c94897f1a81c53cc030aef879'
const contractABI = [
    {
        "constant": false,
        "inputs": [
            {
                "internalType": "string",
                "name": "_value",
                "type": "string"
            }
        ],
        "name": "set",
        "outputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "function"
    },
    {
        "constant": true,
        "inputs": [],
        "name": "get",
        "outputs": [
            {
                "internalType": "string",
                "name": "",
                "type": "string"
            }
        ],
        "payable": false,
        "stateMutability": "view",
        "type": "function"
    },
    {
        "inputs": [],
        "payable": false,
        "stateMutability": "nonpayable",
        "type": "constructor"
    }
]
const contract = new web3.eth.Contract(contractABI, contractAddress)
contract.methods.get().call((err, val) => {
  console.log({ err, val })
})

my geth is the newest .the way for deploying and calling in geth is diffrent from above but meets the same error.What's more,there's no error in ganache-cli.And if using solidity 0.4.* ,there's no error.I think perhaps dealing the problem in ropsten will deal the other.
Thanks for replying.

@cgewecke cgewecke added 1.x 1.0 related issues support labels Apr 13, 2020
@cgewecke
Copy link
Collaborator

@Li6lac Tried to reproduce this using the Ropsten address you linked to but everything worked and did not get an error.

Compiled the contract using solc 0.5.15 which generated this ABI (think this is identical to what you posted):

[
  {
    "inputs": [],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "constructor"
  },
  {
    "constant": true,
    "inputs": [],
    "name": "get",
    "outputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
  },
  {
    "constant": false,
    "inputs": [
      {
        "internalType": "string",
        "name": "_value",
        "type": "string"
      }
    ],
    "name": "set",
    "outputs": [],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
  }
]

Then ran:

const Web3 = require('web3');
web3 = new Web3('https://ropsten.infura.io/v3/1d13168ffb894ad28....etc');

const contractAddress = '0x30951343d6d80d2c94897f1a81c53cc030aef879';
const contract = new web3.eth.Contract(abi, contractAddress)
const val = await contract.methods.get().call();
console.log(val);

Output

qikegu

@Li6lac
Copy link
Author

Li6lac commented Apr 14, 2020

@Li6lac Tried to reproduce this using the Ropsten address you linked to but everything worked and did not get an error.

Compiled the contract using solc 0.5.15 which generated this ABI (think this is identical to what you posted):

[
  {
    "inputs": [],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "constructor"
  },
  {
    "constant": true,
    "inputs": [],
    "name": "get",
    "outputs": [
      {
        "internalType": "string",
        "name": "",
        "type": "string"
      }
    ],
    "payable": false,
    "stateMutability": "view",
    "type": "function"
  },
  {
    "constant": false,
    "inputs": [
      {
        "internalType": "string",
        "name": "_value",
        "type": "string"
      }
    ],
    "name": "set",
    "outputs": [],
    "payable": false,
    "stateMutability": "nonpayable",
    "type": "function"
  }
]

Then ran:

const Web3 = require('web3');
web3 = new Web3('https://ropsten.infura.io/v3/1d13168ffb894ad28....etc');

const contractAddress = '0x30951343d6d80d2c94897f1a81c53cc030aef879';
const contract = new web3.eth.Contract(abi, contractAddress)
const val = await contract.methods.get().call();
console.log(val);

Output

qikegu

ok,thank you,i get it

@NashL
Copy link

NashL commented Mar 4, 2022

I had a similar issue and was because I set wrong the ENDPOINT for web3 in my ENV, I was working on Rinkeby Network but I copied the wrong Endpoint


From:
WEB3_ENDPOINT=https://mainnet.infura.io/v3/7c7aa534bc0a4dfe8e8198f92b281992
To:
WEB3_ENDPOINT=https://rinkeby.infura.io/v3/112sda3asdasjj33f2df3asdasf2b281992

in case helps someone else

@jeftarmascarenhas
Copy link

Can be many things, but there are two causes most common.

  1. Very if you are using abi and a contract address correct.
  2. Very if you are selected the correct network, for exempo, if your contract is on Rinkeby you can selected Rinkeby or if your contract is on Mainnet select the Mainnet.

@abixscodes
Copy link

abixscodes commented Apr 17, 2024

I get this error when I call just a 'get' function from a deployed contracted.This happens in real geth private blockchain and ropsten.I'm confused for a few weeks.Thanks for giving some suggestion. My web3 is 1.2.6 and solcjs is 0.5.0+ the whole error message is 👍 { err: 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.decodeParameters (/home/lilac/WebstormProjects/web3_learn2/node_modules/web3-eth-abi/src/index.js:239:15) at Contract._decodeMethodReturn (/home/lilac/WebstormProjects/web3_learn2/node_modules/web3-eth-contract/src/index.js:557:22) at Method.outputFormatter (/home/lilac/WebstormProjects/web3_learn2/node_modules/web3-eth-contract/src/index.js:910:46) at Method.formatOutput (/home/lilac/WebstormProjects/web3_learn2/node_modules/web3-core-method/src/index.js:167:54) at sendTxCallback (/home/lilac/WebstormProjects/web3_learn2/node_modules/web3-core-method/src/index.js:596:33) at /home/lilac/WebstormProjects/web3_learn2/node_modules/web3-core-requestmanager/src/index.js:147:9 at XMLHttpRequest.request.onreadystatechange (/home/lilac/WebstormProjects/web3_learn2/node_modules/web3-providers-http/src/index.js:110:13) at XMLHttpRequestEventTarget.dispatchEvent (/home/lilac/WebstormProjects/web3_learn2/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22) at XMLHttpRequest._setReadyState (/home/lilac/WebstormProjects/web3_learn2/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14) at XMLHttpRequest._onHttpResponseEnd (/home/lilac/WebstormProjects/web3_learn2/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14) at IncomingMessage. (/home/lilac/WebstormProjects/web3_learn2/node_modules/xhr2-cookies/dist/xml-http-request.js:289:61) at IncomingMessage.emit (events.js:323:22) at endReadableNT (_stream_readable.js:1204:12) at processTicksAndRejections (internal/process/task_queues.js:84:21), val: undefined }

I'm a real new learner.Thanks for help.

me too is facing problem can u help me on this
???

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues
Projects
None yet
Development

No branches or pull requests

5 participants