Skip to content
Compare now
ConceptGlossary

What Is a Smart Contract? How They Work & Examples

Definition

A smart contract is a program stored on a blockchain that automatically executes agreed terms when predefined conditions are met, with no intermediary needed. Because the code and its results are recorded on the blockchain, they are transparent and hard to alter, but bugs in the code can also be costly.

At a glance
CategoryConcept
Reading timeAbout 9 min
Related terms8
Sources cited6
Browse the A-Z glossary
01

What is a smart contract?

So, what is a smart contract? It is a computer program that lives on a blockchain and runs exactly as written. The name can mislead, because a smart contract is not artificial intelligence and not always a legal contract. It is code that follows simple "if this happens, then do that" rules.

The idea comes from computer scientist Nick Szabo, who described smart contracts in the 1990s as promises written in digital form, together with the protocols that carry them out. His favourite example was the vending machine: you insert the right coin, press a button, and the machine releases the product without a shopkeeper. Blockchains made the idea practical because they offer a shared record that no single party controls. Ethereum, which launched on 30 July 2015, brought smart contracts to a wide audience.

KEY TAKEAWAY

A smart contract does what its code says, nothing more and nothing less. If the code does not match what the parties intended, the code still wins.

02

How smart contracts work

Most of what follows uses Ethereum as the main example, because its design is well documented. Other blockchains work in similar but not identical ways.

Code and state

A smart contract is a collection of code (its functions) and data (its state) stored at a specific address on a blockchain. Developers write it in a high-level language, compile it, and deploy it with a transaction. Once deployed, anyone can usually read the public code and call its functions.

Triggers

A smart contract does not run on its own schedule. It waits until a wallet or another contract sends it a transaction. A contract also cannot look up outside information, such as a share price or the weather, unless a separate data service called an oracle supplies it.

Execution

When a transaction arrives, the nodes of the network run the same code and must reach the same result. If the conditions in the code are met, the contract updates its state, for example by moving tokens. If they are not met, the transaction fails and its changes are undone. The outcome is then recorded on the blockchain.

Gas

On Ethereum, each step of a contract's execution costs a small amount of computing effort, measured in gas and paid in Ether (ETH). Gas (Gas Fees & Gas Limit) stops programs from running forever and pays for the network's work. Deploying a contract costs far more than a simple transfer. Other blockchains use different fee systems.

The contract lifecycle

  1. Write: a developer writes the contract code and its rules.
  2. Test and review: the code is tested and, ideally, reviewed by independent specialists.
  3. Deploy: the compiled code is sent to the blockchain in a transaction and receives its own address.
  4. Call: a user or another contract sends a transaction that triggers one of its functions.
  5. Verify and execute: network nodes run the code and check the conditions.
  6. Record: if the conditions are met, the new state is written to the blockchain and assets move. If not, the transaction is rejected.
  7. Persist: the contract stays on the blockchain. By default it cannot be deleted, and past interactions cannot be reversed.

As an example, imagine a simple escrow contract. A buyer sends payment to the contract. If the seller's delivery is confirmed before a deadline, it releases the payment to the seller, and if not, it returns the payment to the buyer. No third party holds the money, but the delivery confirmation still has to come from somewhere, usually an oracle or a signed approval.

03

Smart contracts vs traditional contracts

A traditional contract is an agreement written in human language and enforced by courts, arbitration or the parties' goodwill. A smart contract is enforced by software. The two can overlap, but they are not the same thing.

FeatureSmart contractTraditional contract
FormComputer codeHuman language, usually on paper or PDF
EnforcementAutomatic, by the networkCourts, arbitration or negotiation
AmbiguityCode is exact, but may be wrongWording can be vague, open to interpretation
ChangesHard once deployed, unless built to be upgradeableParties can amend by mutual agreement
IntermediariesOften fewerOften lawyers, banks or notaries
TransparencyPublic code and history on most blockchainsUsually private between the parties
Legal statusVaries by jurisdiction and by caseWell established in most legal systems

