Smart Contracts
Programmable Agreements
Introduction
Traditional contracts are documents written in legal language, interpreted by lawyers, and enforced through courts. They require trust that counterparties will perform as promised and that legal systems will provide remedy if they don't. But what if contracts could execute themselves automatically, with performance guaranteed by code rather than courts?
Smart contracts represent one of blockchain's most transformative applications. First proposed by cryptographer Nick Szabo in the 1990s and realized on Ethereum in 2015, smart contracts are programs that execute automatically when predetermined conditions are met.
This lesson explores smart contracts: what they are, how they work, and what they make possible, while examining both revolutionary potential and practical limitations.
What Is a Smart Contract?
A smart contract is a program stored on a blockchain that executes automatically when predefined conditions are satisfied. Think of it as an if-then statement where meeting certain conditions triggers automatic actions.
Nick Szabo's Vending Machine Analogy:
Szabo's original vision used the vending machine as an analogy:
- Insert correct money
- Select product
- Receive product automatically
No judge, lawyer, or trust in the operator required. The machine enforces the agreement.
Smart contracts extend this concept to complex arrangements:
- Holding and transferring digital assets
- Checking conditions from various sources
- Executing multi-step processes
- Interacting with other contracts
Key Characteristics:
- Deterministic: Same inputs always produce same outputs
- Immutable: Code typically cannot be changed once deployed
- Transparent: Code is visible to all participants
- Trustless: Execution guaranteed by the network, not by any party
Important Caveat:
Smart contracts are not legal contracts in the traditional sense. They:
- Don't interpret intent or context
- Can't handle unforeseen circumstances
- Don't automatically have legal standing
- Require careful design to avoid unintended consequences
How Smart Contracts Work
Deployment:
Smart contracts are deployed to a blockchain as code:
- Developer writes contract code (typically in Solidity for Ethereum)
- Code is compiled to bytecode
- Bytecode is deployed to the blockchain
- Contract receives a unique address
Execution:
To interact with a contract:
- User sends a transaction to the contract's address
- Transaction includes inputs and gas fees for computation
- Every node executes the same code with same inputs
- Network reaches consensus on the outcome
- Results are recorded on the blockchain
The Ethereum Virtual Machine (EVM):
Ethereum contracts run on the EVM:
- A global, decentralized computer
- Every node runs the same virtual machine
- Execution is deterministic across all nodes
- "Gas" limits prevent infinite loops and resource abuse
Composability:
Smart contracts can interact with other contracts:
- Call functions in other contracts
- Transfer assets between contracts
- Build complex systems from simple components
This composability enables "DeFi Legos"—combining protocols to create new functionality.
Immutability Trade-offs:
Once deployed, contract code typically cannot be changed:
- Benefit: Users can trust the code won't be altered
- Challenge: Bugs can't be simply patched
- Solution: Upgrade patterns (proxy contracts) exist but add complexity
Use Cases for Smart Contracts
Decentralized Finance (DeFi)
DeFi represents the most developed smart contract use case:
-
Lending: Protocols like Aave and Compound enable lending/borrowing without banks. Collateral is automatically liquidated if values fall below thresholds.
-
Decentralized Exchanges: Uniswap uses smart contracts for automated trading without order books.
-
Yield Strategies: Contracts automatically move funds to optimize returns.
Token Creation
The simplest smart contract application—creating new tokens:
- ERC-20: Standard for fungible tokens (interchangeable, like currencies)
- ERC-721: Standard for non-fungible tokens (unique items, NFTs)
- ERC-1155: Multi-token standard for gaming and collections
These standards enable interoperability—any ERC-20 token works with any ERC-20-compatible wallet or exchange.
Decentralized Autonomous Organizations (DAOs)
DAOs use smart contracts for governance:
- Token holders vote on proposals
- Votes are counted automatically
- Approved proposals execute automatically
- Treasury managed by code rather than individuals
Insurance
Parametric insurance with automated payouts:
- Define triggering events (flight delays, weather events)
- When conditions are met (verified by oracles), payouts happen automatically
- No claims process or adjuster needed
Supply Chain
Track goods and automate payments:
- Record product journey on blockchain
- Release payments when goods reach checkpoints
- Provide verifiable provenance
Oracles: Connecting to the Real World
Smart contracts operate in self-contained blockchain environments. They cannot natively access external information—they don't know the price of ETH, the weather, or whether a package was delivered.
The Oracle Problem:
Oracles bridge this gap by feeding external data into contracts:
- Price feeds for DeFi applications
- Weather data for parametric insurance
- Sports scores for prediction markets
- IoT data for supply chain verification
Centralized vs. Decentralized Oracles:
Centralized Oracle:
- Single source provides data
- Simple to implement
- Single point of failure
- If compromised, contracts execute incorrectly
Decentralized Oracle Networks:
- Multiple sources aggregate data
- Economic incentives for accuracy
- More manipulation-resistant
- Example: Chainlink aggregates data from multiple providers
The Fundamental Challenge:
No matter how secure the contract code, systems depending on external data are only as secure as their oracle. The "garbage in, garbage out" principle applies—if the oracle provides incorrect data, the contract will execute incorrectly.
Limitations and Risks
Smart Contract Bugs:
Bugs in smart contracts can have devastating consequences:
- The DAO Hack (2016): A reentrancy bug allowed an attacker to drain millions from an early decentralized organization
- Unlike traditional software, immutable contracts can't be patched
- Stolen funds typically can't be recovered
Security Considerations:
- Auditing has become essential but provides no guarantees
- Formal verification offers stronger assurance but is expensive
- Even audited protocols have been exploited
- Complexity increases attack surface
Scalability Limitations:
Every node executes every contract interaction:
- Limits throughput
- Makes complex computation expensive
- Gas costs can be prohibitive during high demand
Legal Uncertainty:
Smart contracts exist in legal gray areas:
- Code can't account for reasonable interpretation
- What happens when code doesn't match intent?
- Jurisdiction questions for global networks
- Regulatory frameworks still developing
User Experience:
Current smart contract interaction is complex:
- Requires understanding gas, addresses, and transactions
- Errors are often irreversible
- Security is user's responsibility
Key Takeaways
- Smart contracts are programs on blockchains that execute automatically when conditions are met
- They are deterministic and immutable, with every network node executing the same code
- Key use cases include DeFi, token creation, DAOs, and automated insurance
- Oracles bridge smart contracts to real-world data but introduce trust assumptions
- Significant risks include immutable bugs, security vulnerabilities, and legal uncertainty
Summary
Smart contracts extend blockchain capabilities by enabling programmable, self-executing agreements. While they offer transformative potential for finance, governance, and commerce, they introduce new risks around security, scalability, and legal recognition. Understanding both possibilities and limitations is essential for evaluating smart contract applications.

