这是我的package.json
:
{
"dependencies": {
"solc": "^0.4.16",
"web3": "^1.0.0-beta.20"
}
}
这是我的智能合约代码:
contract HelloWorld {
function displayMessage() constant returns (string) {
return "Hello from a smart contract";
}
}
我已经在运行 testprc 的节点 repl 上编译了这个合约,并且我正在尝试displayMessage
像这样调用该方法:
myContract.methods.displayMessage().call()
或者
myContract.methods.displayMessage.call()
但我只是收到这个错误:
> Unhandled rejection Error: ERROR: The returned value is not a convertible string:
at SolidityTypeString.formatOutputString [as _outputFormatter] (/Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-abi/src/formatters.js:245:15)
at /Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-abi/src/type.js:246:25
at SolidityTypeString.SolidityType.decode (/Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-abi/src/type.js:247:11)
at /Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-abi/src/index.js:327:49
at Array.forEach (<anonymous>)
at ABICoder.decodeParameters (/Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-abi/src/index.js:326:13)
at Contract._decodeMethodReturn (/Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-contract/src/index.js:490:22)
at Method._parent._ethereumCall.call.method.outputFormatter (/Users/alberthu/Documents/solidity-intro/node_modules/web3-eth-contract/src/index.js:820:42)
at Method.formatOutput (/Users/alberthu/Documents/solidity-intro/node_modules/web3-core-method/src/index.js:179:54)
at sendTxCallback (/Users/alberthu/Documents/solidity-intro/node_modules/web3-core-method/src/index.js:446:33)
at /Users/alberthu/Documents/solidity-intro/node_modules/web3-core-requestmanager/src/index.js:144:9
at XMLHttpRequest.request.onreadystatechange (/Users/alberthu/Documents/solidity-intro/node_modules/web3-providers-http/src/index.js:64:13)
at XMLHttpRequestEventTarget.dispatchEvent (/Users/alberthu/Documents/solidity-intro/node_modules/xhr2/lib/xhr2.js:64:18)
at XMLHttpRequest._setReadyState (/Users/alberthu/Documents/solidity-intro/node_modules/xhr2/lib/xhr2.js:354:12)
at XMLHttpRequest._onHttpResponseEnd (/Users/alberthu/Documents/solidity-intro/node_modules/xhr2/lib/xhr2.js:509:12)
at IncomingMessage.<anonymous> (/Users/alberthu/Documents/solidity-intro/node_modules/xhr2/lib/xhr2.js:469:24)
at emitNone (events.js:110:20)
at IncomingMessage.emit (events.js:207:7)
at endReadableNT (_stream_readable.js:1059:12)
at _combinedTickCallback (internal/process/next_tick.js:138:11)
at process._tickDomainCallback (internal/process/next_tick.js:218:9)
我试过阅读 web3 api 文档,但我是新手,没有发现任何有用的东西。任何人都知道我怎样才能在服务器上显示“来自智能合约的你好”?
谢谢!