Course Objectives
- Learn the fundamental concepts of smart contracts
- Enable beginners with zero programming background to understand ERC20 and ERC721 Solidity contracts
Smart Contract Concepts
A smart contract is:
- A program that runs on the Ethereum blockchain (per ethereum.org definition)
- Like an automated vending machine - it only executes when triggered
Solidity Introduction
- The most widely used language for Ethereum smart contracts
- Not the only option (Vyper, LLL also exist)
- Compatible with Ethereum-compatible chains like BSC, Avalanche, and TRON
Learning Solidity Through Examples
SimpleStorage Contract Example
pragma solidity ^0.8.10;
contract SimpleStorage {
uint public num;
function set(uint _num) public {
num = _num;
}
function get() public view returns (uint) {
return num;
}
}Key Features:
- Stores a number (
num) on-chain - Allows modifying the number via
set() - Allows reading the number via
get()
Version Pragma
pragma solidity ^0.8.10;Specifies compiler version requirements (0.8.10+ but below 0.9.0)
Contract Structure
contract SimpleStorage {...}- Similar to classes in OOP languages
- Basic deployable unit containing state variables and functions
- Converted to bytecode before deployment
Key Components Explained
Variables
uint public num;- State variables persist on blockchain
- Public variables are readable by other contracts/accounts
uint= unsigned integer (0 to 2^256-1)
Functions
function set(uint _num) public {...}
function get() public view returns (uint) {...}public: Can be called externallyview: Read-only (no state modification)returns: Specifies output type
👉 Learn more about Solidity fundamentals
Advanced Concepts
Ownable Pattern
Common security pattern restricting function access:
modifier onlyOwner() {
require(msg.sender == owner);
_;
}ERC20 Standard
Key functions:
balanceOf()- Check token balancestransfer()- Move tokens between accountsapprove()/transferFrom()- Delegated transfers
ERC721 (NFT) Standard
- Tracks unique token ownership
- Includes approval system for delegated transfers
safeTransferFrom()handles contract receivers
👉 Master Ethereum token standards
FAQ
Is ERC20 approve() safe?
While convenient, approving maximum amounts carries risk. Best practice:
- Only approve trusted contracts
- Revoke approvals (set to 0) when done
What can a malicious signature do?
A compromised signature could:
- Transfer all ETH from your wallet
- Transfer specific tokens
- Approve NFT transfers (setApprovalForAll)
What's MetaMask connect?
Simply shares your address with websites - cannot move assets. Generally safe for read-only access.
How are MetaMask addresses related?
Generated from same seed phrase but completely independent on-chain. No visible linkage between addresses.