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

Module Five

📖 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.
6
Module Five · Blockchain and Smart Contract Development

🧪 Module Five · Testing and Deployment


📖 Module Introduction

Hello, future blockchain developer! In Module Four, we learned advanced Solidity concepts like mappings, events, inheritance, modifiers, and error handling. We built more complex contracts like tokens and voting systems. Now it is time to learn how to test and deploy your smart contracts.

Testing ensures your contract works correctly and is secure. Deployment puts your contract on the blockchain so others can use it. In this module, we will learn how to test contracts using Hardhat and deploy them to test networks like Sepolia. By the end of this module, you will be able to deploy your own smart contracts.

🎯 Learning Objectives

  • Understand why testing is important.
  • Learn about Hardhat and how to set it up.
  • Write simple tests for smart contracts.
  • Learn about test networks (testnets).
  • Deploy a smart contract to a testnet.

📚 Warm-up Story · Ada's Successful Deployment

Ada is a developer in Lagos. She had written a smart contract for a token. She wanted to share it with her friends. But first, she needed to test it and deploy it.

She used Hardhat to test her contract. She wrote tests to check every function. She made sure everything worked. Then she deployed her contract to the Sepolia testnet. She shared the address with her friends. They could interact with her token. Ada was proud of her first deployed contract.

🧩 Main Lessons

Lesson 1 · Why Test?

Definition: Testing is the process of checking if your smart contract works as expected.

Why important: Testing catches bugs and prevents security issues.

Simple explanation: Like checking your work before submitting it.

Real-life example: A developer tests a contract before deploying.

School example: A student checks their homework before submitting.

Home example: A family tests a recipe before serving.

Nigerian example: A Nigerian developer tests contracts before launch.

Illustration:

    +----------------------+
    |  Testing =           |
    |  Check before        |
    |  deploying           |
    |  → Catch bugs       |
    |  → Ensure security  |
    +----------------------+
            

Mini summary: Testing ensures your contract works correctly.


Lesson 2 · What is Hardhat?

Definition: Hardhat is a development environment for Ethereum. It helps you compile, test, and deploy smart contracts.

Why important: Hardhat is one of the most popular tools for smart contract development.

Simple explanation: Like a workshop for building and testing contracts.

Real-life example: A developer uses Hardhat to test contracts.

School example: A student uses Hardhat for a project.

Home example: A hobbyist uses Hardhat to learn.

Nigerian example: A Nigerian developer uses Hardhat for dApps.

Illustration:

    Hardhat:
    🔨 Compile
    🧪 Test
    🚀 Deploy
            

Mini summary: Hardhat is a tool for developing smart contracts.


Lesson 3 · Setting Up Hardhat

Definition: Setting up Hardhat involves installing it and creating a project.

Why important: You need Hardhat to test and deploy contracts.

Simple explanation: Like installing a game before playing.

Real-life example: A developer runs npm install --save-dev hardhat.

School example: A student sets up Hardhat for a project.

Home example: A hobbyist installs Hardhat.

Nigerian example: A Nigerian developer sets up Hardhat.

Illustration:

    npm init -y
    npm install --save-dev hardhat
    npx hardhat
            

Mini summary: Set up Hardhat to start developing.


Lesson 4 · Writing Tests

Definition: Tests are code that checks if your contract functions work correctly.

Why important: Tests give you confidence that your contract is safe.

Simple explanation: Like checking if a button works.

Real-life example: A test for a transfer function.

School example: A student tests a function.

Home example: A family tests a new appliance.

Nigerian example: A developer tests a token contract.

Illustration:

    describe("Token", function () {
        it("Should transfer tokens", async function () {
            // Test code
        });
    });
            

Mini summary: Tests check if your contract works correctly.


Lesson 5 · Test Networks (Testnets)

Definition: Testnets are blockchain networks used for testing without real money.

Why important: You can deploy and test for free.

Simple explanation: Like a practice version of the blockchain.

Real-life example: Sepolia is a testnet.

School example: A student uses a testnet for practice.

Home example: A family uses a testnet to learn.

Nigerian example: A developer deploys to Sepolia.

Illustration:

    Testnets:
    🔵 Sepolia
    🔵 Goerli
    🔵 Rinkeby (deprecated)
            

