Summary
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
andconstant
function modifiers. The documentation says:
constant for functions: Same as view
Does this mean
view
is just an alias forconstant
?
Answer: This is discussed here
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 useSSTORE
, cannotsend
orreceive
ether and can only call otherview
orpure
functions.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 useSSTORE
,SLOAD
, cannotsend
orreceive
ether, cannot usemsg
orblock
and can only call otherpure
function.The keyword
constant
is invalid on functionsThe keyword
constant
on any variable means it cannot be modified (and could be placed into memory or bytecode by the optimiser)