0
0
Blockchain / Solidityprogramming~30 mins

Contract structure and syntax in Blockchain / Solidity - Mini Project: Build & Apply

Choose your learning style9 modes available
Basic Smart Contract Structure and Syntax
📖 Scenario: You want to create a simple smart contract on the blockchain that stores a number and allows anyone to read it.
🎯 Goal: Build a basic Solidity contract with a state variable and a function to read it.
📋 What You'll Learn
Create a contract named SimpleStorage
Declare a public unsigned integer variable called storedNumber initialized to 0
Write a function called getNumber that returns the value of storedNumber
Use correct Solidity syntax for contract, variable, and function declarations
💡 Why This Matters
🌍 Real World
Smart contracts are programs that run on blockchains to automate agreements without middlemen.
💼 Career
Understanding contract structure and syntax is essential for blockchain developers building decentralized applications.
Progress0 / 4 steps
1
Create the contract and state variable
Write a Solidity contract named SimpleStorage and declare a public unsigned integer variable called storedNumber initialized to 0.
Blockchain / Solidity
Need a hint?

Start with contract SimpleStorage { } and inside it declare uint public storedNumber = 0;

2
Add a function to read the stored number
Inside the SimpleStorage contract, write a public view function called getNumber that returns a uint and returns the value of storedNumber.
Blockchain / Solidity
Need a hint?

Define function getNumber() public view returns (uint) { return storedNumber; } inside the contract.

3
Add a function to update the stored number
Add a public function called setNumber that takes a uint parameter named newNumber and updates storedNumber with it.
Blockchain / Solidity
Need a hint?

Write function setNumber(uint newNumber) public { storedNumber = newNumber; } inside the contract.

4
Test the contract output
Write a comment that shows the expected output when calling getNumber() after deploying the contract and before calling setNumber. The output should be 0.
Blockchain / Solidity
Need a hint?

Write a comment like // Expected output of getNumber() after deployment: 0 below the contract.