I'm new in smart contracts and faced with one problem. After deploying contract to my test local blockchain network, i try to set new value via setter, after that I call get method of contract and it return old value.
This is my contract,
pragma solidity ^0.4.10;
contract Storage {
uint256 storedData;
function set(uint256 data) {
storedData = data;
}
function get() constant returns (uint256) {
return storedData;
}
}
What steps I did:
- Deploy contract via web3j in java code, after deploying I see address of my contract,so it's deployed
- After than in geth console create variable abi: var abi = [{"constant":false,"inputs":[{"name":"data","type":"uint256"}],"name":"set","outputs":[],"payable":false,"statemutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":false,"statemutability":"view","type":"function"}];
- load contract: var storage = eth.contract(abi)
- load contract by adress: var contractInstance = storage.at("0x45564fe8d90e542f3f896dd43b374210bc109299");
- try calling method get(): var result = contractInstance.get(); it's output 0
- then try set new value: var result = contractInstance.set(566); After that I see something like this: INFO [09-07|08:42:07] Submitted transaction fullhash=0x7110b3fdfc8005187ed367beb8275a6f4b926f4852f726784219a5a3aa9c8d9e recipient=0x45564fe8d90e542f3f896dd43b374210bc109299 "0x7110b3fdfc8005187ed367beb8275a6f4b926f4852f726784219a5a3aa9c8d9e"
- Next I start mining: miner.start(), at the beginning of mining a see log like this: INFO [09-07|08:44:15] Commit new mining work number=38 txs=1 uncles=0 elapsed=1.044ms INFO [09-07|08:44:15] Successfully sealed new block number=38 hash=e62548…39ad89 INFO [09-07|08:44:15] 🔗 block reached canonical chain number=33 hash=9a6ae1…9cb82d INFO [09-07|08:44:15] 🔨 mined potential block number=38 hash=e62548…39ad89 INFO [09-07|08:44:15] Commit new mining work number=39 txs=0 uncles=0 elapsed=182.5µs INFO [09-07|08:44:15] Successfully sealed new block number=39 hash=87b682…f52e39 INFO [09-07|08:44:15] 🔗 block reached canonical chain number=34 hash=cc9a2d…36838a INFO [09-07|08:44:15] 🔨 mined potential block number=39 hash=87b682…f52e39 INFO [09-07|08:44:15] Mining too far in the future wait=2s
- Then I stop mining: miner.stop() 9.Then call contractInstance.get(): and see the same value 0
I'm confused( Thanks everybody for help!
storedData
a default value before you try to change it, that will tell you whether your problem is the reading or the writing.