1

Having a smart contract mined on testnet at address 0x5a6661c75df7de88ba74437a6dc372ccfa72a564 with the following function:

    function whoAmI() constant returns (address) {
        return msg.sender;
    }

should return caller always. And that's what I am trying to verify. I works ok when calling synchronously from geth console like this:

// creation of contract object
var aContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"totalSupply","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"account","type":"address"}],"name":"queryBalanceOf","outputs":[{"name":"balance","type":"uint256"}],"payable":false,"type":"function"},{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"balanceOf","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"initialSupply","type":"uint256"}],"name":"MyToken","outputs":[],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"whoAmI","outputs":[{"name":"","type":"address"}],"payable":false,"type":"function"},{"payable":false,"type":"fallback"},{"anonymous":false,"inputs":[{"indexed":true,"name":"from","type":"address"},{"indexed":true,"name":"to","type":"address"},{"indexed":false,"name":"value","type":"uint256"}],"name":"Transfer","type":"event"}]);

// initiate contract for an address
var sc = aContract.at('0x5a6661c75df7de88ba74437a6dc372ccfa72a564');

// calling function
sc.whoAmI();
    "0x47978a69f410d0f61850c92acdb0d4c464d70937"

The problem comes when trying to call it asynchronously from another account like this:

sc.whoAmI.sendTransaction({from:"0x3b877e80b5c0b29d88f3768ed4292b35fdd93a9d"});
txHash => "0x5fc3f7454d558ad4bd01294448b45bc7072b46958375fafe32e277a770d48e90"

Where is the output of the transaction stored? Trying this:

eth.getTransactionReceipt("0x5fc3f7454d558ad4bd01294448b45bc7072b46958375fafe32e277a770d48e90")
{
  blockHash: "0xa19553677ede1d1eed791d1658a4229629346f90db5907c14c915dda13926df9",
  blockNumber: 1821495,
  contractAddress: null,
  cumulativeGasUsed: 21612,
  from: "0x3b877e80b5c0b29d88f3768ed4292b35fdd93a9d",
  gasUsed: 21612,
  logs: [],
  root: "31aa355a0a7534b18c7874a31fd78926a6869f0e9e309a972d1b5505405c6421",
  to: "0x5a6661c75df7de88ba74437a6dc372ccfa72a564",
  transactionHash: "0x5fc3f7454d558ad4bd01294448b45bc7072b46958375fafe32e277a770d48e90",
  transactionIndex: 0
}

I couldn't find it. Any help? Thx!

  • 1
    are you looking for the sent input or the returned data? – Badr Bellaj Nov 1 '16 at 13:00
  • The returned data. This function has no input, except for the very msg.sender that comes from the transaction itself. – Juan Ignacio Pérez Sacristán Nov 1 '16 at 15:14
1

I guess it is not possible to get the return value of a function when mined asynchronously. According to How to get return values when function with argument is called? it is not currently possible to return values from functions which modify the blockchain ... the only way to "return" information is by using Solidity Events.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.