Skip to main content
deleted 106 characters in body; edited tags
Source Link
eth
  • 86.5k
  • 53
  • 287
  • 411

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

Contractcontract Test {
    uint x;

    function Test() { //to init the contract I definatelydefinitely 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 getwant to check my point, I just have an understanding problem here I think and raisedhave 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 :)

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 :)

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

contract Test {
    uint x;

    function Test() { //to init the contract I definitely 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 want to check my understanding and have 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 :)

edited title
Link
Ba5t14n
  • 213
  • 2
  • 5

Reading values from a contract: When do I need transactions to call a contract?

edited title
Link
Ba5t14n
  • 213
  • 2
  • 5

When do I need transactions to call a contract?

Source Link
Ba5t14n
  • 213
  • 2
  • 5
Loading