0 votes
1 view
in Blockchain by (11.4k points)

I want to write a simple function to call the method on contract and get the running result,

This is the contract code

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

  }

front end js codes

// 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"

        })

but in fact, I found r returned is a ** transaction detail**, like,

{tx: "0xa543fff3c3bac2268c0c94a21f6cf62faa8cf667defcd9fd8dcdbcf7669a4e58",

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

There is no information about the id which should be returned included.

Did I do something wrong?

1 Answer

0 votes
by (27.7k points)

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.

...