constant and immutable
Use constant and immutable variables for variable that don't change
Using the
constant
and theimmutable
keywords for variables that do not change helps to save ongas
used.The reason been that
constant
andimmutable
variables do not occupy a storage slot when compiled. They are saved inside the contract byte code.
Summary
For constant variables, the value has to be fixed at compile-time,
For immutable, it can still be assigned at construction time.
immutable
is one of the easiest gas optimizations that can be made, and at the same time very effective.
Last updated