Constants and Immutables
Gas-efficient values.
Fixed Values Save Gas
Some values never change after a contract is deployed. For these, Solidity offers constant and immutable keywords that store the value in the contract bytecode instead of expensive storage slots.
Using them reduces gas and signals intent to readers.
Declaring Constants
A constant must be assigned at the point of declaration and known at compile time. Its value can never change.
By convention constants use UPPER_CASE names.
<code>uint256 public constant MAX_SUPPLY = 1000000;
string public constant NAME = 'MyToken';</code>All lessons in this course
- Value Types
- Reference Types
- Storage vs Memory
- Constants and Immutables