Course 05 · Lesson 02

Smart Contracts Explained

~8 min readLesson 02/7
Progress Tracking Locked• Free Feature

Sign in to unlock progress tracking

Create a free account or sign in to save your completed lessons, track your quiz scores, resume your learning from any device, and earn course completion certificates.

Smart contracts are the technology that makes everything else in this course possible. DeFi, NFTs, DAOs, decentralised exchanges - all of them are smart contracts. The concept was proposed by computer scientist Nick Szabo in 1994 - fifteen years before Bitcoin existed - as a way to encode contractual terms in digital code that executes automatically without requiring trust in any party to honour the agreement. Ethereum made this vision practical by providing a blockchain environment where smart contracts could be deployed, verified, and executed by anyone without permission from any authority. Understanding what smart contracts actually are - and critically, what they cannot do - is the foundation for understanding every protocol and application built on them.

What Is a Smart Contract?

A Smart Contract is a programme stored permanently on a blockchain that runs automatically when specific conditions are met. It is characterised by Immutability - once deployed, the code cannot be changed. It is transparent - anyone can read the code. It is deterministic - the same inputs always produce the same outputs. And it is self-executing - no human needs to trigger it, verify it, or enforce it.

The simplest mental model: a vending machine. You insert money, you press a button, the machine checks your input against its rules, and if conditions are met - it dispenses your item automatically, without a shopkeeper, without trust, without any possibility of the machine deciding to keep your money. A smart contract is a vending machine that can hold assets, enforce agreements, and execute financial transactions - at any scale, with any complexity, written typically in the programming language Solidity.

How Smart Contracts Execute

Smart contracts are deployed to Ethereum by sending a transaction containing the contract code. Once deployed, the contract has its own address - it can hold ETH and tokens, and it can be called by sending transactions to that address. External software communicates with it using its ABI (Application Binary Interface).

SMART CONTRACT EXECUTION - EXAMPLE

Simple Escrow Contract:
• Alice sends 1 ETH to the contract.
• Bob completes the agreed work.
• Alice confirms completion within 30 days.
If confirmed: 1 ETH automatically transfers to Bob.
If not confirmed within 30 days: 1 ETH automatically returns to Alice.

No lawyer. No intermediary. No trust required. The code executes the agreement exactly as written - automatically, transparently, irreversibly. Both Alice and Bob can read the contract code before agreeing.

Real-World Applications

SMART CONTRACT APPLICATIONS

Decentralised Exchanges: Swaps are executed automatically by contracts calculating price ratios based on liquidity pools.
Lending Protocols: Lending and collateral rules are automatically maintained. Undercollateralised positions are automatically liquidated.
NFTs: Contracts that map unique token IDs to specific addresses, automating transfers and digital ownership records.
Stablecoins: Systems that automatically manage collateral deposits and peg parameters without institutional intervention.

What Smart Contracts Cannot Do

Smart contracts have significant limitations that are frequently overlooked. The most important: smart contracts can only access data that is on the blockchain. They cannot natively access real-world data - stock prices, weather data, sports results, or any external information.

This limitation is addressed by an Oracle - a service that feeds external data onto the blockchain for smart contracts to consume. But oracles introduce a new trust assumption: the smart contract is trustless, but the oracle feeding it data is a centralised point of potential failure or manipulation.

The Code Is Law Problem

Smart contract immutability - the property that makes them trustworthy - is simultaneously their most significant risk. If a smart contract has a bug, that bug is permanent. If the bug can be exploited to drain funds, the only recourse is a network-level governance decision to reverse the transactions, which is itself deeply controversial.

The most significant example is the 2016 DAO hack. A smart contract managing approximately $150 million of ETH was exploited through a recursive withdrawal bug. The attacker drained approximately $60 million of ETH. The Ethereum community faced a stark choice: honour the "code is law" principle and accept the loss, or perform a hard fork to return the funds. The community chose the hard fork - creating the Ethereum/Ethereum Classic split that exists to this day. The episode remains the defining case study in smart contract vulnerability and community governance.

Key Takeaways
Smart contracts are self-executing programmes on a blockchain - immutable, transparent, deterministic, requiring no human intermediary.
Once deployed, contract code cannot be changed - bugs are permanent and potentially exploitable.
Applications: DEXs, lending, NFTs, stablecoins - all are smart contracts.
Smart contracts cannot access real-world data natively - oracles provide this bridge but introduce trust assumptions.
The code is law principle creates the immutability paradox: trustworthy because unchangeable, dangerous because bugs cannot be fixed without governance.
KEY TERMS
Smart Contract
Self-executing code stored on a blockchain that automatically performs actions when predefined conditions are met - no human intermediary required.
Solidity
The primary programming language for writing Ethereum smart contracts - statically typed, similar to JavaScript.
Immutability
Once deployed, a smart contract's code cannot be changed - a security feature that is simultaneously a vulnerability when bugs exist.
Oracle
A service that feeds real-world data into smart contracts - required because blockchains cannot natively access external data.
ABI (Application Binary Interface)
The specification defining how to interact with a smart contract - the interface between the contract and the outside world.

Test Your Knowledge

Take a quick 5-question quiz to check your understanding of this lesson.