Where should you develop your blockchain app?
→ Download our guide to Web3 ecosystemsClose Icon

Bitcoin Ecosystem: An Overview of Bitcoin Smart Contracts and How They Work

Bitcoin rarely featured in the discussion of smart contracts because it had a limited scripting language that prioritized security over programmability.That’s changing thanks to Stacks: Bitcoin smart contracts are now here. Developers now have options for building Web3 applications beyond Ethereum and other emerging blockchains.

Type
Deep dive
Topic(s)
Bitcoin
Stacks
Published
April 27, 2022
Author(s)
Content Marketing Manager
Power of Smart Contracts
Contents
Copy link

Bitcoin smart contracts, in terms of their core design and architecture, exist on a separate blockchain (Stacks) and leverage Bitcoin’s security and latent capital through a unique consensus mechanism called Proof of Transfer. All of this occurs without tampering with Bitcoin itself. Let’s get into how they work. 

So What Exactly Is a Smart Contract?

Smart contracts are blockchain programs designed to run autonomously when predefined events or actions occur. The terms of a smart contract are specified in code to eliminate the need for human execution, arbitration, or enforcement, and since that code is stored on the blockchain, the terms of the contract can’t be tampered with.

Bitcoin smart contracts, like other smart contracts, ensure trustless transactions. But beyond that, those transactions ultimately settle on Bitcoin, making the history of transactions more durable through Bitcoin’s battle-tested security.

Interestingly, Bitcoin wasn’t originally designed with smart contract functionality because it was designed to be a decentralized currency. That required an emphasis on both security and decentralization, and in order to achieve that goal Bitcoin had a limited scripting language to reduce the surface area for potential vulnerabilities. It made the currency safer but also limited its programmability. Now, Stacks functions as the smart contract layer for Bitcoin, and it enables developers to write fully expressive smart contracts that benefit from Bitcoin’s security.

Example of Bitcoin Smart Contracts at Work 

Bitcoin smart contracts can execute complex and predetermined multi-step transactions. Let’s take a look at an example and see how a Bitcoin smart contract can work in practice.

Arkadiko is a Bitcoin DeFi app that enables users to take out a self-repaying loan in USDA (a stablecoin) that is backed by their STX tokens. This is how it works at a high level.

  1. A user deposits STX tokens into an Arkadiko vault as collateral.
  2. The user can then borrow USDA, in an amount less than or equal to 25% of the initial value they deposited.
  3. The requested USDA is sent to the user’s wallet.
  4. When depositing into the vault, the user can choose to stack the STX collateral via Stacks’ Proof of Transfer mechanism to earn BTC yield.
  5. That BTC yield pays off the borrowed USDA. When the USDA loan is fully repaid, the assets in their vault unlock and the user can withdraw them.
  6.  In the event that the loan isn’t repaid, or the collateralized loan falls under the liquidation threshold, the user’s assets are sold in an auction until the debt and penalty fees are covered.

The reason I'm listing out all of these steps is to point out that all of this complexity happens autonomously. There are no individuals signing off at different stages. Importantly, this also means that individuals cannot interfere or manipulate the process. That is the power of smart contracts. 

Why Do Bitcoin Smart Contracts Need a Gas Asset?

Bitcoin smart contracts on Stacks blockchain use the Stacks (STX) token as a gas asset to pay for executing smart contracts. Someone needs to execute, verify, and store transactions, and computation isn’t free. You need a way to incentivize miners to provide that computation for the network.

If miners are not incentivized, they won’t do the work, and the network will stall. Gas assets are necessary for an open-mining network to succeed. The network determines what the gas asset price would be for a smart contract transaction depending on supply and demand for the network’s processing capacity, among other factors. For example, during a new app launch or a popular NFT mint, the network can become congested, and some users might be willing to pay higher fees in order to have their transaction verified before others.

Open smart contract networks require gas assets to create healthy, open markets, and this is why Stacks has the STX token.

Gas fees help to prevent spam transactions from clogging up the network, and they provide miners with a rational reason to participate: they are compensated in the gas token for their computational work. The competitive pricing, in turn, leads to the emergence of a robust fee market, which is a sign of a healthy blockchain network. Open smart contract networks require gas assets to create healthy, open markets, and this is why Stacks has the STX token. As a side note, without a gas asset, it is still possible to create a functioning network in a closed-federated system, but that brings its own risks. In that scenario, you enter a centralized model, and there are security risks that come with that.

