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

Sep 11, 2018 in Blockchain by sabby
• 4,370 points
1,041 views

1 answer to this question.

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 25, 2018 in Blockchain by Shashank
• 10,400 points
977 views
0 votes
1 answer

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

You need to remove the colon: list.select(&valid_transaction) The & ...READ MORE

answered Aug 24, 2018 in Blockchain by digger
• 26,740 points
680 views
–1 vote
1 answer

How to get balance of all accounts in ethereum network using javascript?

You can write a function that will ...READ MORE

answered Jan 10, 2019 in Blockchain by Omkar
• 69,220 points
2,463 views
+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 27, 2018 in Blockchain by Johnathon
• 9,090 points
1,964 views
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
1,928 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,456 views
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
• 69,220 points
1,469 views
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 1,576 views
+15 votes
5 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP