1

I have very simple solidity code as below -

pragma solidity ^0.5.6;

contract SaveData {
  uint public salary;

  function setSalary(uint input) public {
        salary=input;
  }

  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. – goodvibration Mar 26 at 11:15
  • 1
    Is it on public blockchain? Could you show transaction receipt for the transaction that supposed to change state variable? – Mikhail Vladimirov Mar 26 at 11:20
  • I suppose you mean SaveData.setSalary(5000), not lowercased savedata as you wrote... – Rick Park Mar 26 at 22:53
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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