Hiring Partners
Segilola Resources Operating LimitedTaviatech TechnologiesFCMBMTN NigeriaAdvans La Fayette Microfinance BankAboki AfricaFirst Bank of NigeriaOPay
← Blockchain & Smart Contact Development · Lesson 4 of 7

Module Three

📖 Every lesson in this course is free to read right here, no account needed. Create a free account to track your progress, take the exam, and earn your certificate.
4
Module Three · Blockchain and Smart Contract Development

💻 Module Three · Solidity Basics


📖 Module Introduction

Hello, future blockchain developer! In Module Two, we learned about Ethereum and smart contracts. We learned how Ethereum works and why smart contracts are powerful. Now it is time to learn how to write smart contracts using Solidity.

Solidity is the programming language used to write smart contracts on Ethereum. It is designed to be easy to learn and powerful enough to build complex applications. In this module, we will learn the basics of Solidity — data types, variables, functions, and more. By the end of this module, you will be able to write your first smart contract.

🎯 Learning Objectives

  • Understand what Solidity is and why it is used.
  • Learn the basic structure of a Solidity contract.
  • Learn about data types: uint, string, bool, and address.
  • Learn about variables and functions.
  • Write and deploy a simple "Hello World" smart contract.

📚 Warm-up Story · Chidi's First Contract

Chidi is a young developer in Lagos. He wanted to write his first smart contract. He opened Remix, an online tool for writing Solidity. He wrote a simple contract that stored a message. He deployed it to a test network. He was amazed when it worked.

His contract was simple: it stored a string and allowed anyone to read it. It was like a digital notice board. Chidi learned that Solidity is not as hard as he thought. He continued to learn and eventually built more complex contracts.

🧩 Main Lessons

Lesson 1 · What is Solidity?

Definition: Solidity is a programming language used to write smart contracts for Ethereum and other blockchain platforms.

Why important: Solidity is the most popular language for smart contract development.

Simple explanation: Solidity is the language you use to tell the blockchain what your smart contract should do.

Real-life example: A developer writes a smart contract for a token.

School example: A student writes a contract for a class project.

Home example: A hobbyist writes a contract for a game.

Nigerian example: A Nigerian developer writes a contract for a DeFi app.

Illustration:

    +----------------------+
    |  Solidity =          |
    |  Language for        |
    |  smart contracts     |
    |  → Ethereum          |
    |  → dApps            |
    +----------------------+
            

Mini summary: Solidity is the language for writing smart contracts.


Lesson 2 · Contract Structure

Definition: A Solidity contract is a collection of code (functions and data) that lives on the blockchain.

Why important: Every smart contract starts with a structure.

Simple explanation: Like a blueprint for a house.

Real-life example: A contract for a token.

School example: A contract for a class record.

Home example: A contract for a family agreement.

Nigerian example: A contract for a land registry.

Illustration:

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;

    contract MyContract {
        // Code goes here
    }
            

Mini summary: A contract is the basic building block of Solidity.


Lesson 3 · Pragma

Definition: Pragma is a statement that tells the compiler which version of Solidity to use.

Why important: It ensures your contract works with the right version.

Simple explanation: Like saying "Use this version of the language."

Real-life example: pragma solidity ^0.8.0;

School example: A student specifies the version for their project.

Home example: A family uses a specific recipe version.

Nigerian example: A developer specifies the version for their contract.

Illustration:

    pragma solidity ^0.8.0;
            

Mini summary: Pragma specifies the Solidity version.


Lesson 4 · Data Types

Definition: Data types define the kind of data you can store in a variable. Common types are uint, string, bool, and address.

Why important: You need to know what type of data you are working with.

Simple explanation: Like different containers for different things.

Real-life example: uint for numbers, string for text.

School example: A student uses uint for grades.

Home example: A parent uses string for names.

Nigerian example: A developer uses address for wallet addresses.

Illustration:

    uint: 100
    string: "Hello"
    bool: true
    address: 0x123...
            

Mini summary: Data types define the kind of data you store.


Lesson 5 · Variables

Definition: Variables are containers that store data. In Solidity, you can have state variables (stored on the blockchain) and local variables (temporary).

Why important: Variables store the data your contract needs.

Simple explanation: Like boxes that hold information.

