How do smart contracts work?
A smart contract is a program stored on a blockchain that executes an agreement automatically when set conditions are met. Users call it with a transaction; every node runs the same code and records the result. On Ethereum, deployed code cannot be changed and its transactions cannot be reversed. The German term is Smart Contract.
Published . Last reviewed .
Smart contracts in brief
| Term | Smart contract. German: Smart Contract, also intelligenter Vertrag. |
|---|---|
| Origin | Nick Szabo coined the term and described the concept in 1994 (ethereum.org). |
| EU law | Article 2(39) of Regulation (EU) 2023/2854 (Data Act) defines the smart contract; Article 36 sets requirements for smart contracts that execute data sharing agreements. |
| Date of application | The Data Act applies from (Article 50). |
| A number | An Ethereum smart contract can be at most 24 KB in size (ethereum.org). |
How do smart contracts work compared with traditional contracts?
Smart contracts work by putting the performance of a contract into code, so no party has to trust the other to pay. With traditional contracts, a person or institution has to carry out the outcome: a bank releases escrow money, a court settles a dispute. The ethereum.org introduction calls "the need for trusted individuals to follow through with the contract's outcomes" one of the biggest problems with a traditional contract.
Its metaphor is a vending machine, as described by Nick Szabo: with the right inputs, a certain output is guaranteed. A smart contract for an escrow account can hold funds and release them only after a set date. Before that date the contract does not execute. In smart contracts vs traditional contracts, the difference is who enforces the terms: people and courts in one case, code in the other.
How do smart contracts work on Ethereum?
On Ethereum a smart contract is an account with its own address, code and balance. The documentation defines it as "a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain". No user controls it; it runs as programmed.
- A developer writes the contract in a language such as Solidity or Vyper and compiles it.
- The developer deploys it in a transaction and pays gas, the fee for computation.
- A user sends a transaction that calls one of its functions.
- Every node runs the function and updates the state of the contract in the same way.
That is how smart contracts work in a blockchain: the result is the same on every node, and it is stored on the chain. Anyone can write and deploy a smart contract.
What are smart contracts used for?
Smart contracts are used for financial services, tokens and wallets. ESMA calls them "the backbone of decentralised finance". It analyzed contracts on the Ethereum blockchain and found five categories: financial, operational, tokens, wallet and infrastructure (ESMA, ).
Examples of smart contracts in DeFi are stablecoins, governance tokens and decentralized exchanges, where users trade tokens with each other without an intermediary. The article on decentralized finance explains these applications.
Are smart contracts immutable, and what is smart contract risk?
Smart contracts on Ethereum are immutable by default: they "cannot be deleted by default, and interactions with them are irreversible". Smart contract risk is the risk that the code contains an error or that someone misuses it, because a faulty contract executes exactly as written.
Smart contracts also have a limit by design: they "can't retrieve data from offchain sources". A price or an interest rate reaches them through a blockchain oracle, which adds its own risk.
The Data Act answers part of this risk for data sharing. Article 36 requires robustness and access control, a way to terminate or interrupt the contract, archiving of transaction data and code, and consistency with the terms of the agreement. The vendor must perform a conformity assessment and issue an EU declaration of conformity.
Smart contracts in Germany, Austria and Switzerland
In Germany and Austria the Data Act applies directly since . It defines a smart contract as "a computer program used for the automated execution of an agreement or part thereof" (Article 2(39)). Its Article 36 covers only smart contracts that execute data sharing agreements. Whether a smart contract is legally binding as a contract depends on national contract law. Banks and crypto-asset service providers that use smart contracts stay under the rules for their service, supervised by BaFin in Germany and the FMA in Austria.
Switzerland is outside the EU, so the Data Act does not apply there. Article 973d of the Swiss Code of Obligations defines a ledger-based security as a right that is registered in a securities ledger and "may be exercised and transferred to others only via this securities ledger". FINMA supervises. This page gives no legal advice.
Sources
- ethereum.org: Introduction to smart contracts, updated
- ethereum.org: Introduction to smart contracts (developer documentation), updated
- European Securities and Markets Authority: Decentralised Finance: A categorisation of smart contracts,
- European Union: Regulation (EU) 2023/2854 (Data Act),
- Swiss Confederation: Code of Obligations, status as of