Back

Lesson 4:
Immutable

Introduction to immutable keyword in Vyper

Progress: 0%

Visit desktop version for better experiences.

Immutable

Immutable variables are similar to constants, except the value must be defined in the constructor of the contract. Declare immutable variables if you want a variable to remain constant throughout the lifetime of a deployed contract.

Accessing an immutable variable reduces runtime gas costs in comparison with constant variables.

# pragma version 0.4.0 IMMUTABLE_INT: immutable(uint256) IMMUTABLE_ADDR: immutable(address) @deploy def __init__(): IMMUTABLE_INT = 999 IMMUTABLE_ADDR = 0xE2b4795039517653c5Ae8C2A9BFdd783b48f447A @external @view def retrieveImmutables() -> (uint256, address): return (IMMUTABLE_INT, IMMUTABLE_ADDR)
Vyper Differentiators
  • Immutable variables cannot have any initial values.

Further Reading:

© 2025 Scroll Foundation | All rights reserved

Terms of UsePrivacy Policy