Mini summary: Testnets are free environments for testing.


Lesson 6 · Deploying a Contract

Definition: Deploying means putting your contract on the blockchain.

Why important: Deployment makes your contract available to users.

Simple explanation: Like publishing a website.

Real-life example: A developer deploys a token contract.

School example: A student deploys a project.

Home example: A family deploys a family contract.

Nigerian example: A developer deploys to Sepolia.

Illustration:

    npx hardhat run scripts/deploy.js --network sepolia
            

Mini summary: Deployment puts your contract on the blockchain.


Lesson 7 · Interacting with Deployed Contracts

Definition: After deployment, you can interact with your contract using a wallet or frontend.

Why important: This is how users use your contract.

Simple explanation: Like using an app after it's built.

Real-life example: A user interacts with a token contract.

School example: A student interacts with a deployed contract.

Home example: A family interacts with a contract.

Nigerian example: A user interacts with a Nigerian dApp.

Illustration:

    Interact with Contract:
    1. Connect wallet
    2. Call functions
    3. View data
            

Mini summary: Interaction allows users to use your contract.


Lesson 8 · You Can Deploy Smart Contracts!

Definition: You have learned how to test and deploy smart contracts.

Why important: You can now share your contracts with the world.

Simple explanation: You know how to test and deploy your contracts.

Real-life example: You can deploy a token or voting contract.

School example: You can deploy a project.

Home example: You can deploy a family contract.

Nigerian example: You can deploy a Nigerian dApp.

Illustration:

    +----------------------+
    |  You can deploy      |
    |  Smart Contracts! 🎉 |
    |  → Test with Hardhat |
    |  → Deploy to testnet |
    |  → Interact with it  |
    +----------------------+
            

Mini summary: You are now ready to deploy smart contracts!


📌 Key Vocabulary

  • Testing: Checking if your contract works.
  • Hardhat: A development tool for Ethereum.
  • Testnet: A free blockchain for testing.
  • Deployment: Putting your contract on the blockchain.
  • Interact: Using a deployed contract.
  • Compile: Converting code to bytecode.
  • Script: A file that performs a task.
  • Network: A blockchain network (mainnet, testnet).
  • Wallet: A tool to interact with the blockchain.
  • Frontend: A user interface for a dApp.

🧠 Important Concepts

  • Testing is crucial: It catches bugs and ensures security.
  • Hardhat is a powerful tool: It helps with development.
  • Testnets are free: Use them for testing without spending real money.
  • Deployment makes contracts live: It makes them accessible to users.
  • Interaction allows use: Users can call functions after deployment.

👣 Step-by-Step Explanations

How to Test a Contract in 5 Steps

  1. Install Hardhat: npm install --save-dev hardhat
  2. Create a project: npx hardhat
  3. Write your contract: Add your Solidity code.
  4. Write tests: Create test files in the test folder.
  5. Run tests: npx hardhat test

How to Deploy a Contract in 5 Steps

  1. Write a deploy script: Create a script in the scripts folder.
  2. Compile the contract: npx hardhat compile
  3. Choose a network: Select a testnet like Sepolia.
  4. Run the deploy script: npx hardhat run scripts/deploy.js --network sepolia
  5. Get the address: The contract address is displayed.

Example:

    // test/Token.js
    const { expect } = require("chai");

    describe("Token", function () {
        it("Should deploy and assign initial supply", async function () {
            const Token = await ethers.getContractFactory("Token");
            const token = await Token.deploy(1000);
            await token.deployed();
            expect(await token.totalSupply()).to.equal(1000);
        });
    });
            

🌍 Real-life Examples

  • Testing: A developer tests a token contract.
  • Hardhat: Used by many developers.
  • Testnet: Sepolia is a popular testnet.
  • Deployment: A contract is deployed to Sepolia.
  • Interaction: Users interact with the contract.

🇳🇬 Nigerian Examples

  • Testing: A Nigerian developer tests a contract.
  • Hardhat: Used by Nigerian developers.
  • Testnet: Sepolia is used in Nigeria.
  • Deployment: A contract is deployed to Sepolia.
  • Interaction: Users interact with the contract.

