Back
Lesson 3:
Constants
Introduction to Solidity constants
Visit desktop version for better experiences.
Constants
Constants are variables that cannot be modified. Constants should be named with all capital letters with underscores separating words. Examples: MAX_BLOCKS
, TOKEN_NAME
, TOKEN_TICKER
, CONTRACT_VERSION
.
Their value is hard coded and using constants can save gas cost.
// SPDX-License-Identifier: MITpragma solidity ^0.8.24;
contract Constants {
// coding convention to uppercase constant variablesaddress public constant MY_ADDRESS =
0x777788889999AaAAbBbbCcccddDdeeeEfFFfCcCc;
uint256 public constant MY_UINT = 123;
}