Smart Contracts: Code on the Blockchain
A smart contract is simply a program deployed to a specific address on Ethereum that runs exactly as written. There is no central operator who can change its logic after deployment, unless the developer explicitly built in an upgrade mechanism (a design choice with its own trade-offs, which later lessons touch on). This lesson covers what a smart contract actually is, how it comes into existence, and the core trade-off — immutability — that defines working with them.
The lifecycle of a smart contract. A developer writes source code, most commonly in a language called Solidity, which reads somewhat like JavaScript or a C-family language but is purpose-built for the EVM (covered in the next lesson). That source code is compiled into bytecode — the low-level instructions the EVM actually executes. The developer then deploys that bytecode in a transaction, paying gas for the deployment, and the network assigns the resulting contract a permanent address. From that point forward, anyone — any EOA, or any other contract — can call the deployed contract's public functions by sending it a transaction (or, for read-only functions, a free query that doesn't change state). Every call that changes the contract's state costs gas, paid by whoever initiates the call.
Public versus restricted functions. Not every function on a deployed contract is open to everyone. A developer can write access control directly into the contract's logic — for example, a function that only the contract's designated "owner" address can call, enforced by a check at the start of the function (commonly a line like require(msg.sender == owner)). Anyone can read this logic in the contract's verified source code and see exactly which functions are open and which are restricted, and to whom — this is part of what "verifiable" means in practice.
Why immutability is the central trade-off. Once a contract is deployed without an upgrade mechanism, its code cannot be changed — not by its developer, not by Ethereum's broader community, not by anyone. This gives smart contracts a kind of predictability no traditional software can match: once you've read the deployed code and decided to trust it, that code cannot later be silently altered to do something different. But the same property means that a bug, once deployed, is often permanent and can be extremely costly if exploited — there is no customer support line to call and no way to patch a live, unmodifiable contract. Module 6 covers documented cases of this risk in detail. Some developers address this by deploying contracts with a deliberate upgrade path (for example, a proxy pattern that lets a separate, governance-controlled contract point to new logic), but that reintroduces a form of trust in whoever controls the upgrade — it is not free of trade-offs either.
Where contracts actually fit together. It's rare for a real application to be a single, isolated contract. A lending protocol, for instance, typically splits logic across several contracts — one tracking each market's collateral rules, one managing an interest rate model, one issuing a receipt token to depositors — which call each other's functions as needed. This composability is one of Ethereum's most useful properties: a developer building a new application can call an existing, already-deployed, already-audited contract rather than rebuilding the same logic from scratch, in the same way a web developer might call a well-tested library rather than writing their own cryptography. The flip side, covered more in Module 6, is that a vulnerability in one widely relied-upon contract can ripple into every other contract that calls it.
A short illustration of what deployed Solidity code actually looks like, for a minimal function that only the contract's stored owner address can call:
function withdraw(uint256 amount) external {
require(msg.sender == owner, "not authorized");
payable(owner).transfer(amount);
}
Anyone reading this function on a block explorer's verified source code tab can see, before ever interacting with the contract, exactly who is allowed to withdraw funds and under what condition — this is the kind of verification that distinguishes "trust the code, which you can read" from "trust a company's internal policy, which you can't."
Worked Example
Read the public, verified source code of a well-known smart contract on a block explorer — a simple token contract is a good starting point because its functions are usually short and clearly named. Identify one function anyone could call (commonly something like a transfer function, open to any token holder) and one function restricted to an owner or admin address (commonly something like a mint or pause function, gated by an ownership check similar to the example above). Note whether the contract's page also shows a "proxy" or "upgradeable" label — many block explorers flag this directly — which tells you whether the immutability guarantee described above fully applies.
Exercise
Find a verified contract on a block explorer. List its three most-called public functions (block explorers often show a "most used methods" or similar breakdown) and write one sentence for each explaining what it likely does, based on its name and the code you can read.
Recap
- A smart contract is deployed code at a permanent address; once deployed without an upgrade mechanism, it runs exactly as written and cannot be changed by anyone, including its own developer.
- Developers can restrict specific functions to specific addresses (like an owner) using access-control checks written directly into the code, which anyone can read in advance.
- Immutability is a genuine trade-off: it provides strong predictability, but it also means bugs are typically permanent and can be costly if exploited, since there is no central party who can patch a live contract — and composability between contracts means that risk can spread beyond a single application.
Resources
- Ethereum.org: Introduction to Smart Contracts — official documentation on deployment, immutability, and composability.
- Solidity Documentation — the language reference for the example contract code in this lesson.
- Etherscan: Verified Contracts — for reading a real contract's public source code and access-control logic.