I have very simple solidity code as below -

pragma solidity ^0.5.6;

contract SaveData {
  uint public salary;

  function setSalary(uint input) public {

  function getSalary() public view returns(uint) {
        return salary;


I am calling savedata.setSalary(5000) from eth console. It generates a transaction. However after mining the transaction when I ran savedata.getSalary() it always return me 0. I tried allocating a lot of GAS as well.

  • 1
    Sounds like your node is not synced. Also, make sure to await for the function to complete, or resolve the promise it returns before you read the state variable. Mar 26, 2019 at 11:15
  • 1
    Is it on public blockchain? Could you show transaction receipt for the transaction that supposed to change state variable? Mar 26, 2019 at 11:20
  • I suppose you mean SaveData.setSalary(5000), not lowercased savedata as you wrote...
    – Rick Park
    Mar 26, 2019 at 22:53

2 Answers 2


Try following commands after migration. I am using truffle console.

  • SaveData.deployed().then((instance) => instance.setSalary(1000))

  • SaveData.deployed().then((instance) => instance.getSalary())

and its working for me.


I am pretty late to reply. I think remove the view and your problem will be solved. You are obviously making some changes here. View is for read operations only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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