August 2019
Intermediate to advanced
486 pages
13h 52m
English
Solidity supports the constant keyword for state variables and functions. The state variables that are defined as constant will have their values assigned at compile time and will not allow for any modifications at runtime. You cannot use blockchain data or block information such as now, msg.value, block.number, or msg.sender to assign constant state variables. However, you can use other built-in functions, such as keccak256, ecrecover, and sha256.
The following is the example contract defining constants:
contract ConstantExample { string public constant symbol = "TKN"; uint public constant totalSupply = 10 ** 9; bytes32 public constant hash = keccak256(symbol);}
You could also use the constant keyword for ...