Changing value in contract not reflected in geth console

trialcritictrialcritic Posts: 1Member
I am using a geth private console and a simple sol file which sets and gets a number
pragma solidity ^0.4.0;

contract SimpleStorage {
  uint storedData;

  function set(uint x) {
    storedData = x;
  }

  function get() constant returns (uint) {
    return storedData;
  }
}
I did the following
 var abi = <abi from solc>;
 var myContract = eth.contract(abi); 
 var bytecode = '0x' + <bytecode from solc>;
 var txDeploy = {from:eth.coinbase, data: bytecode, gas: 1000000}; 
 var myContractPartialInstance = myContract.new(txDeploy); 

 miner.setEtherbase(eth.accounts[0])
 miner.start(4)
After 30 secs
 miner.stop()
 myContractPartialInstance.get()
 myContractPartialInstance.set.call(123)

 miner.setEtherbase(eth.accounts[0])
 miner.start(4)
After some time
 miner.stop()
 myContractPartialInstance.get()
I get 0 instead of 123. What is the error?

Comments

  • mikeshultzmikeshultz Posts: 4Member
    Don't use call. Your set function call is a transaction because it writes to the blockchain. Should be something like this:
    var tx = myContractPartialInstance.set(123, {from: eth.accounts[0], gas: 90000})
    // Check the transaction went through(mining has to be happening)
    eth.getTransactionReceipt(tx)
    Adjust accordingly.
Sign In or Register to comment.