HOLIDAY OFFER: Get the gift of up to $70 of Bitcoin. While supplies last!

Shop now

Up your Web3 game

Ledger Academy Quests

  • Test your knowledge
  • Earn POK NFTs
Play now See all quests

Bitcoin Smart Contracts and Apps: Do They Even Exist?

Beginner
Coins spiraling in a circle
KEY TAKEAWAYS:
— Bitcoin supports smart contracts through its native language ‘Script’, enabling multiple transaction types to take place.

— Script is a purposefully non-Turing complete language and this makes smart contracts on Bitcoin limited in their functionality.

— Layer-2 blockchains and solutions are present for Bitcoin to improve its smart contract offerings while keeping its security intact.

Bitcoin is the world’s first blockchain and cryptocurrency. Its primary use case is peer-to-peer payment transfers.  Often Bitcoin is referred to as digital gold, with it offering a secure and decentralized way to store and manage value. This core value proposition is what led Bitcoin to become the most popular and widely used crypto network so far. And it’s these same core values that many other networks have taken inspiration from while creating new use cases and innovations. 

To explain, while Bitcoin was created purely to store and manage value in a decentralized manner, other networks expanded into other territories, creating ways to host decentralized applications. Decentralized apps (DApps) have taken the world by storm, and as such, there has been a push to create these types of apps that work using the most popular network, Bitcoin. However, this was not the reason Bitcoin was created, thus it’s a bit more complex than many smart-contract-ready networks like Ethereum.

So how do Bitcoin’s versions of smart contracts work? And what kinds of functions are available using this method?

Let’s explore the concept of Bitcoin smart contracts and dive into the different types of smart contracts on the Bitcoin network. 

Does Bitcoin Have Smart Contracts?

Yes, the Bitcoin blockchain supports smart contracts. Developers can use Script, a scripting language, to write and deploy smart contracts on Bitcoin.

So, why is Bitcoin never the first thing people think when the topic of smart contracts pops up? 

Often, you’ll hear people say Bitcoin is not “Turing complete”. But in fact, that’s not quite true. Instead, it’s all to do with something called opcodes. Or more, Bitcoin’s lack of them.

Opcodes are essentially small pieces of code that represent functions that can be executed on a specific network. On some blockchains, for example, Ethereum, some of these opcodes have the power to read and write the current “state” of the blockchain. Then from there, you can combine many of these opcodes to create complex automated tasks triggered by a blockchain transaction. These groups of opcodes are better known as smart contracts and are responsible for countless blockchain apps and platforms.

However, Bitcoin script doesn’t contain these types of opcodes. That also means that Bitcoin doesn’t have a recorded current “state” at any given moment. Instead, it simply records who owns what, and allows people to send and receive coins via UTXOs, with a limited choice of conditions of how that value transfer executes.           

So, now you know why Bitcoin smart contracts aren’t exactly what you might expect, so let’s see how they work.

What are Bitcoin Smart Contracts and How Do They Work?

Bitcoin smart contracts, like their counterparts on other networks, are simply pieces of code that automatically execute when some predefined conditions are met. So, you can imagine, they work in a similar way. 

Firstly, it’s important to know that Bitcoin operates using its own computing language: Script. And script uses something like a lock and key system to execute smart contracts. The sender sets a condition or rule in order for the transaction to be processed — acting as the lock. To follow, the recipient must provide a matching “key” —also a piece of code in Script—that fulfills the condition set by the sender.

Now, what kind of conditions can be set?

Let’s find the answer to this by exploring the various types of smart contracts present on Bitcoin.

Types of Bitcoin Smart Contracts

Pay-to-public key hash scripts (P2PKH)

This is the most common type of transaction. The sender addresses Bitcoin to the receiver’s public key’s hash. To access the funds, the receiver must prove they own the corresponding private key.

This is like locking a box and giving the key to one person.

Multisignature scripts (MultiSig)

MultiSig requires more than one signature for a transaction to be valid. An example is a 2-of-3 MultiSig, which needs at least two signatures from a group of three to execute a transaction. This adds an extra layer of security and is often used by businesses.

This is like a safe that needs two or more keys turned at the same time.

Time Locked Bitcoin Transactions (nLockTime and nSequence)

This allows a transaction to be created at any given time, but only be valid at a specified future date or block height. It’s a way to ‘postdate’ a Bitcoin transaction and is useful for various financial agreements. It’s a sort of timelock that pertains to transactions. 

Time-locked transactions were made possible with BIP-65 and BIP-112’s introduction of new opcodes concerning the  ‘nLockTime’ and nSequence fields.

Essentially, these opcodes allow an entry to specify the earliest time it can be added to a block—stopping the transaction from completing until a certain number of blocks, or amount of time has passed. In short, these time-locked opcodes are important, as without them the entire Lightning network could not exist!

Pay to Script Hash (P2SH – BIP16)

Instead of locking outputs to a public key, P2SH locks them to a script’s hash. The spender needs to provide the script matching the hash and satisfy its conditions. This enables complex scripts without burdening the sender with their details. P2SH came into play with the BIP-16 upgrade.

For instance, you challenge a friend with a puzzle. If they solve it, they get the bitcoins. 

Pay-to-taproot (P2TR – BIP341)

