Constant, View, and Pure in Solidity


  • pure for functions: Disallows modifition or access of state - this is not enforeced yet.

  • view for functions: Disallow modifition of state - this is not enforced yet.

  • payable for functions: Allows them to receive Ether together with a call.

  • constant for state variables: Disallow assignment (except initialization), does not occupy storage slot.

  • anonymouse for events: Does not store event signature as topic(indexable).

  • indexed for event parameters: Stores the parameter as topic(indexable).


Q: Solidity 0.4.16 introduced the view and constant function modifiers. The documentation says:

constant for functions: Same as view

Does this mean view is just an alias for constant?

Answer: This is discussed here

  1. The keyword view is introduced for functions (it replaces constant). Calling a view cannot alter the behavior of future interaction with any contract. This means such functions cannot use SSTORE, cannot send or receive ether and can only call other view or pure functions.

  2. The keyword pure is introduced for functions, they are view functions with the additional restriction that their value only depends on the function arguments(pure function). This means they cannot use SSTORE, SLOAD, cannot send or receive ether, cannot use msg or block and can only call other pure function.

  3. The keyword constant is invalid on functions

  4. The keyword constant on any variable means it cannot be modified (and could be placed into memory or bytecode by the optimiser)


Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now