Real-life example: uint public count = 0;

School example: A student stores their name.

Home example: A family stores a message.

Nigerian example: A developer stores a balance.

Illustration:

    uint public count = 0;
    string public message = "Hello";
    address public owner;
            

Mini summary: Variables store data in your contract.


Lesson 6 · Functions

Definition: Functions are blocks of code that perform specific tasks. They can be called by users or other contracts.

Why important: Functions are how you interact with a smart contract.

Simple explanation: Like buttons that do something when pressed.

Real-life example: function setMessage(string memory _message) public { message = _message; }

School example: A function to update a grade.

Home example: A function to add a chore.

Nigerian example: A function to transfer tokens.

Illustration:

    function setMessage(string memory _message) public {
        message = _message;
    }
            

Mini summary: Functions perform actions in your contract.


Lesson 7 · Visibility

Definition: Visibility determines who can call a function or access a variable. The main types are public, private, and internal.

Why important: It controls access to your contract's data and functions.

Simple explanation: Like who is allowed to enter a room.

Real-life example: public means anyone can call it.

School example: A public function can be used by anyone.

Home example: A private variable is only for the contract.

Nigerian example: A public function for users.

Illustration:

    public: Anyone can call
    private: Only this contract can call
    internal: Only this contract and derived contracts
            

Mini summary: Visibility controls access to functions and variables.


Lesson 8 · Hello World Contract

Definition: The Hello World contract is the simplest smart contract. It stores and returns a message.

Why important: It is the first step in learning Solidity.

Simple explanation: Like writing your first program.

Real-life example: A contract that says "Hello, World!"

School example: A student writes their first contract.

Home example: A family stores a greeting.

Nigerian example: A developer writes a test contract.

Illustration:

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;

    contract HelloWorld {
        string public message = "Hello, World!";
    }
            

Mini summary: Hello World is the simplest smart contract.


Lesson 9 · You Can Write Solidity!

Definition: You have learned the basics of Solidity — data types, variables, functions, and visibility.

Why important: You are now ready to write your own smart contracts.

Simple explanation: You know how to write a simple contract.

Real-life example: You can write a Hello World contract.

School example: You can build a simple project.

Home example: You can store a message on the blockchain.

Nigerian example: You can start building dApps.

Illustration:

    +----------------------+
    |  You can write       |
    |  Solidity! 🎉       |
    |  → Data types       |
    |  → Variables        |
    |  → Functions        |
    |  → Visibility       |
    +----------------------+
            

Mini summary: You are now ready to write Solidity!


📌 Key Vocabulary

  • Solidity: The language for smart contracts.
  • Contract: A collection of code on the blockchain.
  • Pragma: Specifies the Solidity version.
  • Data type: The kind of data stored (uint, string, etc.).
  • Variable: A container for data.
  • Function: A block of code that performs a task.
  • Visibility: Controls access (public, private, internal).
  • uint: Unsigned integer (non-negative number).
  • string: Text data.
  • address: An Ethereum address.

🧠 Important Concepts

  • Solidity is the language: It is used to write smart contracts.
  • Contracts are like blueprints: They define the rules of your application.
  • Data types define data: Use the right type for your data.
  • Functions perform actions: They are how users interact with your contract.
  • Visibility controls access: Keep data safe with proper visibility.

👣 Step-by-Step Explanations

How to Write a Hello World Contract in 5 Steps

  1. Open Remix: Go to remix.ethereum.org.
  2. Create a new file: Click the "+" icon and name it "HelloWorld.sol".
  3. Write the code: Type the contract code.
  4. Compile: Click the Compile button.
  5. Deploy: Click Deploy and interact with your contract.

Example:

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;

    contract HelloWorld {
        string public message = "Hello, World!";
    }
            

🌍 Real-life Examples

  • Solidity: Used to write ERC-20 tokens.
  • Contract: A simple storage contract.
  • Pragma: Specifies the Solidity version.
  • uint: Used for balances.
  • address: Used for wallet addresses.

🇳🇬 Nigerian Examples

  • Solidity: Used by Nigerian developers.
  • Contract: A simple storage contract.
  • Pragma: Specifies the version.
  • uint: Used for balances.
  • address: Used for wallet addresses.

