In Bitcoin, a smart contract is simply a set of rules that define how and when coins can be spent. These rules are written in a simple scripting language and executed by the network when a transaction is validated.
Instead of thinking of contracts as big programs, it helps to think of them as locking scripts.
Each UTXO has:
- A locking script: A small program that says what must be true to spend the coins.
- An unlocking script: Data that proves those conditions are met.
Bitcoin’s scripting language is stack based and uses op codes (operation codes) like building blocks. Some examples:
- OP_DUP duplicates the top item on the stack.
- OP_HASH160 hashes data.
- OP_EQUALVERIFY checks equality and fails if it does not match.
- OP_CHECKSIG verifies a digital signature.
A standard “pay to public key hash” script, which is what most simple payments use, is a smart contract that says:
- To spend these coins, you must provide a valid signature that matches this public key hash.
More advanced scripts can:
- Require signatures from multiple parties (multisig).
- Enforce time locks, so coins cannot be spent before or after a certain block height or time.
- Use complex conditions that combine different checks.
On scalable implementations of Bitcoin, developers can leverage these primitives to build powerful on-chain applications, all while staying inside the basic Bitcoin transaction model.
So, in Bitcoin, smart contracts are not separate programs living on another layer. They are part of the core transaction logic, evaluated by nodes whenever a transaction is processed. This keeps contracts close to the money itself and backed by the same proof of work security.