Functions
an informal syntax of function declaration can defined as:
function <identifier> ( <ty> <identifier> ) <modifiers> return <return decl> { ... }
<modifiers> := <visibility> <mutability?> <inheritance modifier?> <custom modifier*>
<visibility> := public | external | internal | private
<mutability> := view | pure | payable
<inheritance modifier> := virtual | override
<custom modifier> := <identifier>where:
<x*>indicates zero or more<x?>indicates optional<x+>indicates one ore more
Visibility (aka. Function types)
Function types define the visibility of a function
public- anyone can accessexternal- cannot be accessed internally, only externallyinternal- only this contract and the contract that inherit this contractprivate- can be accessed only from this contract
Note
The visibility flag is optional at and before solidity
0.7and default topublicif not explicitly stated.
Mutability
purefunction declares only pure computation is involved, no state variable will be read or written.viewfunction is readonly over state variablenon-payableis default mutability (can’t be explicitly stated), can read and modify the state variablepayablefunction means it can receive ether, beside the state variable, it can also access the global variables (e.g.msg).