Bitcoin Smart Contracts: How They Work and Where They Are Used
Bitcoin smart contracts run on Script, Taproot, Stacks and Rootstock. Learn how each approach works and what it is used for in the real world.
On this page
Short answer
Bitcoin smart contracts are programs that set rules for spending bitcoin, and they run on Bitcoin Script, Taproot, or layers built on top of Bitcoin such as Stacks and Rootstock. They power escrow, lending, tokenised assets and atomic swaps, though Bitcoin's scripting is deliberately narrower than the general-purpose smart contracts on other chains.
What are Bitcoin smart contracts?
A Bitcoin smart contract is a set of rules written into a transaction that decides when bitcoin can be spent. The rules run on the Bitcoin network itself, so no bank or middleman is needed to enforce them.
The simplest example is a multisignature wallet: the contract says that two of three key holders must sign before the funds move. More involved examples lock funds until a date passes, or release them only when an agreed event happens.
Bitcoin was built with a narrow scripting language on purpose. It trades flexibility for safety: fewer ways to write a contract means fewer ways for a contract to go wrong. That is why Bitcoin smart contracts look different from those on general-purpose chains, and why several approaches exist side by side.
Most Bitcoin smart contracts fall into three groups: native Script contracts that run on the base chain, Taproot contracts that hide their rules until they are used, and contracts on layers such as Stacks and Rootstock that add a richer language. Each group suits different jobs.
How does Bitcoin Script work?
Bitcoin Script is the language that every Bitcoin transaction carries. It is a stack-based language with a small set of operations: it pushes data onto a stack, checks signatures, checks time locks, and returns a yes or no answer about whether the funds can move.
Script has no loops, so a program cannot run forever and cannot drain a node's resources. That limit is deliberate. It keeps the network predictable, but it also means Script cannot do the open-ended logic that other chains allow.
| Operation | What it does | Used for |
|---|---|---|
| OP_CHECKSIG | Checks a signature against a public key | Normal payments, multisig |
| OP_CHECKLOCKTIMEVERIFY | Locks funds until a time or block height | Vesting, escrow deadlines |
| OP_CHECKSEQUENCEVERIFY | Locks funds for a relative time | Payment channels, refunds |
| OP_RETURN | Stores a small piece of data | Proofs, token markers |
Developers combine these operations into templates: multisig wallets, time-locked vaults, and hash-locked payments for atomic swaps. The templates are simple, and that simplicity is what makes them easy to audit. For a broader view of how Bitcoin organises its scaling, see what Bitcoin layer 2 is.
What did Taproot change?
Taproot, activated in November 2021, changed how Bitcoin handles complex contracts. It introduced Schnorr signatures, which let several signers combine their signatures into one, and a new way to hide a contract's rules until they are needed.
Before Taproot, a multisig contract showed all its rules on the chain. After Taproot, a contract with several spending paths can look like an ordinary single-signature payment. Only the path that is actually used is revealed, which improves privacy and keeps transaction data smaller.
Taproot also made it practical to build more involved contracts, such as discreet log contracts and payment channels, without exposing their full logic. The Bitcoin Taproot upgrade explains the change in more detail.
None of this changed Bitcoin's safety model. Taproot contracts are still Script programs with the same limits, and they still settle on the base chain. What changed is how much a contract reveals and how cheaply it can be written, which opened the door to contracts that were awkward to build before.
What are Stacks and Rootstock?
Stacks and Rootstock are layers that add richer smart contracts to Bitcoin. They settle their security in different ways, but both let developers write contracts that Bitcoin Script cannot express on its own.
| Layer | Language | How it connects to Bitcoin | Best for |
|---|---|---|---|
| Stacks | Clarity | Anchors blocks to Bitcoin | Apps that settle on Bitcoin |
| Rootstock | Solidity | Merged mining with Bitcoin miners | EVM-style contracts and DeFi |
Stacks uses Clarity, a language designed so a contract's behaviour can be checked before it runs. Its blocks are anchored to Bitcoin, which means a Stacks transaction is only final once its anchor is buried in the Bitcoin chain.
Rootstock is a sidechain that runs the Ethereum Virtual Machine, so developers can write contracts in Solidity and reuse existing tools. Its miners merge-mine with Bitcoin, which means the same mining work secures both chains. The top Bitcoin layer 2 solutions list compares these and other options.
What are Bitcoin smart contracts used for?
Bitcoin smart contracts are used for escrow, lending, tokenised assets, atomic swaps and payment channels. Each use takes the same idea — rules that release funds only when agreed conditions are met — and applies it to a different job.
| Use | How it works | Where you see it |
|---|---|---|
| Escrow | Funds locked until both sides confirm | Freelance work, trading |
| Lending | Collateral locked, released on repayment | Bitcoin-backed loans |
| Tokenised assets | Tokens issued with rules on transfers | Stablecoins, real-world assets |
| Atomic swaps | Two chains swap without a middleman | Cross-chain trading |
| Payment channels | Off-chain payments, settled on chain | Fast small payments |
Escrow is the oldest use. A buyer locks payment in a multisig contract, the seller delivers, and the funds release when both sides sign. If they disagree, a third party they both chose can settle the dispute.
Tokenised assets are a newer use. Projects issue tokens on Bitcoin layers to represent dollars, gold or shares, with rules that limit who can hold them. Ordinals showed another path: what Bitcoin Ordinals are explains how inscriptions put data on individual satoshis.
How do DLCs and BitVM fit in?
Discreet log contracts, or DLCs, let two parties bet on an outside event — such as a price — without trusting each other or the oracle that reports the result. The oracle signs the outcome, and the contract pays the winner automatically.
A DLC works in three steps. The parties lock funds in a contract with all possible outcomes written in. The oracle publishes a signed result when the event happens. The winner claims the funds by showing the oracle's signature for the outcome that matches.
BitVM, proposed in 2023, takes a different route. It uses Bitcoin's existing operations to check a computation step by step, so a complex program can run off chain and only its result needs to be verified on chain. It is still early, and it suits cases where one party might need to challenge the other.
Neither DLCs nor BitVM change what Bitcoin is. They are ways to do more with the operations Bitcoin already has, and both keep settlement on the base chain. That is the pattern for Bitcoin smart contracts: build up from simple, audited pieces rather than adding a new language.
Example (hypothetical): a loan secured by bitcoin
Example (hypothetical): a borrower wants a loan of 20,000 dollars and offers 1 bitcoin as collateral. The lender locks the loan in a contract that releases the bitcoin back to the borrower when the loan is repaid, and to the lender if the borrower defaults.
The contract uses a time lock and a price check. If the bitcoin price falls by a fifth, the borrower must add collateral or repay part of the loan. The arithmetic is plain: a fifth of 1 bitcoin at 50,000 dollars is 10,000 dollars, so the collateral would be worth 40,000 dollars, still twice the 20,000 dollar loan.
If the borrower repays on time, one signature from each side releases the collateral. If not, the lender claims it after the time lock passes. No court or agent is involved; the rules in the contract decide the outcome.
What are the common mistakes?
The most common Bitcoin smart contract mistakes are treating Bitcoin like a general-purpose chain, trusting a layer without checking its security, and writing a contract nobody has reviewed.
- Assuming EVM logic works. Bitcoin Script has no loops and no general storage.
- Ignoring the anchor. a layer contract is only as settled as its link to Bitcoin.
- Skipping review. a bug in a contract that holds funds cannot be undone.
- Trusting an oracle blindly. a DLC is only as honest as the oracle that signs.
- Forgetting fees. complex contracts cost more to settle, especially when the network is busy.
Start with the simplest contract that does the job. A multisig wallet or a time lock is easier to audit than a custom layer contract, and it settles directly on Bitcoin. A smart contract audit is worth the cost before real funds are locked in.
Key takeaways
- Bitcoin smart contracts are rules for spending bitcoin, written in Script, Taproot or a layer language
- Script has no loops by design, which keeps contracts simple and easy to audit
- Taproot hides a contract's rules until the path that is used is revealed
- Stacks and Rootstock add richer contracts while settling back to Bitcoin
- Escrow, lending, tokenised assets, atomic swaps and payment channels are the main real-world uses
Frequently asked questions
Does Bitcoin have smart contracts?
Yes. Bitcoin has had smart contracts since the start, written in its Script language. They cover multisig wallets, time locks, escrow and payment channels. Taproot and layers such as Stacks and Rootstock added richer options, but the base chain stays deliberately simple.
How are Bitcoin smart contracts different from Ethereum smart contracts?
Ethereum contracts run in a general-purpose virtual machine with storage and loops, so they can do almost anything. Bitcoin Script has no loops and no general storage, so contracts are narrower, simpler and easier to audit, and richer logic moves to layers built on top.
What is a discreet log contract?
A discreet log contract, or DLC, is a Bitcoin contract that pays out based on an outside event, such as a price. The parties lock funds with all outcomes written in, an oracle signs the result when the event happens, and the winner claims the funds with that signature.
What is BitVM?
BitVM is a way to run complex programs off chain and verify the result on Bitcoin, using only Bitcoin's existing operations. It was proposed in 2023 and is still early. It suits cases where one party may need to challenge the other's result step by step.
Can I build a DeFi app on Bitcoin?
Yes, through layers. Stacks and Rootstock support lending, trading and tokenised assets with contracts that settle back to Bitcoin. Native Script can handle escrow and payment channels directly, but full DeFi logic needs a layer with a richer language.
Are Bitcoin smart contracts safe?
They are as safe as their design and review. Native Script contracts are simple and well tested, which is a strength. Layer contracts add more power and more risk, so they need review and an audit before real funds are locked in.