🎈 Fun Examples children can relate to

  • Testing: Checking a toy before playing.
  • Hardhat: A workshop for building.
  • Testnet: A practice playground.
  • Deployment: Putting a toy on a shelf.
  • Interaction: Playing with a toy.

🏠 Everyday Examples

  • Testing: Trying a recipe before serving.
  • Hardhat: A kitchen for cooking.
  • Testnet: A practice kitchen.
  • Deployment: Serving a meal.
  • Interaction: Eating the meal.

👩‍🏫 Teacher Notes

  • Encourage students to test their contracts.
  • Demonstrate Hardhat setup and testing.
  • Show how to deploy to a testnet.
  • Celebrate their first deployment.
  • Emphasise the importance of testing.

👪 Parent Tips

  • Encourage your child to test and deploy.
  • Help them understand the importance of testing.
  • Celebrate their first deployment.
  • Make learning about blockchain fun.
  • Support their progress.

🧐 Interesting Facts

  • Hardhat is used by thousands of developers.
  • Testnets are free to use.
  • Deploying to a testnet costs no real money.
  • Testing is a standard practice in software development.
  • Many projects are tested on testnets before mainnet.

💡 Did You Know?

  • Did you know that Hardhat was created in 2020?
  • Did you know that Sepolia is one of the most popular testnets?
  • Did you know that testing can prevent costly bugs?
  • Did you know that deployment is irreversible?
  • Did you know that many developers deploy to testnets first?

🧷 Remember This

  • Testing is crucial.
  • Hardhat is a powerful tool.
  • Testnets are free.
  • Deployment makes contracts live.
  • Interaction allows use.

⚠️ Common Mistakes

  • Not testing: Deploying without testing.
  • Using wrong network: Deploying to mainnet by mistake.
  • Incorrect deploy script: Errors in the script.
  • Not saving the address: Losing the contract address.
  • Not verifying: Not verifying the contract on Etherscan.

✅ Best Practices

  • Test your contract thoroughly.
  • Use Hardhat for development.
  • Deploy to a testnet first.
  • Save the contract address.
  • Verify your contract on Etherscan.

🎨 Illustrations, Diagrams & Tables

Hardhat Workflow

    Write Contract → Compile → Test → Deploy → Interact
            

Testnet vs Mainnet

TestnetMainnet
Free to useCosts real money
For testingFor production
No real valueReal value

Deploy Script Example

    const hre = require("hardhat");

    async function main() {
        const Token = await hre.ethers.getContractFactory("Token");
        const token = await Token.deploy(1000);
        await token.deployed();
        console.log("Token deployed to:", token.address);
    }

    main().catch((error) => {
        console.error(error);
        process.exitCode = 1;
    });
            

📝 End-of-Module Summary

In this module, we learned about testing and deploying smart contracts. We discovered that testing is crucial for catching bugs and ensuring security. We learned about Hardhat, testnets, and how to deploy a contract to a testnet. With this knowledge, you can now test and deploy your own smart contracts. Great job!

❓ Frequently Asked Questions (10)

  1. Why test? To catch bugs.
  2. What is Hardhat? A development tool.
  3. What is a testnet? A free blockchain for testing.
  4. What is deployment? Putting a contract on the blockchain.
  5. What is interaction? Using a deployed contract.
  6. What is compile? Converting code to bytecode.
  7. What is a script? A file that performs a task.
  8. What is a network? A blockchain network.
  9. What is a wallet? A tool to interact with the blockchain.
  10. What is a frontend? A user interface.

📋 Review Questions (15)

  1. Why is testing important?
  2. What is Hardhat?
  3. What is a testnet?
  4. What is deployment?
  5. What is interaction?
  6. What is compile?
  7. What is a script?
  8. What is a network?
  9. What is a wallet?
  10. What is a frontend?
  11. How do you test a contract?
  12. How do you deploy a contract?
  13. What is the difference between testnet and mainnet?
  14. What is the first step in testing?
  15. What is the most important thing about testing?

