Say I have a contract like so:

pragma solidity ^0.4.0;

contract SimpleStorage {
    uint storedData;

    function set(uint x) {
        storedData = x;

    function get() constant returns (uint) {
        return storedData;

Kindly correct me if I'm wrong, but it is possible to change x to, say, the value 500, and the transaction that called set(500) will be included in a block, which will make the change in the contract state. If another user calls the get function after the block has been mined, it'll return 500.

However, is it not the case that the block that contains the transaction that called set will be orphaned in the future, and then future get calls would return the previous value (e.g. 0)? Or am I not understanding Ethereum properly?

If what I said is true, how could I be sure that the contract is returning a proper value? Do I need to store somewhere the transaction hash that invoked set and then see how many confirmations it had? Or does a better solution exist?


1 Answer 1


Ethereum theoretically approaches finality in less time than Bitcoin, due to the GHOST protocol. You'd generally wait for 12 confirmations (approx. 3 mins) before you can be sure that the transaction which invoked set(x) is included into the blockchain.

The longer you wait, the higher the likelihood that a transaction will remain forever in the chain and a conflicting transaction (i.e. double spend) will not be included. For a more detailed explanation see here.

So to be sure that your set(500) was 'registered'... waiting is the key.

  • Thank you for the answer. I understand that, but I do not understand how one can be sure of the current state of the contract. Say I have no idea that someone called set(500). I call contractInstance.get() on geth. How could I be sure that the value returned is "confirmed"? Maybe the call to the function will return 500. But maybe, later, as I said, the block will be orphaned, and calling get() after that will return 0.
    – Léo Vital
    Nov 9, 2017 at 20:32
  • Contract state is determined by the transactions within the blocks on the heaviest chain. These transactions are executed by every node and that current 'state' of the contract is deducted. When you say 'maybe later', you need to understand that when every second ticks by, the likelihood of a transaction being deemed void by a competing block gets less and less. So much so that the probability spirals towards zero (never actually reaching it).
    – Malone
    Nov 9, 2017 at 20:58
  • @LéoVital If you're talking about securing your contract so that only you or a predefined number of people can invoke functions, then check this out solidity.readthedocs.io/en/develop/….
    – Malone
    Nov 9, 2017 at 20:58

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.