A smart contract is a program stored on a blockchain that runs exactly as written when someone sends it a transaction. It holds its own code and data at a fixed address, and every node that validates the chain executes it and reaches the same result. Nobody can quietly change the rules or stop it, which is why people use a smart contract to hold funds, issue tokens or enforce agreements without a trusted middleman.
If you are asking what is a smart contract in practice, think of it as a tiny shared application whose code and state are public and whose execution is verified by the whole network. This guide explains how that works, with a small example.
The term was proposed by the computer scientist Nick Szabo in the 1990s. His picture was a vending machine: you insert a coin, choose an item, and the machine delivers it by following fixed rules with no clerk involved.
Bitcoin allowed simple scripts that decide who may spend coins. Ethereum, launched in 2015, was designed so that contracts could be general programs. A contract can:
Despite the name, a smart contract is not automatically a legal contract and it is not "smart" in the sense of AI. It is code with guaranteed execution.
A contract lives at an address on a chain such as Ethereum. The life cycle looks like this.
The EVM is deterministic: given the same state and the same transaction, every node computes the same output. That agreement is what lets strangers trust the outcome without trusting each other.
Reading data is different from writing it. A read-only call runs on a single node and is free. A transaction that changes state must be included in a block and costs gas.
The following contract is a basic savings box. Anyone can deposit ETH, and only the owner can withdraw.
The constructor runs once at deployment and records who deployed it. The payable function can receive ETH, and msg.value is the amount sent. The rule that only the owner may withdraw is enforced by the code itself and checked by every node, not by a company. The balance function is view, so reading it costs nothing.
Three properties define how contracts behave.
| Property | What it means | Consequence |
|---|---|---|
| Gas | Every operation has a cost paid in the chain's currency | Infinite loops cannot freeze the network, and efficient code is cheaper |
| Immutability | Deployed code cannot be edited | Bugs are permanent unless you planned an upgrade path |
| Determinism | No randomness, clock or network calls outside the chain | A contract cannot fetch a web page or a price on its own |
Because of the last point, contracts that need outside data use an oracle, a service that writes external facts, such as an asset price, onto the chain where contracts can read them. The oracle becomes part of the trust model, so choose a reputable decentralised one.
Immutability is a strength for trust and a risk for security. Teams reduce the risk with audits, tests, formal verification, bug bounties and, when needed, upgradeable proxy patterns, which move the trust to whoever controls the upgrade.
Smart contract platforms exist beyond Ethereum, including other EVM chains and Layer 2 networks that run the same bytecode at lower fees, and non-EVM platforms such as Solana, where programs are written in Rust.
Not by itself. It enforces rules technically, but whether it counts as a contract in law depends on the jurisdiction and the surrounding agreement.
The deployed bytecode cannot be edited. Developers can deploy a new version or use a proxy pattern that points to replaceable logic, at the cost of trusting whoever can upgrade it.
The sender of the transaction pays gas to the network, and a contract can also be designed to charge its users a fee.
On Ethereum and other EVM chains the main language is Solidity, with Vyper as an alternative. Other chains use languages such as Rust or Move.
A smart contract is deterministic code stored at an address on a blockchain, executed by every node and changed only through transactions. It can hold funds and data and expose functions that anyone can verify. Gas keeps execution bounded, immutability gives trust but makes bugs permanent, and oracles bring outside data in. Understand these basics before writing Solidity.