Build decentralized financial applications on blockchain
DeFi (Decentralized Finance) recreates traditional financial services (banking, lending, trading) without intermediaries like banks. Everything runs on smart contracts.
Traditional finance is like a restaurant where waiters take your order and bring food. DeFi is like a vending machine - you interact directly, no middleman needed.
Token standards define how tokens behave on Ethereum. They ensure compatibility across wallets and dApps.
Standard for cryptocurrencies and utility tokens. Each token is identical and interchangeable (like dollars - one $1 bill equals any other $1 bill).
// ERC-20 Interface
interface IERC20 {
function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 amount) external returns (bool);
function approve(address spender, uint256 amount) external returns (bool);
function transferFrom(address from, address to, uint256 amount) external returns (bool);
event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);
}Examples:
USDC, DAI, LINK, UNI - Most DeFi tokens are ERC-20
Each token is unique and not interchangeable (like trading cards - each one is different).
// ERC-721 Key Functions
interface IERC721 {
function ownerOf(uint256 tokenId) external view returns (address);
function transferFrom(address from, address to, uint256 tokenId) external;
function approve(address to, uint256 tokenId) external;
function tokenURI(uint256 tokenId) external view returns (string memory);
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
}Examples:
CryptoPunks, Bored Ape Yacht Club, digital art, game items
Can handle both fungible and non-fungible tokens in one contract. Efficient for gaming.
Use Cases:
Gaming (100 swords + 1 unique legendary sword in same contract)
Decentralized Exchanges (DEX) let you trade tokens without a centralized company. Automated Market Makers (AMM) use math instead of order books.
Imagine a seesaw with ETH on one side and USDC on the other. The AMM keeps them balanced using a formula. When you buy ETH, you add USDC and remove ETH, tilting the seesaw and changing the price.
// Constant Product Formula (Uniswap V2)
// x * y = k (constant)
// x = amount of token A
// y = amount of token B
// k = constant product
// Example:
// Pool has 100 ETH and 200,000 USDC
// k = 100 * 200,000 = 20,000,000
// If you buy 10 ETH:
// New ETH amount: 90
// New USDC amount: k / 90 = 222,222
// You pay: 222,222 - 200,000 = 22,222 USDC
// Price per ETH: 2,222 USDCWhat are they?
Smart contracts holding pairs of tokens (e.g., ETH/USDC pool)
Liquidity Providers (LPs)
Users who deposit tokens into pools and earn trading fees
LP Tokens
Receipt tokens representing your share of the pool
Impermanent Loss
Risk that token prices diverge, reducing your value vs holding
DeFi lending protocols let you earn interest by lending crypto or borrow against your holdings - all without a bank.
Deposit your tokens into a lending pool. Earn interest from borrowers. Withdraw anytime.
Example: Deposit 1000 USDC, earn 5% APY = 50 USDC per year
Deposit collateral (e.g., ETH), borrow other tokens (e.g., USDC). Pay interest. Must maintain collateral ratio or get liquidated.
Example: Deposit $10,000 ETH, borrow $6,000 USDC (60% collateral ratio)
If collateral value drops too much, liquidators can repay your debt and take your collateral at a discount. This protects lenders.
If ETH drops and your collateral is now worth $7,000, you might get liquidated
You now understand DeFi fundamentals! In the next module, we'll learn how to build Web3 frontends that interact with smart contracts.