1
votes

I'm studying Ethereum smart contract. I deployed my greeter contract through Mist browser, and it worked well on Mist.

So I want to make simple Dapp using my deployed greeter contract.

My contract code in Solidity:

contract mortal {
  address owner;
  function mortal() { owner = msg.sender; }
  function kill() { if (msg.sender == owner) suicide(owner); }
}

contract greeter is mortal {
  string greeting;

  function greeter(string _greeting) public {
    greeting = _greeting;
  }

  function greet() constant returns (string) {
    return greeting;
  }

  function changeMsg(string msg) {
    greeting = msg;
  }
}

My Dapp code in Javascript:

_connect() {

  /* ... */

  contract = web3.eth.contract(CONTRACT_ABI);
  instance = contract.at(CONTRACT_ADDRESS);

}

_greet() {
  console.log(instance.greet());
}

_changeMsg(msg) {
  console.log(instance.changeMsg(msg));
}

_greet() function works well, it returns my greeting message.

But _changeMsg() function returns some hexa string only. How can I change greet message through _changeMsg() function?

Thank you.

1

1 Answers

1
votes

You'll find that the message is indeed updated: try calling _greet() again.

The hex that _changeMsg() is returning is the transaction hash, which is what's always returned by state changing methods (transactions).

For more information see:

https://ethereum.stackexchange.com/questions/765/what-is-the-difference-between-a-transaction-and-a-call