🎈 Fun Examples children can relate to

  • Solidity: A language for digital agreements.
  • Contract: A rule book.
  • Pragma: A version label.
  • uint: A counter.
  • address: A digital mailbox.

🏠 Everyday Examples

  • Solidity: A language for rules.
  • Contract: A rule book.
  • Pragma: A version label.
  • uint: A counter.
  • address: A digital mailbox.

👩‍🏫 Teacher Notes

  • Encourage students to write their first contract.
  • Use Remix for hands-on practice.
  • Explain data types with simple examples.
  • Emphasise the importance of functions.
  • Celebrate their first contract.

👪 Parent Tips

  • Encourage your child to try Solidity.
  • Use Remix together.
  • Help them write a simple contract.
  • Celebrate their progress.
  • Make learning about blockchain fun.

🧐 Interesting Facts

  • Solidity was created by Gavin Wood.
  • Solidity is influenced by C++, Python, and JavaScript.
  • Solidity is the most popular language for smart contracts.
  • Remix is a popular online IDE for Solidity.
  • Smart contracts are written in Solidity and deployed on Ethereum.

💡 Did You Know?

  • Did you know that Solidity is named after the sun?
  • Did you know that Remix is used by thousands of developers?
  • Did you know that smart contracts can store any type of data?
  • Did you know that Solidity is evolving quickly?
  • Did you know that you can deploy contracts for free on test networks?

🧷 Remember This

  • Solidity is the language for smart contracts.
  • Contracts are like blueprints.
  • Data types define the data you store.
  • Functions perform actions.
  • Visibility controls access.

⚠️ Common Mistakes

  • Wrong pragma: Using the wrong version.
  • Incorrect data type: Using the wrong type.
  • Visibility errors: Not setting the right visibility.
  • Missing semicolons: Forgetting to end lines.
  • Not compiling: Forgetting to compile before deploying.

✅ Best Practices

  • Use the latest stable version of Solidity.
  • Use descriptive variable names.
  • Set visibility appropriately.
  • Compile before deploying.
  • Test your contract on a test network.

🎨 Illustrations, Diagrams & Tables

Contract Structure

    // SPDX-License-Identifier: MIT
    pragma solidity ^0.8.0;

    contract MyContract {
        // State variables
        // Functions
    }
            

Data Types

TypeDescription
uintNon-negative integer
stringText
boolTrue/False
addressEthereum address

Visibility

    public: Anyone can call
    private: Only this contract
    internal: This contract and derived
            

📝 End-of-Module Summary

In this module, we learned the basics of Solidity. We discovered that Solidity is the language used to write smart contracts on Ethereum. We learned about the structure of a contract, data types, variables, functions, and visibility. We also wrote a simple "Hello World" contract. With this knowledge, you can now start writing your own smart contracts. Great job!

❓ Frequently Asked Questions (10)

  1. What is Solidity? The language for smart contracts.
  2. What is a contract? A collection of code on the blockchain.
  3. What is pragma? Specifies the Solidity version.
  4. What is uint? A non-negative integer.
  5. What is a function? A block of code that performs a task.
  6. What is visibility? Controls access to functions.
  7. What is the EVM? The environment that runs smart contracts.
  8. What is Remix? An online IDE for Solidity.
  9. What is the first contract to write? Hello World.
  10. Is Solidity hard to learn? No, it is beginner-friendly.

📋 Review Questions (15)

  1. What is Solidity?
  2. What is a contract?
  3. What is pragma?
  4. What are data types?
  5. What is uint?
  6. What is a function?
  7. What is visibility?
  8. What is the EVM?
  9. What is Remix?
  10. What is the first contract to write?
  11. What is the structure of a Solidity contract?
  12. What is the difference between public and private?
  13. What is an address?
  14. What is a string?
  15. How do you deploy a contract?

✏️ Fill-in-the-Blank Exercises

  1. Solidity is the language for ______________. (smart contracts)
  2. A ______________ is a collection of code on the blockchain. (contract)
  3. ______________ specifies the Solidity version. (Pragma)
  4. ______________ is a non-negative integer. (uint)
  5. ______________ performs a task in a contract. (Function)

