Gas Optimization in Solidity
Gas Optimization in Solidity
Gas Optimization in Solidity
Constant Variables
A constant variable is one whose value is assigned at
Key Features
// Without constant
// With constant
Gas Savings:
Naming Convention:
Immutable Variables
An immutable variable is one that is assigned once during
Key Features
conditions.
runtime inputs.
Example:
// Without immutable
address public owner;
// With immutable
constructor() {
Gas Savings:
Naming Convention:
contract’s bytecode.
● Constant: Compile-time
Feature: Flexibility
● Constant: Fixed values only
owner)
TOKEN_NAME, TOKEN_DECIMALS)
Example:
Example:
constructor(address _admin) {
i_admin = _admin;
2. Security:
● Prevent accidental modifications by enforcing
immutability.
3. Code Clarity:
Conclusion
In Solidity, using constant and immutable is a best practice
Further Exploration
Experiment with these keywords in your contracts and