3

With this code:

pragma solidity ^0.4.0;

contract Test {
    string word = "Hi Guys";

    function getWord() constant returns(string) {
        return word;
    }

   function resetWord() returns(string) {
       word="Hi Guys again";
        return("Hi Guys again");   
    }
}

With function getWord() i got "Hi Guys" in the bottom window of Remix. But with function resetWord i doesn't get text on the bottom window of Remix. What i get is:

transact to browser/test.sol:Test.resetWord pending ... [vm] from:0xca3...a733c, to:browser/test.sol:Test.resetWord() 0x0dc...97caf, value:0 wei, data:0x1f2...09393, 0 logs, hash:0xaea...bad80

and i don't see "Hi Guys again". The content of variable word is correctly update.

Why? Can anyone tell me why?

Thanks in advance.

SomeOneMore
  • 53
  • 1
  • 4

2 Answers2

3

resetWord is a function that modifies a state variable. It's a transaction. Transactions don't return values outside of solidity, all you get is a tx hash which corresponds to the transaction being mined.

Remix is nice enough to give you the details of the transaction log after the transaction is mined, but if you wanted to access the data from a Dapp, you would have to either watch for events or call getWord() after resetWord() has been successfully mined.

pabloruiz55
  • 7,686
  • 2
  • 17
  • 38
  • How to wait until and how to know when resetWord() is mined before call getWord()? – SomeOneMore Nov 06 '17 at 18:08
  • On remix, when you get the results it means it was mined (it won't be pending anymore). Notice that the pending to result change is almost instant if you are testing on testrpc or Javascript VM, but when using Injected Web3 on a testnet or mainnet it will take 30-60 seconds. – pabloruiz55 Nov 06 '17 at 18:10
  • On a web3 app (Dapp) you can use Truffle to get a callback when the transaction is mined OR use web3 to watch for events to get notified when it has been successfully mined. – pabloruiz55 Nov 06 '17 at 18:11
  • But i only get the "pending..." message on the debug window. I don't get any more message about. and never see the return message. – SomeOneMore Nov 06 '17 at 18:26
  • Try refreshing the Remix tab, sometimes it gets stuck on a pending transaction and doesn't display any further logs anymore. – pabloruiz55 Nov 06 '17 at 19:20
2

Just building on pabloruiz55's answer...

You can expand the transaction details in remix to show more. You'll see your expected message in the "decoded output" field. :)

enter image description here

Malone
  • 1,590
  • 12
  • 23