I have a few questions about non state changing smart contract functions.

Say I have a smart contract deployed with a function that takes an input "num" and returns a value 10 * num. I presume this costs gas, but how is this function executed? Is it executed by a node/client like geth?

State doesn't change but is there a record of this transaction recorded on the blockchain?


There are two ways to access blockchain functionality: calls and transactions. Calls only access the node you use and the blockchain itself is not consulted at all. Also no state changes. Transactions can change state and are recorded to the actual blockchain.

So if you query a view or pure function it's a local call to your node and you get the result immediately. Note that it's also possible to use such functions in a transaction but then it costs gas, even if it wouldn't change state.

  • So if I want to query a smart contract function do you need to run your own node? Then the computation and resources used come from your own node?
    – Peck3277
    Nov 19 '20 at 13:30
  • 1
    You can either use your own node or use some external node provider, such as Infura. But yes, then the computation comes from the node. Of course the node needs to be synchronized with the blockchain to have the data to query for. Nov 19 '20 at 14:01

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.