1/5
## Immutables & Constants We'll learn about immutables and constants. Immutables are a way to declare values that we know won't change once a contract is deployed. They help improve the readability and gas efficiency of our code. Let's look at an example. Imagine we have an owner for our contract, and we know this owner will never change within the contract. We can use a constant to represent this value. First, let's declare the `owner` variable as a public address: ```python owner: public(address); ``` Now, we want to set this value in the constructor of the contract. Using the keyword `constant`, we need to initialize it with a value: ```python owner: public(constant(address)) = msg.sender ``` Notice that we can't assign a value to a constant within the constructor. Instead, we need to assign it at compile time. So, we can change the code to: ```python OWNER: public(constant(address)) = msg.sender ``` Here, we are assigning a value to a constant, which is the `msg.sender` address at compile time. We will cover constants in more detail in the following lessons.
A detailed guide to utilizing Immutables and Constants in Vyper smart contracts. This lesson dives into the concepts behind immutables and constants, explaining their differences and showcasing how to leverage them for improved code readability and gas efficiency.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Course Overview
About the course
The basics of blockchain transactions, how to send and receive money on a blockchain network.
How to write Python based smart contracts using Vyper.
How to read and understand Vyper smart contracts.
Vyper data structures, arrays, structs, hash maps.
How to build a smart contract application and deploy on ZKsync with Moccasin.
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on May 15, 2025
Vyper Developer
Introduction to Python and VyperDuration: 2h 08min
Duration: 2h 32min
Duration: 24min
Course Overview
About the course
The basics of blockchain transactions, how to send and receive money on a blockchain network.
How to write Python based smart contracts using Vyper.
How to read and understand Vyper smart contracts.
Vyper data structures, arrays, structs, hash maps.
How to build a smart contract application and deploy on ZKsync with Moccasin.
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
On-chain Data Analyst
$59,000 - $139,000 (avg. salary)
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Last updated on May 15, 2025