What are Bitcoin smart contracts, and how do they work?

The idea of a digital framework that can carry out the terms of a contract without human intervention is not new. In fact, Nick Szabo, the infamous computer scientist first used the term “smart contract” in 1994, demonstrating the long history of self-executing protocols. But the various applications of blockchain technology we see today proved the numerous potential of this protocol evident.

A smart contract refers to a self-executing digital protocol that carries out the predefined conditions set by the developer. These self-executing protocols operate on the blockchain they are developed on; that is, an Ethereum smart contract runs on the Ethereum blockchain, and a Bitcoin smart contract run on the Bitcoin blockchain. So, what are Bitcoin smart contracts, and how do they work? 

What are Bitcoin smart contracts?

For many years, we have thought that smart contracts only exist on the Ethereum network and smart contract blockchain platforms like Solana and Cardano. ‘Bitcoin’ and ‘smart contracts’ were two words that were barely used together in crypto discussions. However they are more used together than ever before. Bitcoin blockchain now supports smart contracts, and developers create them through a unique, yet complex scripting language.

Bitcoin is rarely the first on-chain mentioned when discussing smart contracts, because of “opcodes.” Opcodes are small code fragments that represent operational functions that can be executed. For instance, the opcodes in Ethereum can read and write autonomously and also allow you to create even more complex opcodes that can execute difficult tasks on the blockchain. 

Multiple opcodes are known as smart contracts and are thus responsible for different functions on the blockchain. Unlike Ethereum, Bitcoin does not contain opcodes, which implies that there is never a recorded “state” for Bitcoin at any given time; instead, Bitcoin merely keeps track of who owns what and permits users to send and receive coins. 

What is Bitcoin smart contracts, and how do they work?

Bitcoin smart contracts, like other networks, are lines of code that automatically execute when the conditions are met. To understand how Bitcoin smart contracts work, one must first understand the computing language, Script. 

The script computing language employs a lock and key mechanism to execute smart contracts. When the sender or developer sets a prerequisite or condition that needs to be processed, the language recognizes it as a lock. The receipt may provide a corresponding “key,”  which is usually a code to fulfill the condition set by the sender.

For instance, Script allows the sender to set criteria when a user wants to send BTC to another recipient. This criteria acts as a lock and is called the ScriptPubKey. Once the recipient acknowledges the criteria set by providing a matching key called ScriptSig or Script Witness (used during SegWit transactions), the transaction is executed. The script allows different conditions to be set, hence various types of Bitcoin smart contracts.

Types of Bitcoin Smart Contracts

There are different types of smart contracts; the following are the common types in use:

Pay-to-public key hash scripts (P2PKH)

The pay-to-public key hash script is the most common type of Bitcoin transaction that allows users to send BTC to a recipient address. To access the sent funds, the receiver must provide the corresponding private key. In simpler terms, this smart contract is a typical lock-and-key mechanism whereby the recipient must provide a signature that corresponds with the public key defined by the script. 

Multisignature scripts (MultiSig or m-of-n MultiSig)

Multisignature scripts are unlike pay-to-public key hash scripts, which require one key to process the defined transaction. Instead, it requires more than one signature to approve its validity. The 2-of-3 MultiSig, a common multi-sig contract, needs at least two out of three mandatory signatures to execute a transaction. This approach is to increase security and determination through hacks. 

Time-locked Bitcoin Transactions (nLockTime and sequence)

A time-locked Bitcoin transaction is a type of smart contract that withholds Bitcoin transactions until a specified future time or block height is attained. The addition of new opcodes for the ‘nLockTime’ and ‘nSequence’ fields in BIP-65 and BIP-112 enabled time-locked transactions. This feature is common in many Bitcoins smart contracts and is used to lock up Bitcoin investments for months or even years. It is often preferred for being profitable as it reduces fee sniping.

Pay-to-Script Hash (P2SH-BIP16)

The pay-to-script-hash follows an unquestionable mechanism in comparison to other smart contracts. It is a transaction method introduced in Bitcoin via Bitcoin Improvement Proposal 16 (BIP 16) that allows the sender to lock up bitcoins to the hash of a script.

In a P2SH transaction, for instance, if Alice sends Bob $1 BTC, she also includes the hash of the script that is needed to spend the Bitcoin in the transaction. The script may require Bob’s private keys and many other requirements. Bob then reconstructs the script Alice used to send the Bitcoin when he wanted to spend it, and he signs the transaction using any private keys the script requires. It’s like providing a puzzle to a friend, and upon completion, they receive money. 


Miniscript was introduced to simplify the complex transaction conditions for developers. It is a simple yet high-level coding language that helps developers create more secure and efficient Bitcoin scripts with multiple functionalities. It addresses several issues with the Bitcoin script language and enables the practical use of complex spending conditions. In essence, it enables your Bitcoin wallet to perform more complex operations, such as having a wallet that requires multiple keys for an account.

Build Smart Contracts and NFTs on Bitcoin

With PTPWallet, you can build bitcoin smart contracts for various use cases and solutions in today’s world. From the success of Ordinals and Runes, it has been proven that digital assets of value can be built and managed successfully on the bitcoin blockchain. Building your own token can be challenging, but with the help of experts like PTPWallet, who do the heavy lifting for you, it can be done quickly and easily. 

PTPWallet assists businesses with full-scale development, deployment, design, management, and even promotion of projects. We handle all kinds of tokens including  non-fungible tokens, utility tokens, real world assets (RWA) security tokens, and many more. 

Our industry-leading smart contract security developers and professionals have all the necessary expertise to provide each client with a full-fledged smart contract development process while offering enhanced protocol security to secure your users. 


More to explore

Get on the VIP list!

Get company and PTPWallet updates and news sent straight to your inbox. No spam. Unsubscribe at any time. 

Get on the VIP list!

Get company and PTPWallet updates and news sent straight to your inbox. No spam. Unsubscribe at any time.