1/5
In this lesson, we will continue to develop our smart contract which stores favorite numbers. Let's take a look at what we have done so far. We have created a new type called a **struct**, called **Person**, which has two variables: - **favorite_number**: A public variable to store our favorite number - **name**: A public string variable to store a name We have defined several state variables: - **my_name**: A string which stores our name. - **my_favorite_number**: A public variable to store our favorite number. - **list_of_numbers**: A public list that will store a list of favorite numbers. - **list_of_people**: A public list that will store a list of people. - **index**: A public integer that will track the size of our lists. - **name_to_favorite_number**: A public hashmap that will store a name and a favorite number as a key value pair. The **constructor** function is used to initialize the state variables. In our example, we will set the **my_favorite_number** to 7 and the **index** to 0. We will also set **my_name** to "Patrick". We also have two functions, a **store** function to set our favorite number and a **retrieve** function to retrieve our favorite number. Here is the code we have written so far: ```python # pragma version ^0.4.0 # @license MIT struct Person: favorite_number: uint256 name: String[100] my_name: public(String[100]) my_favorite_number: public(uint256) = 7 list_of_numbers: public(uint256[5]) = [0, 0, 0, 0, 0] list_of_people: public(Person[5]) index: public(uint256) name_to_favorite_number: public(HashMap[String[100], uint256]) @deploy def __init__(): self.my_favorite_number = 7 self.index = 0 self.my_name = "Patrick!" @external def store(new_number: uint256): self.my_favorite_number = new_number @external @view def retrieve() -> uint256: return self.my_favorite_number ``` In the next lesson, we will deploy our smart contract and test it.
A comprehensive guide to deploying a Vyper smart contract - This lesson will cover how to deploy a smart contract that stores favorite numbers and names of people. It also discusses the concept of state variables, constructors, and using the Remix IDE to deploy the contract.
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)
Web3 engineer, educator, and Cyfrin co-founder. Patrick's smart contract development and security courses have helped hundreds of thousands of engineers kickstarting their careers into web3.
Last updated on March 21, 2025
Duration: 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)
Web3 engineer, educator, and Cyfrin co-founder. Patrick's smart contract development and security courses have helped hundreds of thousands of engineers kickstarting their careers into web3.
Last updated on March 21, 2025
Testimonials
Read what our students have to say about this course.
Chainlink
Chainlink
Gustavo Gonzalez
Solutions Engineer at OpenZeppelin
Francesco Andreoli
Lead Devrel at Metamask
Albert Hu
DeForm Founding Engineer
Radek
Senior Developer Advocate at Ceramic
Boidushya
WalletConnect
Idris
Developer Relations Engineer at Axelar