Learning Objectives – after this chapter you will be able to:
- Define a smart contract and explain the vending-machine analogy.
- Describe how a smart contract is written, compiled, deployed and executed.
- List the key properties, use cases and limitations of smart contracts.
- Outline the timeline of smart-contract platforms and consensus innovations.
Smart Contracts
A smart contract is a program stored on a blockchain that runs automatically when predefined conditions are met. Its code and state live at a blockchain address, and every node executes it in exactly the same way.
- The idea was introduced by computer scientist Nick Szabo in the 1990s. He compared a smart contract to a vending machine: insert the right amount, choose a product, and the machine delivers it automatically – no shop-keeper is needed to enforce the deal.
- Smart contracts became practical in 2013–2015 when Vitalik Buterin proposed Ethereum, a blockchain with a built-in, Turing-complete programming environment designed for smart contracts and dApps.
- A smart contract is “smart” because it executes itself; it is a “contract” because it encodes rules that all parties agree to in advance. It is not automatically a legal contract.
Life-cycle of a Smart Contract
1. WriteCode in a language such as Solidity or Vyper.
2. CompileProduces EVM bytecode and the ABI (interface description).
3. DeployA transaction with no “to” address creates the contract and gives it an address.
4. InteractUsers and other contracts call its functions through transactions or calls.
Example : A Simple Solidity Contract
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;
contract SimpleStorage {
uint256 private storedData; // state variable kept on the blockchain
event ValueChanged(uint256 newValue); // log that front ends can listen to
function set(uint256 x) public { // changes state → needs a transaction (gas)
storedData = x;
emit ValueChanged(x);
}
function get() public view returns (uint256) { // read-only → free when called off-chain
return storedData;
}
}
Practice code for Solidity is available in the course GitHub repository.
Properties of Smart Contracts
| Property | Explanation |
|---|---|
| Self-executing | Runs automatically when called with valid inputs; no intermediary enforces it. |
| Deterministic | The same input on the same state always produces the same result on every node. |
| Immutable | Deployed code cannot be edited; upgrades require new contracts or proxy patterns. |
| Transparent | Bytecode is public; verified source code can be read by anyone. |
| Composable | Contracts can call other contracts, so applications can be built like building blocks. |
| Metered | Every operation costs gas, which prevents infinite loops and spam. |
Use Cases and Limitations
Use cases
- Tokens (ERC-20) and NFTs (ERC-721 / ERC-1155)
- Decentralized exchanges and lending (DeFi)
- Escrow, crowdfunding and automatic payments
- DAOs – voting and treasury management
- Supply-chain tracking and certificates
Limitations
- Cannot read off-chain data directly – needs oracles (Chapter 28).
- Bugs are costly and hard to fix after deployment.
- Every execution costs gas.
- Legal recognition varies by country.
- “Code is law” only covers what the code actually says.
Time-Line
- 1990s – Nick Szabo describes smart contracts (published in First Monday, 1997).
- 2009 – Bitcoin includes a limited, non-Turing-complete scripting language for spending conditions.
- 2013 – Vitalik Buterin publishes the Ethereum white paper.
- 2015 – Ethereum mainnet launches, enabling general-purpose smart contracts and dApp development.
- 2015 onwards – new blockchain platforms emerge, such as Hyperledger Fabric, R3 Corda and Stellar, with different contract models.
- 2020 – Ethereum’s Proof-of-Stake Beacon Chain launches; 2022 – The Merge completes Ethereum’s switch to PoS.
- Other consensus methods appear in different networks: Proof of Authority (PoA), Proof of History (PoH, used with PoS on Solana) and Proof of Importance (PoI, used by NEM).
Key Takeaways
- A smart contract is self-executing code on a blockchain – like a vending machine for digital agreements.
- Contracts are compiled to bytecode, deployed by a transaction and called through transactions or read-only calls.
- They are deterministic, transparent and immutable, which makes security reviews essential.
Question / Answer (15 questions)
Answer : A smart contract is a program stored at an address on a blockchain that executes automatically when its functions are called with valid inputs. Every node runs it identically, so its result becomes part of the shared blockchain state.
Answer : Nick Szabo introduced the concept in the 1990s. He used the analogy of a vending machine, which automatically enforces a simple agreement: pay the right amount and the product is delivered without a human intermediary.
Answer : Vitalik Buterin is a Russian-Canadian programmer and a co-founder of Ethereum. He co-founded Bitcoin Magazine in 2011 and published the Ethereum white paper in 2013, proposing a blockchain designed for general-purpose smart contracts.
Answer : No. A smart contract is code that executes automatically. It may represent an agreement, but whether it is legally binding depends on the laws of the relevant country and on the surrounding legal documents.
Answer : Bytecode is the low-level code produced by compiling a contract; it is what the EVM executes. The ABI (Application Binary Interface) is a JSON description of the contract’s functions and events, used by applications to encode calls and decode results.
Answer : By sending a transaction that has no recipient (“to” is empty) and whose data field contains the contract’s creation bytecode. The network executes it and assigns the new contract an address.
Answer : Every node executes the same contract to verify results. If execution could produce different outputs on different nodes (for example, by using random numbers or the local time), nodes would disagree and consensus would fail.
Answer : A transaction is signed, costs gas and can change contract state; it is recorded on the blockchain. A call is a read-only execution on a node, does not change state, is not recorded and is free for the caller when run off-chain.
Answer : Once deployed, the code at a contract address cannot be edited. Developers achieve upgrades by deploying a new contract and migrating, or by using a proxy pattern that forwards calls to a replaceable implementation contract.
Answer : Contracts can call and build on other deployed contracts, much like building blocks. For example, a lending protocol can use a token contract and a price-feed contract created by other teams.
Answer : Nodes must reach the same result deterministically, and external data may differ between nodes or change over time. External data is therefore brought on-chain by oracles.
Answer : Token issuance (ERC-20), NFTs, decentralized exchanges and lending (DeFi), and escrow or crowdfunding. DAOs and supply-chain tracking are other examples.
Answer : Contracts often control valuable assets, their code is public, and bugs cannot be easily patched after deployment. A single flaw can be exploited by anyone, sometimes causing large irreversible losses.
Answer : Bitcoin Script is intentionally limited and not Turing-complete; it mainly defines conditions for spending coins. Ethereum provides a Turing-complete environment with persistent contract storage for general applications.
Answer : Proof of Authority (PoA), where approved validators produce blocks; Proof of History (PoH), a verifiable time-ordering technique used with PoS on Solana; and Proof of Importance (PoI), used by NEM.
MCQ Test : Check Your Understanding (5 questions)
Select an option and press Check Answer, or answer all questions and press Submit Test to see your score. Each answer comes with an explanation.
Bibliography/References
The notes, questions and MCQs on this page are original explanations written for this course. The works listed below were consulted and are cited for attribution and further reading. Product names, logos and trademarks belong to their respective owners. Short quotations, where used, are marked and attributed.
- Szabo, N. (1997). Formalizing and securing relationships on public networks. First Monday, 2(9). https://doi.org/10.5210/fm.v2i9.548
- Buterin, V. (2013). Ethereum Whitepaper: A Next-Generation Smart Contract and Decentralized Application Platform. ethereum.org. https://ethereum.org/en/whitepaper/
- ethereum.org. (n.d.). Introduction to smart contracts. Ethereum Developer Documentation. https://ethereum.org/en/developers/docs/smart-contracts/
- Solidity Team. (n.d.). Solidity Documentation. https://docs.soliditylang.org/
- Antonopoulos, A. M., & Wood, G. (2018). Mastering Ethereum: Building Smart Contracts and DApps. O’Reilly Media.
- ethereum.org. (n.d.). The Merge. Ethereum Roadmap. https://ethereum.org/en/roadmap/merge/