Variables, Consts & Immutable
Variables
There are 3 types of variables in Solidity:
local
Declared inside a function.
Not stored on the blockchain.
state
Declared outside a function.
Stored on the blockchain.
global
Provides information about the blockchain.
Example - Variables
Constants
Constants are variables that cannot be modified
Their value is hard coded into the bytecode of the contract
Using constants can save gas cost
Example - Constants
Immutable
Immutable variables are like constants
Values of immutable variables can be set inside the
constructor
but cannot be modified afterwards
Example - Immutable
Last updated