Many people ask whether a smart contract is legally binding. There is no single global answer. In November 2021, the Law Commission of England and Wales concluded that its existing legal framework can already support smart legal contracts, but that is one jurisdiction's view.

LEGAL NOTE

Whether a smart contract creates enforceable rights depends on local law and on the facts. This page is general education, not legal advice. If a real agreement matters to you, ask a qualified lawyer in your own country, including in Türkiye.

04

Platforms that run smart contracts

Several blockchains support smart contracts. Their languages, fees and designs differ, and this list changes over time, so treat it as a snapshot of well-known examples as of 2026 rather than a complete or ranked list.

PlatformTypical contract languageNotes
EthereumSolidity, VyperLaunched July 2015. Uses the Ethereum Virtual Machine (EVM).
EVM-compatible chainsSolidity, VyperInclude BNB Chain, Avalanche C-Chain and many layer 2 networks.
SolanaRustCalls contracts "programs". Keeps state in separate accounts.
Aptos and SuiMoveNewer designs built around the Move language.
BitcoinBitcoin ScriptDeliberately limited scripting, not general-purpose contracts.

Because EVM-compatible chains share the same tools, a contract written for Ethereum can often be deployed on them with few changes. Always check how each network is run, how it charges fees and what its security record looks like before you use it.

05

Use cases

Smart contracts are the building blocks of most on-chain applications. A dApp (Decentralized Application) usually pairs a website with one or more contracts that hold the rules and the assets. Common areas include the following.

  • DeFi: lending pools, token swaps and stablecoins use contracts to hold funds and apply rules for borrowing, trading and interest without a company running the book.
  • NFTs: a token contract records who owns each item and the rules for transferring it. The image or file itself is often stored elsewhere.
  • DAOs: a DAO (Decentralized Autonomous Organization) puts voting rules and a shared treasury into contracts, so members' votes can trigger payments. The first well-known example, called The DAO, was launched in 2016.
  • Insurance: parametric policies could pay out automatically when a trusted data feed reports an agreed event, such as a flight delay. Most remain experimental.
  • Supply chain: contracts can record handovers and release payments when a shipment is confirmed, but they depend on reliable real-world data entering the chain.

Many real-world use cases still depend on oracles, sensors or human input. A smart contract can be exact about what it is told, but it cannot check on its own whether the information is true.

06

Benefits and limitations

Benefits

  • Automation: payments and transfers happen when the conditions are met, without manual approval.
  • Transparency: on public blockchains, anyone can inspect the code and the history of its use.
  • Always on: a deployed contract can be used at any time, without office hours.
  • Less reliance on one party: no single company controls how the contract executes, although developers or administrators may still hold special powers.
  • Composability: contracts are public, so one can call another, like open building blocks.

Limitations

  • No built-in outside knowledge: contracts cannot see off-chain data without an oracle.
  • Fees: every interaction costs gas or a similar fee, and deployment can be expensive.
  • Rigidity: code cannot handle the vague or changing situations that human agreements often do.
  • Size limits: on Ethereum, a single contract has a maximum size of 24KB.
  • Irreversibility: a transaction sent by mistake usually cannot be undone.
  • Legal uncertainty: how courts treat disputes over code varies by country.
07

Risks

Smart contract risk is mostly about code, data and trust. Money held in a contract can be lost quickly if something goes wrong, and there is usually no help desk to reverse it.

Bugs and exploits

Contracts are written by people, and people make mistakes. An attacker who finds a flaw can sometimes drain funds in a single transaction. See Exploit (Crypto Exploits & Hacks) for how such attacks are described and tracked.

Immutability

Public blockchains make deployed code hard to change. That protects users from sudden edits, but it also means a flaw can stay live. Some contracts are built to be upgradeable, which fixes bugs but means an admin key or vote can alter the rules, so the trust moves to whoever holds that power.

Oracle risk

If a contract relies on a price or event feed, a wrong or manipulated feed can cause wrong payouts. The contract can be flawless and still produce a bad result.

WARNING

