Duration: 1 hour
Difficulty: Beginner
Alignment: Course Objectives 1 & 6 (Understand blockchain principles; Build a basic prototype/dApp)
Prerequisites: Basic Python knowledge, ability to install browser extensions, internet connection
- Install Python (if not installed): https://python.org/downloads
- Run the simulation:
python simple_blockchain.py
- Observe Output:
- Note how each block's
hashdepends onprevious_hash - Notice the
is_valid()function returnsFalseafter tampering
- Note how each block's
- Experiment:
- Change
bc.add_block("Vote: YES")to your name + a short message - Re-run and observe how the hash chain updates automatically
- Change
- Concept Check:
- Why does changing one block break the chain?
- How does this relate to immutability in real blockchains?
- Install MetaMask: https://metamask.io/download/
- Create a wallet (save recovery phrase securely)
- Switch network to Sepolia Testnet
- Get Test ETH:
- Visit: https://sepoliafaucet.com/ or https://faucets.chain.link/sepolia
- Paste your MetaMask address and request free test ETH
- Open Remix IDE: https://remix.ethereum.org/
- Create a new file:
SimplePoll.sol - Paste the Solidity code provided above
- Click Solidity Compiler β Select
0.8.20(or compatible) β Click Compile
- Create a new file:
- Deploy:
- Go to Deploy & Run Transactions
- Environment: Select
Injected Provider - MetaMask - Confirm connection in MetaMask
- Click Deploy β Approve transaction in MetaMask
- Interact:
- In the deployed contract panel, expand
createPoll - Input:
_question: "Should we adopt blockchain in our campus?" _options: ["Yes", "No"]β Clicktransact- Wait for confirmation (~15 secs)
- Expand
voteβ Input_pollId: 0,_optionIndex: 0β Clicktransact - Repeat vote with index
1 - Expand
getPollβ Input0β Click call to view results
- In the deployed contract panel, expand
- Verify on Etherscan:
- Copy contract address from Remix
- Paste into: https://sepolia.etherscan.io/
- View transaction hashes, events, and gas usage
| Issue | Solution |
|---|---|
pip install errors |
Use Python 3.10+. No external packages required for this lab. |
| MetaMask not connecting to Remix | Ensure MetaMask is unlocked & set to Sepolia. Refresh Remix after switching networks. |
| "Out of gas" on deployment | Request more test ETH from faucet. Set gas limit to 300000 in Remix advanced settings. |
getPoll returns empty |
Wait for transaction confirmation (15β30s). Check Etherscan for pending status. |
| Solidity compiler mismatch | In Remix Compiler tab, select 0.8.0 or higher. Code uses pragma solidity ^0.8.0; |
| Lab Component | Course Tool Used | Concept Demonstrated |
|---|---|---|
simple_blockchain.py |
Python hashlib |
Hash functions, block linking, immutability |
SimplePoll.sol + Remix |
Remix IDE, Solidity | Smart contract structure, on-chain execution |
| MetaMask + Sepolia | MetaMask, Testnet | Wallets, gas, transaction signing, public ledger |
| Etherscan Verification | Blockchain Explorer | Transparency, auditability, real-time verification |
π‘ Note: This lab intentionally avoids complex frontend frameworks or advanced Solidity patterns. It focuses on experiential learning: students first simulate blockchain mechanics locally, then interact with a live decentralized network. This bridges Week 1 theory with the hands-on development covered in Weeks 5β7.