Blockchain Concepts

Smart Contracts Explained

What smart contracts are, how self-executing code on a shared ledger works, and why bugs, bad data and legal gaps limit what they can do.

On this page
  1. A program, not a legal document
  2. How one works
  3. A simple hypothetical example
  4. The oracle problem
  5. Strengths
  6. Limitations and risks
  7. Where people use them
  8. Questions to ask about any smart contract

A smart contract is a small computer program stored on a shared ledger that runs automatically when set conditions are met. The name is a little misleading. It is not necessarily smart in the sense of intelligent, and it is not necessarily a contract in the legal sense. It is code that carries out rules exactly as written.

The idea predates the technology that made it practical. A familiar comparison is a vending machine: you insert the right payment, press a button, and the machine releases a product without a clerk. The rules are built into the machine. A smart contract applies that logic to digital agreements, with the ledger acting as the machine that nobody owns.

How one works

A developer writes code that defines conditions and consequences, then publishes it to the ledger, where it receives an address. After that, anyone can send it a transaction. Every node in the network runs the same code on the same inputs and checks that they reach the same result, which is then recorded. This repeated execution is what lets strangers trust the outcome without trusting each other, and it relies on the network’s consensus mechanisms to agree on the order of events.

Running code on many machines also has a cost. Most networks charge a fee for each step of computation, partly to pay those who operate the network and partly to stop endless loops from clogging it.

A simple hypothetical example

Suppose two people agree that a deposit of 100 units will be held until a rental item is returned. A smart contract could hold the deposit and follow two rules: if the owner confirms the return, send the 100 units back to the renter; if the owner reports damage, send them to the owner. Hypothetically, if a fee of 2 units applies in either case, the amount returned would be 98.

The code handles the holding and the payment automatically. But notice that the contract still needs someone to say whether the item was returned or damaged. This is where complications start.

The oracle problem

A smart contract can only see what is on its own ledger. It cannot check the weather, a delivery status or a stock price on its own. To use outside information, it relies on a data source often called an oracle, which feeds facts into the ledger.

That reintroduces trust. If the oracle supplies wrong or manipulated data, the contract will execute faithfully on bad input. The phrase often used is “garbage in, garbage out.” Using multiple independent sources reduces the risk but does not remove it. The same limitation applies to supply chain blockchain ideas, where sensors and people supply the facts.

Strengths

  • Automation. Payments or transfers can happen without manual steps, which can cut delays and paperwork.
  • Transparency. In public designs, the code can be inspected, so parties can see the rules in advance.
  • Consistency. The same inputs produce the same outputs, with no discretion or favoritism.
  • Reduced reliance on intermediaries. For some simple arrangements, a middleman may not be necessary.

Limitations and risks

Bugs are binding

A contract does what the code says, not what the authors meant. Mistakes in logic can be exploited, and several well-known incidents involved attackers using unintended behavior to drain funds. Because published code can be difficult or impossible to change, some designs add upgrade mechanisms, which then raise the question of who has the power to alter the rules. Independent code audits help but cannot guarantee safety.

Rigidity

Real agreements involve ambiguity, changed circumstances and goodwill. Human courts can interpret “reasonable” effort or excuse a delay caused by a storm. Code cannot, unless every case was foreseen and written in. An agreement that suits a mechanical rule works well; one that depends on judgment generally does not.

Whether a smart contract is legally binding depends on the jurisdiction, on whether the usual elements of a contract are present, and on how the code relates to any written agreement. In many places the law is unsettled. If the code and the parties’ intentions conflict, it may not be clear which prevails. Anyone relying on such an arrangement for something important should seek qualified legal advice.

Privacy and permanence

On public ledgers, contract activity is typically visible to anyone. Personal data should not be placed there casually, as it may be impossible to remove later, which sits uneasily with data privacy rules.

Scams

Malicious contracts can be written to trap funds or take permissions from users. Some of these are described in the article on digital asset scams. Signing a transaction with a contract you do not understand can authorize more than you expect.

Where people use them

Common uses include automated exchanges between tokens, escrow-like holding of funds, rules for issuing and transferring digital tokens, and shared treasuries managed by group votes. Some companies have explored them for insurance payouts triggered by trusted data or for coordinating payments between businesses. Many experiments have been small or short-lived, and it is difficult to say which will prove durable.

Questions to ask about any smart contract

  • What exactly does the code do, and has it been independently reviewed?
  • Can anyone change it, and if so, who?
  • Where does it get its outside information?
  • What happens if something unexpected occurs?
  • Is there a legal agreement alongside it that says what happens in a dispute?

A smart contract is best understood as a tool for automating clear, mechanical rules. It does not make an agreement fair or wise, and it cannot replace the need for trustworthy inputs and sound design.

The complete guide to blockchain concepts

Blockchain Explained Without the Hype
Read the guide

Keep exploring

Guides from other topics

All topics →