2

Is smart contract data valid if i access the contract data in ethereum node which is not synced yet to latest block?

EDIT: By valid, i meant, consider this scenario: if i have a the smart contract with data (lets say variable x=10 ). i have stopped syncing node. Some other party has changed the data in smart contract ( x=20). now without syncing if i try to access x in smart contract.. will the value of x be 10 or 20

  • After edition, it is almost another question... Nothing to do with validity, it is now an issue of freshness. – bortzmeyer Jun 5 '16 at 15:19
  • @bortzmeyer I agree the original question was vague; I wasn't sure if you were going to update your answer so posted mine. I see you updated your answer and I've upvoted it. – eth Jun 6 '16 at 4:23
4

Without syncing, the value of x in the contract would be 10.

Contract data/state is updated by transactions, which are in chunks called blocks, and syncing is the process of getting new blocks.

  • can i do smart contract transaction( execute smart contract function) without syncing the node?? will i be able to do the following : var MyContract = web3.eth.contract(abi).at('0x42411cdc75bbdc30c37308ba04677d1f218426ce'); MyContract.functionname.sendTransaction(10,{from:}) – siddesh sangodkar Jun 6 '16 at 10:47
  • Maybe if your account already has balance and hasn't sent any transactions before: it could be like ethereum.stackexchange.com/a/5709/42 For development without syncing, one tool to try is Truffle (which uses testrpc) – eth Jun 7 '16 at 5:06
3

It depends a bit on what you call valid (validity is in the eye of the beholder, who can have, for instance, complicated business rules he would like to be obeyed). What Ethereum guarantees is that the state of the contract will be consistent. If a contract updates two variables, you will never see from the outside a state where only one variable has changed (things like cryptocurrencies would be unthinkable otherwise). Ethereum works with transactions.

In the case you mention in the new version of your question; you would get 10 (the old value) since reading a variable in Ethereum is a purely local operation (nothing is sent on the network). Nodes see the same values only if they are at the same block number. Otherwise, Ethereum only provides "eventual consistency".

I suggest that you read the seminal paper "ETHEREUM: A SECURE DECENTRALISED GENERALISED TRANSACTION LEDGER" by Gavin Wood, where it is well explained.

  • by valid, i meant, consider this scenario: if i have a the smart contract with data (lets say variable x=10 ). i have stopped syncing node. Some other party has changed the data in smart contract ( x=20). now without syncing if i try to access x in smart contract.. will the value of x be 10 or 20. – siddesh sangodkar Jun 3 '16 at 4:33

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.