How to use ethereum contract's state changing method in javascript?

0 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 =;


_greet() {

_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?

Sep 11, 2018 in Blockchain by sabby
• 4,050 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 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).
answered Sep 11, 2018 by Christine
• 15,790 points

Related Questions In Blockchain

+1 vote
1 answer

How to store state data in Ethereum blockchain?

You won't have to overwrite the whole ...READ MORE

answered Apr 24, 2018 in Blockchain by Shashank
• 10,330 points
0 votes
1 answer

How to use Proc/lamba returned from a method in Ruby?

You need to remove the colon: The & ...READ MORE

answered Aug 24, 2018 in Blockchain by digger
• 27,620 points
0 votes
1 answer
+1 vote
1 answer

How to deploy ethereum smart contracts on a website?

There are many ways to do this: 1 ...READ MORE

answered Mar 26, 2018 in Blockchain by Johnathon
• 9,030 points
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
0 votes
1 answer
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 65,820 points
0 votes
1 answer

How to make sure transactions take no fee in a private Ethereum blockchain?

In a private ethereum network you have ...READ MORE

answered Mar 26, 2018 in Blockchain by Christine
• 15,790 points

edited Mar 26, 2018 by Christine 56 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.