Introduction to Bitcoin Smart Contracts

UTXO Model

Each bitcoin transaction consists of multiple inputs and outputs. An output contains:

  • The amount of bitcoins it contains.
  • A piece of computer code (the locking script).
  • A reference to the previous transaction output.
  • A piece of computer code (the unlocking script).

Bitcoin Virtual Machine (BVM) and Script

At the core of understanding these computer codes lies the Bitcoin Virtual Machine. Each bitcoin node has a virtual machine (VM), which we call BVM. BVM executes instructions to conduct computations in a stack. Each instruction consists of an operator/opcode and its operands. (Opcode is also called bytecode since it is one byte in size.) Each opcode is followed by zero to two operands.

A Working Example

In one transaction, some bitcoins are locked up in an output with the following script

Smart Contracts on Bitcoin

As seen from the example, for a given locking script, only a certain unlocking script can make the joint script evaluate to true. In this sense, any bitcoin spending forms a contract: one party offers funds in bitcoin and stipulates terms of agreement; the other party can only redeem the funds if he fulfills the terms of the contract. It is smart in the sense that it is automatically enforced by miners in the Bitcoin network, unlike a conventional contract.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


sCrypt ( is a company with a mission to provide integrated on-chain smart contracting solutions on Bitcoin SV