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

用web3@1.2.6和solcjs@0.5.0。部署一个简单的获取状态变量的值的合约。获取状态变量值报错。找了好几天都没找到原因。感谢能解惑。 以太坊新手,非常感谢帮忙解惑 报错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/2/node_modules/web3-eth-abi/src/index.js:239:15) at Contract._decodeMethodReturn (/home/2/node_modules/web3-eth-contract/src/index.js:557:22) at Method.outputFormatter (/home/2/node_modules/web3-eth-contract/src/index.js:910:46) at Method.formatOutput (/home/2/node_modules/web3-core-method/src/index.js:167:54) at sendTxCallback (/home/2/node_modules/web3-core-method/src/index.js:596:33) at /home/2/node_modules/web3-core-requestmanager/src/index.js:147:9 at XMLHttpRequest.request.onreadystatechange (/home/2/node_modules/web3-providers-http/src/index.js:110:13) at XMLHttpRequestEventTarget.dispatchEvent (/home/2/node_modules/xhr2-cookies/dist/xml-http-request-event-target.js:34:22) at XMLHttpRequest._setReadyState (/home/2/node_modules/xhr2-cookies/dist/xml-http-request.js:208:14) at XMLHttpRequest._onHttpResponseEnd (/home/2/node_modules/xhr2-cookies/dist/xml-http-request.js:318:14) at IncomingMessage. (/home/2/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

代码很简单:在infura利用ropsten测试网络 sol:

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;
    }
}

js:

const Web3 = require('web3')
const web3 = new Web3('https://ropsten.infura.io/v3/MY_INFURA_API_KEY')
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 })
})
请先 登录 后评论

最佳答案 2020-04-14 11:13

重新写了一次,ropsten没报错

请先 登录 后评论

其它 2 个回答

七哥 - 独立开发者
  擅长:Defi
请先 登录 后评论
崔棉大师
请先 登录 后评论
  • 3 关注
  • 0 收藏,9668 浏览
  • lilac 提出于 2020-04-13 20:34