0Pricing
Web3 & DApp Development Fundamentals · Lesson

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

  1. Value Types
  2. Reference Types
  3. Storage vs Memory
  4. Constants and Immutables
← Back to Web3 & DApp Development Fundamentals