Interacting with an unknown or unreviewed contract can lead to the total loss of your funds. Be careful with links, fake apps and requests to approve token access. This is general information, not advice.

EXAMPLE

On 17 June 2016, an attacker used a reentrancy bug in The DAO, withdrawing ether repeatedly before the contract updated its balances. About 3.6 million ETH, roughly a third of the fund, was drained. On 20 July 2016, Ethereum carried out a hard fork to reverse the theft, and the network split into Ethereum and Ethereum Classic.

08

Smart contract languages and audits

The language depends on the blockchain. Solidity is the most widely used language on Ethereum and EVM-compatible chains. Vyper is a Python-like alternative on Ethereum. Solana programs are commonly written in Rust, while Aptos and Sui use Move, and code is compiled before deployment.

Because mistakes are costly, projects often pay for a Smart Contract Audit. In an audit, security specialists read the code, run tests and automated tools, and report problems for the team to fix. Some projects also run bug bounty programs or use formal verification, which checks code against mathematical rules.

  • An audit is a snapshot. Later code changes may not be covered.
  • Check who did the audit, which version was reviewed, and whether the findings were fixed.
  • Even a clean report cannot guarantee that a contract is free of bugs.
09 · FAQ

Frequently asked questions

What is a smart contract in simple terms?

A smart contract is a small program on a blockchain that carries out an agreement by itself. You can think of it like a vending machine: when the right input arrives, the set output follows without a person in the middle. It follows its code exactly, so it is only as good as the rules written into it.

How do smart contracts work?

A developer writes the code and deploys it to a blockchain, where it gets an address. A user or another contract then sends a transaction to call it. Network nodes run the code and check the conditions. If they are met, the result is recorded on the blockchain. If not, the transaction fails. On Ethereum, users pay gas fees for this work.

Are smart contracts legally binding?

Not automatically, and it depends on the country and the facts. A smart contract executes by code, while legal enforceability comes from law. In 2021 the Law Commission of England and Wales concluded that existing English law can support smart legal contracts. Other jurisdictions differ, so ask a qualified lawyer where you live, including in Türkiye.

Who invented smart contracts?

Computer scientist and legal scholar Nick Szabo proposed the idea in the 1990s, describing digital promises carried out by protocols, with the vending machine as an example. Ethereum, proposed by Vitalik Buterin in 2013 and launched in July 2015, was the first major blockchain built for general-purpose smart contracts.

What are examples of smart contracts?

Common examples include token contracts, such as stablecoins and NFTs, and decentralized exchanges that swap tokens using pooled funds. Lending protocols hold deposits and set interest by code. DAOs use contracts for voting and treasuries. Simple escrow contracts hold payment until a condition is met. Each runs by code on a blockchain such as Ethereum.

Are smart contracts safe?

Not always. Smart contracts can be secure when carefully written, tested and audited, but bugs, weak admin controls and faulty data feeds have led to large losses. Because blockchain transactions are usually irreversible, mistakes are hard to fix. An audit lowers risk but does not remove it. Never put in money you cannot afford to lose.

10 · RELATED
  • Smart Contract Audit
  • Solidity
  • Ether (ETH)
  • Gas (Gas Fees & Gas Limit)
  • DAO (Decentralized Autonomous Organization)
  • dApp (Decentralized Application)
  • Nick Szabo
  • Exploit (Crypto Exploits & Hacks)
11 · REFERENCES

Sources

  1. Smart contracts ethereum.org
  2. History and Forks of Ethereum ethereum.org
  3. Smart Contracts: Building Blocks for Digital Markets Nick Szabo (1996, archived copy)
  4. Smart legal contracts Law Commission of England and Wales
  5. The DAO hack at 10: From $50 million exploit to a $130 million Ethereum security fund The Block
  6. Programs Solana documentation

This glossary entry is for general information and education only. It is not investment, tax or legal advice. Crypto assets are high-risk; check official sources before you act.

Ready to pick your exchange?

See the full top 10 ranking with fees, coins and TRY support in one place.

Compare top 10