0
0
Blockchain / Solidityprogramming~30 mins

Ethereum Virtual Machine (EVM) in Blockchain / Solidity - Mini Project: Build & Apply

Choose your learning style9 modes available
Understanding Ethereum Virtual Machine (EVM) Basics
📖 Scenario: You are learning how the Ethereum Virtual Machine (EVM) executes smart contracts. To understand this, you will create a simple Solidity contract that stores and retrieves a number. This simulates how data is stored and accessed on the blockchain through the EVM.
🎯 Goal: Build a simple Solidity smart contract that stores a number and allows reading it back. This will help you understand how the EVM handles contract storage and function calls.
📋 What You'll Learn
Create a Solidity contract named SimpleStorage
Add a state variable storedNumber of type uint
Add a function storeNumber that takes a uint parameter and saves it to storedNumber
Add a function retrieveNumber that returns the current value of storedNumber
Print the retrieved number after storing it
💡 Why This Matters
🌍 Real World
Smart contracts on Ethereum use the EVM to store and manage data securely and transparently. Understanding how to store and retrieve data is fundamental to building decentralized applications.
💼 Career
Blockchain developers must know how to write Solidity contracts that interact with the EVM. This project builds foundational skills for creating and testing smart contracts.
Progress0 / 4 steps
1
Create the Solidity contract and state variable
Write a Solidity contract named SimpleStorage. Inside it, declare a state variable called storedNumber of type uint to hold a number.
Blockchain / Solidity
Need a hint?

Use contract SimpleStorage { } to start the contract and uint storedNumber; to declare the variable.

2
Add a function to store a number
Inside the SimpleStorage contract, add a public function named storeNumber that takes a uint parameter called num and assigns it to storedNumber.
Blockchain / Solidity
Need a hint?

Define function storeNumber(uint num) public { storedNumber = num; } inside the contract.

3
Add a function to retrieve the stored number
Add a public view function named retrieveNumber inside SimpleStorage that returns the current value of storedNumber as a uint.
Blockchain / Solidity
Need a hint?

Use function retrieveNumber() public view returns (uint) { return storedNumber; } to read the stored number.

4
Test storing and retrieving a number
Write a script or test code that creates an instance of SimpleStorage, calls storeNumber(42), then calls retrieveNumber() and prints the returned value.
Blockchain / Solidity
Need a hint?

After deploying, call storeNumber(42) then retrieveNumber() to see 42 returned.