Bitcoin Smart Contracts

What is a smart contract?

In the 90s, Nick Szabo coined the term "Smart Contracts" when describing the notion of a digital protocol designed to facilitate, verify, or enforce the terms of an agreement without the need for a third party, where the right inputs guarantee a certain output. The full possibilities of this protocol became a reality when blockchain technology emerged.

Smart contracts work by following simple "if/when...then..." statements that are written into code on a blockchain, meaning they are blockchain programs designed to run autonomously when predefined events or actions occur. There is no central authority necessary to run the software to function seamlessly: the terms of a smart contract are specified in code, thus eliminating the need for human intervention. Similarly to a vending machine, once you drop a coin in and select your option, a predefined automated routine is executed. Because the code is stored on the blockchain and cryptography protects all documents, the terms can't be tampered with. A blockchain-based smart contract is visible to all users of said blockchain, and all Bitcoin transactions recorded on the blockchain are considered on-chain transactions.

Bitcoin, created in 2009 when Satoshi Nakamoto minted the genesis block, was rarely a part of the discussion on smart contracts until just a few years ago. It has limited scripting language and prioritizes security over programmability, making it difficult for developers to work with the syntax. It was designed to be a decentralized cryptocurrency, leaving out smart contract functionality.

Stacks, formerly known as Blockstack, made bitcoin smart contracts possible, allowing developers to build Web3 dApps (decentralized applications) beyond Ethereum (ETH) and other blockchains, while enjoying the security of Bitcoin. Stacks functions as the smart contract layer for Bitcoin, through the Clarity programming language, enabling projects that can natively use BTC, unlocking immense value and helping the growth of crypto adoption.

What is a Bitcoin Smart Contract?

Like other smart contract platforms, Bitcoin smart contracts ensure trustless transactions, which settle on the Bitcoin network, making the history of transactions more durable through Bitcoin's proven security. The digital agreement (smart contract) is stored and executed across all nodes in the Bitcoin blockchain network, where it is given security and immutability.

There are various types of Bitcoin Smart contracts. Script is useful for powering the Bitcoin network but isn't Turing complete, which means it doesn't allow for logical loops. This keeps the Bitcoin network safe from DoS attacks. Bitcoin's most popular script type is Pay-to-Public-Key-Hash (P2PKH). P2PKH scripts allow bitcoin to be sent to a Bitcoin address, such that only the owner of the corresponding private key can spend the bitcoin. Bitcoin's Taproot upgrade will introduce a new script type called Pay-to-Taproot (P2TR), which will unite the functionality of P2PKH and P2SH scripts, allowing bitcoin to be sent to both a public key and arbitrary scripts. More custom smart contracts can be built on top of Bitcoin, like multisignature accounts, payment channels, escrows, time locks, oracles, and more.

All of the above are executed on Bitcoin's blockchain as regular Bitcoin transactions. However, bitcoin can also be spent and used to power smart contracts on additional layers, such as the Lightning Network, which relies on multisignature transactions called Hashed Time-Locked Contracts (HTLCs) to enable instant and nearly free Bitcoin payments. It is only one of many protocols that allow bitcoin to be transferred off-chain. Others, such as the Liquid Network, side chains, and state chains, also rely on Bitcoin's smart contracting ability to enable even more use cases.

Stacks smart contracts offer many benefits including transaction fees that are much lower on the Bitcoin blockchain than on the Ethereum blockchain; trustlessness and immutability, as well as unrivalled security. While the Ethereum blockchain uses the Solidity programming language, Stacks uses Clarity, which offers transparency and scalability.

Stacks enables developers to write fully expressive smart contracts, allowing the creation of new types of apps, use cases, NFT marketplaces and DeFi apps such as Arkadiko, which enables users to take out a self-repaying loan in USDA (a stablecoin) that is backed by their STX tokens, or InfinitySwap, where you can transfer your BTC directly to another Bitcoin address to enter a liquidity pool.

NFTs such as music, collectibles, arts and even real estate can be minted through the Bitcoin ecosystem on NFT marketplaces such as Gamma, the largest NFT marketplace on Stacks.

Related articles: