Solidity Series

Solidity Programming Language -Pure , View & Simple Function

View: Read is allowed but right is not allowed.

Pure: Read and Write is not allowed for state variables only local variables can read and write.

Simple Function: change the state variable.

Pure Functions:

  • A function marked as “pure” is one that does not read or modify the state of the contract.
  • It does not access any storage variables, and it does not modify the contract’s state.
  • Pure functions are deterministic, meaning they always produce the same output for the same input.

View Functions:

  • A function marked as “view” (formerly “constant” before Solidity version 0.4.17) indicates that it does not modify the state of the contract.
  • It can read the state but cannot change it. View functions are used for reading data from the blockchain without creating a transaction.

Both “pure” and “view” functions are used to indicate that a function does not modify the state of the contract. The difference lies in whether they read the state (view) or not access any state (pure). Use “pure” when your function doesn’t even read from the state, and use “view” when it only reads from the state but doesn’t modify it.

Hi, I’m saksham dixit

Leave a Reply

Your email address will not be published. Required fields are marked *