Three Key Benefits of Bitcoin Smart Contracts 

Bitcoin is the most secure and decentralized blockchain network in the world right now — it has never been hacked, and the financial resources required to pull off a successful attempt make such an endeavor unfeasible. Beyond this battle-tested security, below are three key benefits of Bitcoin smart contracts. 

1. Programmability

One of the big benefits that Bitcoin smart contracts deliver is they make Bitcoin programmable for developers. There is a ton of latent capital in Bitcoin with a market cap that currently sits around $800 billion; yet most of that Bitcoin is just sitting there, hodling. For example, less than $15B of that total is locked in DeFi. And most of that is wrapped Bitcoin on other blockchains as opposed to native Bitcoin DeFi. That’s changing.

Through Bitcoin smart contracts, developers can create new applications that allow users to do more with their Bitcoin than just hodl it.

Stacks enables Bitcoin smart contracts through the Clarity programming language. Clarity can read and react to Bitcoin’s global state, which means you can have native trustless swaps, from Bitcoin to other assets, all triggered by Bitcoin transactions on the Bitcoin blockchain. 

Clarity brings two additional strengths to the table worth mentioning here:

  1. Clarity is a decidable language, which means that the language is predictable and easier to reason about. This makes the debugging process of smart contracts easier for developers.
  2. Clarity is an interpreted language and is not compiled. By design the human-readable source code for every smart contract is available on the blockchain, effectively making the blockchain a ‘GitHub for smart contracts.’ This means any user can verify what a smart contract will do, and everything in the ecosystem is transparent.

Through Bitcoin smart contracts, powered by Stacks, developers can create new applications that allow users to do more with their Bitcoin than just hodl it.

2. Trustlessness

A smart contract’s most powerful feature is its trustless execution. Trustlessness in smart contracts means you don’t have to trust a third party, such as a bank, a person, or any other middleman, in your transactions. Instead, you trust the code. The trustlessness of smart contracts is one of the factors behind the growing popularity of NFTs in the art world where artists (and collectors) can ensure the digital scarcity of their work, authenticate their originality, and ensure perpetual residual income from the resale of such assets without a centralized intermediary.

However, for “trustless” systems to gain mass adoption, the system must be provably secure from manipulation. You still have to trust the code, and the underlying blockchain. This is where Bitcoin shines.

The Bitcoin network is open — anyone can contribute to Bitcoin and anyone can become a miner. Over the years, Bitcoin has grown to have a large, decentralized network of miners and developers globally. By design, it is practically impossible for miners or users to collude to alter Bitcoin’s state or ledger. This inherent immutability gives Bitcoin smart contracts a secure foundation. 

3. Cost-Effectiveness 

Bitcoin smart contracts are more cost-effective than smart contracts on Ethereum. Gas fees, which incentivize miners to confirm transactions and keep the network operational, are often astronomical on Ethereum, and can make small transactions not worthwhile.

So far in 2022, Bitcoin’s average transaction fees have reached a high of $4.46, while Ethereum’s average transaction fees have reached a high of $52.46, a striking difference of 1,076%. And because Stacks smart contracts settle on Bitcoin in batches, the individual fee for a Bitcoin smart contract is much lower on average than a transaction on Bitcoin (with a current average fee to date of .3 STX , or well under $1).

If you are building a Web3 app with lots of user transactions, it is logical to be concerned about the willingness of your users to pay high fees. If users are not willing to pay high fees, you will be sacrificing user adoption if you build your app on a blockchain with high fees. For developers who are concerned with the financial costs of running smart contracts, the Bitcoin network provides a cost-effective alternative. 

Harness the Power of Expressive Bitcoin Smart Contracts

Bitcoin has disrupted the world of finance by demonstrating how money can exist and function outside the direct control of governments and banks. Now, thanks to Stacks and the Clarity programming language, Bitcoin can extend its disruption as developers create fully expressive smart contracts to create new types of decentralized applications and use cases. Welcome to a future denominated in Bitcoin.

Looking for a home for your blockchain app? Download our free guide to Web3 ecosystems in 2022.

Download the Guide
Copy link
Hiro news & product updates straight to your inbox
Only relevant communications. We promise we won’t spam.

Related stories