Solidity: The pure getter and view functions
Solidity provides two particular types of getter functions: view
and pure
.
The view functions
view
allows the state to be read but does not allow the state to be modified:
uint public a = 1;function viewFunction(uint b) public view returns (uint) {
return a + b;
}
Let’s compile and deploy the contract. Then call the viewFunction()
function:
The result is 3 = 1 + 2.