One of ethereum solidity methods is not working properly got error Returned values aren't valid, did it run Out of Gas

隐身守侯 提交于 2019-12-23 04:47:40

问题


I'm trying to deploy a solidity program to my private ethereum network. However, when i call a method it's not working properly.

This is what i'vd done before the call method.

$ truffle console
truffle(development)> var dApp
undefined
truffle(development)> Hello.deployed().then(function(instance) { dApp = instance; })
undefined
truffle(development)> dApp.message.call()

test env is below

truffle@5.0.28
solc@0.5.10
linux centOS 7
geth@1.8.23

I tried all of the solution in answer about the below error in stack overflow, but it didn't work.

Weird thing is that I installed geth on my macos using same release version, but its version was different from what I've installed on my centOS. It's 1.8.27 on macos and 1.8.23 on centOS 7.

By the way, it was working well when I tried same progress on my macos. Its return is below.

truffle(development)> dApp.message.call()
'Hello, World : This is a Solidity Smart ' +
  'Contract on the Private Ethereum ' +
  'Blockchain'

Bammmmmmmmmmmm.

This below is a solidity program I deploied.

pragma solidity >=0.4.15 <0.6.0;
contract Hello {
   string public message;

   function HelloEth() public {
    message = "Hello, World : This is a Solidity Smart Contract on the Private Ethereum Blockchain";
   }
}

This is the error returned.

Thrown:
Error: Returned values aren't valid, did it run Out of Gas?
    at XMLHttpRequest._onHttpResponseEnd (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:318:1)
    at XMLHttpRequest._setReadyState (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request.js:208:1)
    at XMLHttpRequestEventTarget.dispatchEvent (/usr/local/lib/node_modules/truffle/build/webpack:/~/xhr2-cookies/dist/xml-http-request-event-target.js:34:1)
    at XMLHttpRequest.request.onreadystatechange (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-providers-http/src/index.js:96:1)
    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-provider/wrapper.js:112:1
    at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3-core-requestmanager/src/index.js:147:1
    at sendTxCallback (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth-contract/~/web3-core-method/src/index.js:473:1)
    at Method.formatOutput (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth-contract/~/web3-core-method/src/index.js:163:1)
    at Method.outputFormatter (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth-contract/src/index.js:818:1)
    at Contract._decodeMethodReturn (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth-contract/src/index.js:465:1)
    at ABICoder.decodeParameters (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth-abi/src/index.jsa:226:1)

I really want to know because i tried almost 1 months... if you have any idea or any solution please let me know. :(


回答1:


all variable which you defined as public it will always becoming a methods. so, you can access/call your public variable as same as calling a method in smart contract. hopefully it helps you.




回答2:


I also ran into a similar problem, after I posted it in Geth Github, they indicated that the problem may be caused by the latest Solidity compilers which depend on features introduced in Constantinople.

Thus, you might need to add "constantinopleBlock": 0 in your genesis.json to let your private blockchain identify what solidity version you used.

"config": {
    "chainId": 1515,
    "homesteadBlock": 0,
    "eip150Block": 0,
    "eip155Block": 0,
    "eip158Block": 0,
    "byzantiumBlock": 0,
    "constantinopleBlock": 0,
    "petersburgBlock": 0,
    "clique": {
      "period": 2,
      "epoch": 30000
    }
  },...

Hope this answer can help you.



来源:https://stackoverflow.com/questions/57175052/one-of-ethereum-solidity-methods-is-not-working-properly-got-error-returned-valu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!