✅ True or False Exercises

  1. Solidity is used for smart contracts. (True)
  2. Pragma specifies the version of Solidity. (True)
  3. uint can store negative numbers. (False)
  4. Functions perform actions. (True)
  5. Private functions can be called by anyone. (False)

🔘 Multiple Choice Questions (15)

  1. What is Solidity?
    a) A language for smart contracts ✅
    b) A type of blockchain
    c) A wallet
  2. What is a contract?
    a) A collection of code ✅
    b) A type of token
    c) A wallet
  3. What is pragma?
    a) Specifies the version ✅
    b) A data type
    c) A function
  4. What is uint?
    a) A non-negative integer ✅
    b) A string
    c) An address
  5. What is a function?
    a) A block of code ✅
    b) A data type
    c) A variable
  6. What is visibility?
    a) Controls access ✅
    b) A data type
    c) A variable
  7. What is the EVM?
    a) The environment that runs contracts ✅
    b) A language
    c) A wallet
  8. What is Remix?
    a) An online IDE ✅
    b) A blockchain
    c) A token
  9. What is the first contract to write?
    a) Hello World ✅
    b) Token
    c) Wallet
  10. What is the structure of a Solidity contract?
    a) Pragma, contract, functions ✅
    b) Only functions
    c) Only variables
  11. What is the difference between public and private?
    a) Public can be called by anyone ✅
    b) Private can be called by anyone
    c) They are the same
  12. What is an address?
    a) An Ethereum address ✅
    b) A string
    c) A number
  13. What is a string?
    a) Text ✅
    b) A number
    c) An address
  14. How do you deploy a contract?
    a) Using Remix or Hardhat ✅
    b) Using a wallet
    c) Using a bank
  15. Is Solidity beginner-friendly?
    a) Yes ✅
    b) No

🔗 Matching Exercises

Match the word with its meaning:

WordMeaning
1. SolidityA) A non-negative integer
2. uintB) A block of code
3. FunctionC) The language for smart contracts
4. VisibilityD) Controls access
5. PragmaE) Specifies the version

(Answers: 1-C, 2-A, 3-B, 4-D, 5-E)

📝 Short Answer Questions

  1. What is Solidity and why is it used?
  2. What is the structure of a Solidity contract?
  3. Write a simple Hello World contract.

🎭 Scenario-based Exercises

Scenario 1: You want to store a message on the blockchain. What contract would you write?

Scenario 2: You want to create a counter that increments. What functions would you write?

👥 Group Activity

In groups of 3, write a Hello World contract in Remix. Deploy it and test it. Share your experience.

🧑‍🎓 Individual Activity

Write a simple contract that stores and retrieves a message. Deploy it on a test network.

🗣️ Classroom Discussion Questions

  • What was the most challenging part of writing your first contract?
  • How can Solidity be used in real-world applications?
  • What would you like to build with Solidity?

🛠️ Mini Project

Write a contract that stores and updates a message. Add a function to change the message. Deploy it and test it.

📁 Practical Assignment

Write a Hello World contract in Remix. Take a screenshot of the deployed contract and share it.

🏆 Challenge Exercise

Write a contract that stores a number and allows users to increment it. Add a function to reset the number.

🔑 Quiz Answers

Fill-in-the-blank: 1-smart contracts, 2-contract, 3-Pragma, 4-uint, 5-Function

True/False: 1-T, 2-T, 3-F, 4-T, 5-F

Matching: 1-C, 2-A, 3-B, 4-D, 5-E

🎁 Key Takeaways

  • Solidity is the language for smart contracts.
  • Contracts are like blueprints.
  • Data types define the data you store.
  • Functions perform actions.
  • Visibility controls access.

🚀 Preparation for the next module

In Module Four, we will learn advanced Solidity concepts like mappings, events, and inheritance. We will build more complex contracts. Before the next session, think about what you would like your contract to do.

See you in Module Four! 🎉


End of Module Three · Solidity Basics

🏆 Get Certified

🔒

Earn this certificate

Every lesson is already free to read. Sign up, finish the lessons, pass the exam (₦2,000 or 20,000 coins), and get a verified certificate with your name on it.

🎓 Sign Up to Get Certified
🛠️ Practice Tools
Hands-on simulators & labs - subscription required.
→
🎯 Internship Tasks
Real-world tasks to build your portfolio - unlock them with a subscription.
→