Lesson 4: Smart Contracts and Token Standards

Lesson 4: Smart Contracts and Token Standards

🎯 Core Concept: Smart Contracts as Automated Trust

The term "smart contract" is often a source of confusion. Pedagogically, it is best explained through the analogy of a vending machine. A vending machine is a physical smart contract—it holds assets (soda), executes logic (checks payment), and dispenses goods automatically without requiring a clerk.

In DeFi, smart contracts are autonomous, self-executing code that hold tokens and execute financial logic (swaps, loans, collateralization) automatically. They eliminate the need for intermediaries by encoding trust into code.

📚 The Vending Machine Model

The Analogy:

  1. Input: The user inserts value ($2.00) and makes a selection (Coke).

  2. Logic: The machine (code) checks if the input ≥ price and if the item is in stock.

  3. Execution: If conditions are met, the machine dispenses the Coke and returns change. If not, it returns the money.

Crucial Insight: No clerk is required. The machine holds the custody of the asset (soda) and the logic for the trade. In DeFi, the smart contract holds the tokens and executes the financial logic automatically.

Smart Contract Vending Machine Analogy

📚 Ethereum and the EVM Paradigm

While Bitcoin acts as a decentralized calculator (tracking balances), Ethereum acts as a decentralized computer. The Ethereum Virtual Machine (EVM) is a turing-complete environment that allows developers to upload persistent scripts known as "smart contracts."

The EVM as a State Machine

The EVM is a state machine: a global computer that transitions from one state to the next with every block of transactions. Every transaction changes the global state of Ethereum.

EVM State Machine Diagram

Gas and Economic Incentives

Gas is the fee paid to network validators to execute computational steps. It serves a dual purpose:

  • Incentivizing Security: Paying validators to secure the network

  • Preventing Spam: Making infinite loops prohibitively expensive

Key Understanding: Complex DeFi interactions (like entering a liquidity pool) cost more gas than simple transfers because they require more computational work from the EVM.

📚 Token Standards as Building Blocks

DeFi relies on standardization to ensure "composability"—the ability for different applications to work together like "Money Legos."

ERC-20: Fungible Tokens

ERC-20 tokens represent currencies or shares. Every ERC-20 token is identical to another of the same type (e.g., 1 USDC = 1 USDC). They serve as:

  • The medium of exchange in DeFi

  • Collateral in lending protocols

  • Governance voting power

Key Properties:

  • Fungible: Each token is identical and interchangeable

  • Divisible: Can be split into smaller units (e.g., 0.001 USDC)

  • Transferable: Can be sent between addresses

ERC-721: Non-Fungible Tokens (NFTs)

While popular for art, in DeFi, NFTs represent unique financial positions. For example, a liquidity provider position in Uniswap V3 is represented as an NFT because it has unique parameters (price range, amount) specific to that user.

Key Properties:

  • Non-Fungible: Each token is unique

  • Indivisible: Cannot be split (you own the whole NFT or none)

  • Metadata: Can store additional information

Composability: The "Money Legos" Concept

Because tokens follow standards, different DeFi protocols can work together seamlessly:

  • Deposit USDC in Aave → Receive aTokens

  • Use aTokens as collateral in Compound

  • Swap tokens on Uniswap

  • All in a single transaction

This composability is what makes DeFi powerful—protocols can build on top of each other.

Token Standards Comparison

🔑 Key Takeaways

  1. Smart Contracts = Automated Trust: Code replaces intermediaries, executing financial logic automatically.

  2. Gas Economics Matter: More complex operations cost more gas. Understanding this helps optimize transactions.

  3. Standards Enable Composability: ERC-20 and ERC-721 allow protocols to work together seamlessly.

  4. The EVM is a Global Computer: Ethereum is not just a currency—it's a platform for decentralized applications.

  5. Code is Law: In DeFi, smart contracts execute deterministically. If the code says it will happen, it will happen (bugs notwithstanding).

📖 Beginner's Corner

What's the difference between Bitcoin and Ethereum?

  • Bitcoin: A decentralized currency (like digital gold)

  • Ethereum: A decentralized computer (can run programs/smart contracts)

Why do transactions cost money?

  • Gas fees pay validators to process and secure transactions. Without fees, the network would be spammed.

What if a smart contract has a bug?

  • Bugs can lead to loss of funds. This is why audits and security are critical. Always use well-audited protocols.

Interactive Token Economics Calculator

Use this interactive tool to calculate and analyze token economics:

⚠️ Important Warnings

  • Smart Contract Risk: Code can have bugs. Always use well-audited, time-tested protocols.

  • Gas Costs: Complex operations can be expensive. Use Layer 2s for cheaper transactions.

  • Composability Risk: When protocols interact, bugs in one can affect others.


Next Lesson: In Lesson 5, we'll explore wallets and self-custody—how to safely store and manage your crypto assets.

Last updated