Part 1 · Chapter 3

Smart Contracts Introduction

At a Glance

Smart contracts are on-chain programs that automatically execute agreements when conditions are met. You'll learn why immutability, transparency, and deterministic execution matter for DeFi and NFTs.

AutonomousTrustlessImmutable

Who Is This For?

  • Learners curious about how apps like Uniswap or OpenSea run trustlessly
  • Non-developers who want a plain-language overview of smart contracts

Learning Objectives

  1. 01Describe what makes a smart contract autonomous and deterministic
  2. 02Identify common use cases (tokens, NFTs, DAOs, escrow)
  3. 03Explain key limitations like oracle dependence and gas costs
Section 1

What Smart Contracts Do

Smart contracts enforce rules without human intervention once deployed. Think of them as unstoppable programs that live on the blockchain and execute exactly as written.

🏭 The Vending Machine Analogy

A vending machine is the perfect real-world analogy for a smart contract:

Insert correct payment → receive product
No human operator needed
Rules are fixed and predictable
Can't negotiate or make exceptions
🤖

🧪 Vending Contract Simulator

Insert ETH and try to purchase items. Watch how the contract enforces rules—try purchasing without enough balance!

Your Balance
0 ETH
Select Item:
Transaction Log
Contract initialized...
Awaiting interaction...
🪙

ERC-20 Tokens

Fungible tokens like USDC, LINK, UNI—all are smart contracts tracking balances

🖼️

NFT Minting

ERC-721 contracts track unique ownership and provenance of digital assets

🏦

Lending Protocols

Aave, Compound—automated borrowing, interest, and liquidation logic

Section 2

Key Properties & Limitations

Smart contracts have unique properties that make them powerful—and unique limitations that developers must design around.

Immutable Code

Once deployed, contract code cannot be changed. This creates trust but requires careful development and auditing.

To "update" you must:
• Deploy a new contract version
• Use an upgradeable proxy pattern
• Migrate users and state

Transparent Logic

Anyone can read the bytecode and, if verified, the source code. This enables public auditing and trust verification.

Etherscan shows:
• Verified source code
• All historical transactions
• Internal function calls

Deterministic Execution

Same inputs always produce same outputs. Every node independently verifies and reaches the exact same result.

This means:
• No randomness (without special techniques)
• Predictable outcomes
• All nodes agree on state

Limitations

  • Oracles needed: Can't access off-chain data natively
  • Bugs are costly: Exploits can drain funds permanently
  • Gas fees: Every computation costs money

🔮 Why Oracles Matter

Smart contracts are sandboxed—they can't fetch data from the internet. Oracles bridge this gap by posting off-chain data on-chain.

🌐
Real World
ETH = $3,200
🔮
Oracle
Chainlink, Pyth
📜
Smart Contract
Uses price data
Section 3

Example Flows

Let's walk through how smart contracts orchestrate complex operations automatically, removing the need for trusted intermediaries.

🧪 Escrow Contract Simulator

An escrow contract holds buyer funds until conditions are met, then automatically releases payment. Click through each step to see the flow.

💰
Buyer deposits funds
Buyer Action
📦
Seller ships item
Seller Action
Buyer confirms receipt
Buyer Action
🎉
Funds released to seller
Automatic
Escrow Log
Escrow contract deployed
Status: Awaiting deposit

🗳️ DAO Vote Flow

1createProposal(description)
2vote(proposalId, support)
3Voting period ends...
4checkQuorum() → execute()

🎨 NFT Mint Flow

1mint() with 0.1 ETH
2require(supply < maxSupply)
3Assign tokenId to sender
4emit Transfer(0x0, sender, id)
Watch Out

Common Mistakes & Gotchas

These misconceptions about smart contracts can lead to security vulnerabilities or poor design decisions.

🔍
Audits guarantee the contract is safe
Audits reduce risk but can miss bugs. Even audited contracts have been exploited—always check TVL history and age.
✏️
Contracts can be edited after deployment
Smart contracts are immutable by default. Changes require proxy patterns or deploying entirely new contracts.
Gas costs are negligible
Complex operations can cost significant fees, especially during network congestion. Design efficiency matters.
🔮
One oracle is enough for price data
Single oracles are attack vectors. Production contracts use multiple redundant sources like Chainlink.

⚠️ Pro tip: Before interacting with any smart contract, check if it's verified on Etherscan, look for audit reports, and consider the age and TVL (Total Value Locked) as indicators of battle-testing.

Test Yourself

Knowledge Check

Let's see how well you understood smart contracts. Answer all 5 questions below.

1

What property ensures a smart contract produces the same result for the same input?

2

Name two popular smart contract use cases.

3

Why do many contracts rely on oracles?

4

What happens when a smart contract condition fails (e.g., insufficient balance)?

5

How can a deployed smart contract be updated?

Next Steps

Continue learning: “Layer 1 vs Layer 2” — see how smart contract environments scale to handle more users and lower fees
Hands-on practice: Visit Uniswap's UNI token on Etherscan and explore its verified source code