Skip to main content
2 of 4
edited title
Ba5t14n
  • 213
  • 2
  • 5

When do I need transactions to call a contract?

Since reading on the Blockchain does not need performance on other nodes, I wonder how I get values from a Smart Contract without any transactions. Therefore, I have created a little example Contract:

Contract Test {
    uint x;

    function Test() { //to init the contract I definately need a transaction
        x = 0;
    }
    
    function inc() returns (uint) { //here I need a transaction too since I change the value
        x = x + 1;
        return x;
    }

    function get() returns (uint) { //I am not sure what is about this function
        return x;
    }
}

I do not know if the code is correct, but I hope you will get my point, I just have an understanding problem here I think and raised some questions:

  • Which functions need a transaction to trigger?
  • Do I even need a function to get a value from a smart Contract when I am a full node? Couldn't I just ... read it?
  • What happens when inc() is called with a transaction but not inserted in a Block and I read an old value? Is this an important point or can it be ignored?
  • When do I get a/the return value? Instantly or when the transaction in placed in a block?

I appreciate any answers :)

Ba5t14n
  • 213
  • 2
  • 5