P2TR is a privacy-preserving complex script that allows multiple parties to create a signature that looks like a single one, enhancing privacy and efficiency. 

It is a combination of P2PKH and P2SH with a lot more privacy. This was part of the BIP-341 proposal, popularly known as the Taproot upgrade.

Miniscript

Miniscript was introduced to make the complex spending conditions (that Bitcoin was already capable of) much easier for developers to use and implement. In short, it’s a simple coding language that facilitates a number of functionalities.  Essentially it allows your Bitcoin wallet to handle more advanced actions like requiring multiple keys for an account or having a wallet with some spending conditions that are only active after some amount of time.   

While this isn’t strictly a smart contract, this is one of the more flexible custody schemes miniscript offers. 

Now that you know about some advanced functions, let’s dig into something more tangible.  

What about NFTs on Bitcoin — do they even exist in the first place?

Tokens and NFTs on Bitcoin

The Ordinals protocol launched on Bitcoin in January 2023, enabling “Ordinal NFTs” by attaching data to individual Satoshis. Each Satoshi gets a unique number through an intuitive ordering system.

Ordinal NFTs reside fully on the Bitcoin blockchain without the need for a separate token. However, that means, inscribed Satoshis now compete for block space on the network, resulting in a spike in network fees.

BRC-20 — a token standard for Bitcoin Ordinals — uses JSON data to facilitate various token functions. At present, the BRC-20 token standard offers three primary functions:

  • Deploy: This function allows users to create a new BRC-20 token contract.
  • Mint: Users can use the mint function to generate a specific amount of BRC-20 tokens.
  • Transfer: The transfer function enables users to send a certain amount of BRC-20 tokens to another address.

The BRC-20 token standard is relatively new and young. Hence, the functionalities are limited and not entirely user-friendly. 

Bitcoin L2s or layer-2 solutions can help Bitcoin overcome this limitation. 

Smart Contracts on Bitcoin Layer 2s

Bitcoin smart contracts have limited functionalities. However, layer-2 blockchains on Bitcoin allow developers to code more complicated smart contracts.

To better understand how they work, let’s look at a few examples of Bitcoin layer 2 chains.

Lightning Network

The Lightning Network (LN) is a layer 2 scaling solution for Bitcoin, designed to facilitate fast and low-cost transactions by conducting most of the transactions off-chain. It operates using payment channels which are like private off-chain tunnels between users that facilitate payments. 

Apart from instant payments and low fees, LN enables the creation of more complex smart contracts like Hashed Time-Locked Contracts (HTLCs) within “Lightning Apps” or “LApps.” These contracts are programmable, most often implemented for functions such as micropayments, instant swaps, and streaming payments.

The Lightning network is also home to Discreet Log Contracts (DLCs). To clarify these contracts allow two parties to engage in a bet, using a connection to an oracle to verify real-life events. While the oracle is crucial for the settlement of these bets, it is not directly involved in the transactions that create and settle the contract. These are directly negotiated among the parties making the bet.

Stacks

Stacks is a chain that works alongside Bitcoin. It enables developers to build smart contracts and decentralized applications (dApps) on top of Bitcoin. 

They employ “Proof of Transfer” (PoX) — an approach to allowing the Stacks blockchain to process its transactions while leveraging Bitcoin’s security.

Smart Contracts on Stacks

Using Stacks, developers can create a wide range of applications, from decentralized finance (DeFi) platforms to non-fungible tokens (NFTs) and decentralized social networks. 

It acts as a more diverse and expansive ecosystem while maintaining the robustness and security of Bitcoin as the base layer.

Two applications of Stacks-based smart contracts on Bitcoin are:

Hiro Wallet: It is a non-custodial wallet enabling secure connections and transactions within the Stacks ecosystem. Bitcoin users can participate in Stacking, a reward system that distributes BTC to users for supporting the network and locking STX tokens for a specified period.

Bitcoin Naming Service (BNS): BNS, a decentralized name system for Bitcoin, similar to Ethereum’s ENS, saw a recent surge in registrations. To own a BTC name, users have to interact with the smart BNS contract on the Stacks chain.

Start using smart contracts on Bitcoin

Understanding how Bitcoin smart contracts work is imperative to participate safely in crypto and DeFi. It’s even better when a user can understand smart contract code to assess if a smart contract is safe to interact with.

And as with using smart contracts on any blockchain, you should prioritize the security of your private keys. The best way to do that is to use Bitcoin applications through a hardware wallet like Ledger. 

Ledger hardware wallets keep private keys offline at all times and also enable clear signing. This helps users clearly read the transaction details before they approve it. 

Moreover, Ledger hardware wallets offer support to Hiro Wallet by which users can pair them and start stacking STX and delegating them to trustworthy validators.

Now you know everything about smart contracts on Bitcoin, you’re ready to dive in. So get yourself a Ledger, connect to Ledger Live, and start exploring the Bitcoin ecosystem. The time for education is now, and accessing Bitcoin from the Ledger ecosystem is secure and easy to understand.


Stay in touch

Announcements can be found in our blog. Press contact:
[email protected]

Subscribe to our
newsletter

New coins supported, blog updates and exclusive offers directly in your inbox


Your email address will only be used to send you our newsletter, as well as updates and offers. You can unsubscribe at any time using the link included in the newsletter.

Learn more about how we manage your data and your rights.