✏️ Fill-in-the-Blank Exercises

  1. ______________ is the process of checking if your contract works. (Testing)
  2. ______________ is a development tool for Ethereum. (Hardhat)
  3. A ______________ is a free blockchain for testing. (testnet)
  4. ______________ puts your contract on the blockchain. (Deployment)
  5. ______________ allows users to use your contract. (Interaction)

✅ True or False Exercises

  1. Testing is not important. (False)
  2. Hardhat is a development tool. (True)
  3. Testnets cost real money. (False)
  4. Deployment puts your contract on the blockchain. (True)
  5. Interaction is not needed. (False)

🔘 Multiple Choice Questions (15)

  1. Why is testing important?
    a) To catch bugs ✅
    b) To make it slower
    c) To avoid it
  2. What is Hardhat?
    a) A development tool ✅
    b) A testnet
    c) A wallet
  3. What is a testnet?
    a) A free blockchain for testing ✅
    b) A mainnet
    c) A wallet
  4. What is deployment?
    a) Putting a contract on the blockchain ✅
    b) Testing a contract
    c) Writing a contract
  5. What is interaction?
    a) Using a deployed contract ✅
    b) Testing a contract
    c) Writing a contract
  6. What is compile?
    a) Converting code to bytecode ✅
    b) Testing a contract
    c) Writing a contract
  7. What is a script?
    a) A file that performs a task ✅
    b) A testnet
    c) A wallet
  8. What is a network?
    a) A blockchain network ✅
    b) A testnet
    c) A wallet
  9. What is a wallet?
    a) A tool to interact with the blockchain ✅
    b) A testnet
    c) A script
  10. What is a frontend?
    a) A user interface ✅
    b) A testnet
    c) A script
  11. How do you test a contract?
    a) Use Hardhat test ✅
    b) Deploy to mainnet
    c) Skip it
  12. How do you deploy a contract?
    a) Use Hardhat deploy ✅
    b) Skip it
    c) Test it
  13. What is the difference between testnet and mainnet?
    a) Testnet is free, mainnet is real ✅
    b) Testnet is real, mainnet is free
    c) They are the same
  14. What is the first step in testing?
    a) Install Hardhat ✅
    b) Deploy
    c) Interact
  15. What is the most important thing about testing?
    a) It catches bugs ✅
    b) It is optional
    c) It is slow

🔗 Matching Exercises

Match the word with its meaning:

WordMeaning
1. TestingA) A development tool
2. HardhatB) Free blockchain for testing
3. TestnetC) Putting a contract on the blockchain
4. DeploymentD) Checking if your contract works
5. InteractionE) Using a deployed contract

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

📝 Short Answer Questions

  1. Why is testing important?
  2. What is the difference between a testnet and mainnet?
  3. How do you deploy a contract using Hardhat?

🎭 Scenario-based Exercises

Scenario 1: You have written a smart contract. Before deploying, what should you do?

Scenario 2: You want to deploy your contract without spending real money. What would you do?

👥 Group Activity

In groups of 3, set up Hardhat and deploy a simple contract to a testnet. Share the contract address.

🧑‍🎓 Individual Activity

Write a simple contract, test it with Hardhat, and deploy it to Sepolia. Record the contract address.

🗣️ Classroom Discussion Questions

  • What is the most challenging part of testing?
  • Why is deployment to a testnet a good practice?
  • What would you like to deploy next?

🛠️ Mini Project

Deploy a simple token contract to Sepolia. Test it using Hardhat. Share the contract address with the class.

📁 Practical Assignment

Write a test for a simple contract. Run the test and share the results.

🏆 Challenge Exercise

Deploy a voting contract to Sepolia. Write tests for the contract. Share the address and test results.

🔑 Quiz Answers

Fill-in-the-blank: 1-Testing, 2-Hardhat, 3-testnet, 4-Deployment, 5-Interaction

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

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

🎁 Key Takeaways

  • Testing is crucial.
  • Hardhat is a powerful tool.
  • Testnets are free.
  • Deployment makes contracts live.
  • Interaction allows use.

🚀 Preparation for the next module

In Module Six, we will learn about building dApps — connecting your smart contract to a frontend. We will use ethers.js and React to build a complete dApp. Before the next session, think about how you would like your dApp to look.

See you in Module Six! 🎉


End of Module Five · Testing and Deployment

🏆 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.
→