ONE TOPIC · THREE LEVELS OF EXPLANATION
What is a smart contract? An example
After this lesson: Understand what a smart contract executes and what it cannot know on its own.
01 / BEGINNER
First, what is it?
A smart contract is a program recorded on a blockchain. It contains rules and can store data. When a transaction calls it, the network executes those rules and checks the result. “Smart” does not mean intelligent: the program follows code, even when that code is badly designed.
Words to know
- Contract
- Here, a program; not necessarily a legal contract.
- Call
- A request to execute a program function.
- Oracle
- A system supplying the program with data from outside the network.
The idea to understand
The benefit is that multiple users can rely on the same execution rule without an employee approving every operation. This shifts trust towards code, the network and anyone retaining upgrade powers.
SEE IT IN PRACTICE
Now, a concrete example
In an ERC-20 token, transfer requests moving units from one account to another. The contract checks its conditions, then updates its accounting. This real mechanism does not prove that the token represents a trustworthy company or a valuable object.
YOUR TURN
The code is public. Does that prove the program is safe?
Form an answer before opening the explanation. You can also discuss it aloud.
Compare with the explanation
No. Transparency enables review but eliminates neither bugs nor dangerous administrative powers. Also check that the code you inspect matches the contract being used.
02 / INTERMEDIATE
How it works, and why
The benefit is that multiple users can rely on the same execution rule without an employee approving every operation. This shifts trust towards code, the network and anyone retaining upgrade powers.
A contract has an address. An interface prepares a request: which function, which parameters and any amount. The wallet asks for authorisation; a published transaction can then call that contract.
A contract does not act just because the time displayed on a website changed. A transaction must trigger operations that change its state. Automated services can send these transactions, but they are additional dependencies.
A program does not inherently know an asset’s price, the weather or whether a parcel arrived. An oracle supplies those facts. Its reliability and control must therefore be examined even when the contract works exactly as written.
SEE IT IN PRACTICE
Apply the mechanism
In an ERC-20 token, transfer requests moving units from one account to another. The contract checks its conditions, then updates its accounting. This real mechanism does not prove that the token represents a trustworthy company or a valuable object.
YOUR TURN
The code is public. Does that prove the program is safe?
Form an answer before opening the explanation. You can also discuss it aloud.
Compare with the explanation
No. Transparency enables review but eliminates neither bugs nor dangerous administrative powers. Also check that the code you inspect matches the contract being used.
03 / ADVANCED
The rules behind the interface
A call can read state without publishing a transaction, for example through eth_call. A state-changing transaction is executed and charged gas. On revert, execution state changes are rolled back; consumed work can still be charged.
A proxy is a contract delegating execution to an implementation. If an administrator can change that implementation, “deployed code” does not mean “permanently fixed rules”. An audit should examine storage, roles, upgrade delays and external dependencies.
YOUR TURN
A lending contract behaves as written but receives a wrong price. Can it wrongly liquidate a position?
Form an answer before opening the explanation. You can also discuss it aloud.
Compare with the explanation
Yes. Correct execution can produce an incorrect economic result when the input is wrong. Analyse the price source, freshness, safeguards and liquidation conditions.
Use the official sources at the end of this page to inspect these mechanisms further.
A useful companion: Ethereum explained: ETH, contracts and gas
THE SHORT ANSWER
A smart contract is a program stored on a blockchain, executed when a transaction calls its functions. It applies rules written in code. It can contain bugs and does not, by itself, establish legal rights or prove that external data is true.
Sources and further reading
- Ethereum.org — Introduction to smart contracts · in English
- Ethereum.org — Smart contract security · in English
- OpenZeppelin — Proxies and upgrades · in English
Page updated on
Documentation checked on · WhyTheBlockchain · Editorial approach