Constant, View, and Pure in Solidity
purefor functions: Disallows modifition or access of state - this is not enforeced yet.
viewfor functions: Disallow modifition of state - this is not enforced yet.
payablefor functions: Allows them to receive Ether together with a call.
constantfor state variables: Disallow assignment (except initialization), does not occupy storage slot.
anonymousefor events: Does not store event signature as topic(indexable).
indexedfor event parameters: Stores the parameter as topic(indexable).
Q: Solidity 0.4.16 introduced the
constantfunction modifiers. The documentation says:
constant for functions: Same as view
Does this mean
viewis just an alias for
Answer: This is discussed here
viewis 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
receiveether and can only call other
pureis 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
receiveether, cannot use
blockand can only call other
constantis invalid on functions
constanton any variable means it cannot be modified (and could be placed into memory or bytecode by the optimiser)