Accordingly to the solidity documentations, functions can be declared as view:

in which case they promise not to modify the state.

or they can be declared as pure

in which case they promise not to read from or modify the state.

But what is the importance of declaring functions with one of this two states and why not just omit it?


1 Answer 1

  • Pure means that the function effectively runs in isolation and only operates on the variables that have been passed to it.
  • View functions won't modify the state but can read from anywhere.
  • Unspecified functions can both modify and read from the blockchain state.

Its very similar to the use of public and private variables in C++/C# or Java classes - just modified for the concept of a blockchain. In this case all operations occur around the chain state - so it makes sense to have modifiers which describe how they interact with that state.

That could be useful for determining things like if your node syncs using the light sync option whether or not to get a chainstate update from a full node.(Pure functions would be guaranteed not to touch or need state so no update needed).

It could also become a basis for determining gas prices in the future - my guess would be that pure functions would cost the lowest amount of gas in that scenario.

Not the answer you're looking for? Browse other questions tagged or ask your own question.