当我在合同上使用 运行 方法时,如何获得 运行ning 结果?

How can I get the running result when I run method on contract?

我想写一个简单的函数来调用合约的方法并得到 运行 结果,

这是合约代码

function _evaluate(uint8[5] _uploads) internal returns (bytes32 resultId){

    resultId= keccak256(abi.encodePacked(now,  msg.sender));

    addressToid[msg.sender] = resultId;
    idToResult[resultId] = Result(msg.sender, r);
  }

function upload(uint8[5] _inputs) public returns ( bytes32 resultId) {

    return _evaluate(_inputs);
  }

前端js代码

// DEE is the contract name
return this.DEE.deployed()
        .then((instance) => instance.upload(this.inputs,  {from: base.accounts[0]}))
        .then((r) => {
          this.message = "Transaction done"

          console.log(r);



        })
        .catch((e) => {
          console.error(e)
          this.message = "Transaction failed"
        })

但实际上,我发现 r 返回的是一个**交易明细**,比如,

{tx: "0xa543fff3c3bac2268c0c94a21f6cf62faa8cf667defcd9fd8dcdbcf7669a4e58",

receipt: {…}, logs: Array(0)} logs : [] receipt : {transactionHash: "0xa543fff3c3bac2268c0c94a21f6cf62faa8cf667defcd9fd8dcdbcf7669a4e58", transactionIndex: 0, blockHash: "0x07d691308724c73025de2f346dc0d6bc4eb7e7de9871e29ea2c4d4e8fb8222bb", blockNumber: 20, gasUsed: 56460, …} tx : "0xa543fff3c3bac2268c0c94a21f6cf62faa8cf667defcd9fd8dcdbcf7669a4e58" proto : Object

没有关于应该返回的id的信息。

我是不是做错了什么?

在函数定义中指定"view":

function upload(uint8[5] _inputs) public view returns ( bytes32 resultId) {
    // do something here
    // save ad calculate
    return "123";
 }

我想我找到了答案。

It is not currently possible to return values from functions which modify the blockchain. To receive a return value, you can mark read-only functions as "constant".

For non-constant functions, the only way to "return" information is by using Solidity Events, which coalesce as LOG opcodes in the Ethereum Virtual Machine.

https://ethereum.stackexchange.com/questions/3285/how-to-get-return-values-when-function-with-argument-is-called