What is a Smart Contract?
How does a smart contract work?
In the 90s, computer scientist and cryptographer 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. The full possibilities of this protocol became a reality when blockchain technology emerged.
A common example to describe how smart contracts work is that of a vending machine. Smart contracts work by following simple "if/when...then..." statements that are written into code on a blockchain, meaning they are self-executed computer programs designed to run autonomously when predefined events or actions occur: with the right inputs, a certain output is guaranteed. The terms of a smart contract are specified in code, thus eliminating the need for human intervention, intermediaries or a central authority and leveraging objectivity and automation.
Similarly to the vending machine we used as an example, 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 code is visible to all users of said blockchain. Smart contracts are immutable: their definition (bytecode) cannot be changed or updated once they are deployed on the blockchain.
Many platforms now allow for the use of smart contracts, including Ethereum, Hyperledger, Tezos, Stacks and Cardano.
Ethereum smart contracts
Ethereum was initially described in a white paper by Vitalik Buterin in 2013 where he imagined a way to build dApps (decentralized applications) and other applications besides money. Buterin argued to the Bitcoin Core developers that Bitcoin and blockchain could benefit from these suggestions and a more robust programming language, but an agreement on how the project should proceed was not found. Vitalik Buterin then proposed the development of a new platform with a Turing-complete programming language, which eventually became Ethereum, officially launched in 2015.
Ethereum smart contracts have led to the network's array of decentralized applications (DApps), DAOs, new technologies and other use cases such as NFT marketplaces that enable buying and minting digital assets like collectibles, art, music and even access to real-world items.
The Ethereum network exists on thousands of computers worldwide, thanks to users participating as nodes, making the network decentralized and highly immune to attacks. Anyone can run an Ethereum node and participate in validating the network provided they have the right hardware, knowledge and time to commit to it. Ethereum runs a computer called the EVM (Ethereum Virtual Machine). Each node holds a copy of that computer. Any interaction (also called transaction) must be verified so that every node can update their copy. Each Ethereum transaction is stored within blocks. Every new transaction is recorded on a new block, which is connected to previous and future blocks in a chain.
On the Bitcoin blockchain, only the owner of a Bitcoin private key can produce a digital signature proving that they own the cryptocurrency they claim to own. In contrast, ETH has developer-friendly languages for writing smart contracts such as Solidity. The Ethereum network is "Turing-complete," meaning it supports a broader set of computational instructions. Without limits, programmers can write just about any smart contract they can think of.
Although smart contracts are often associated with the Ethereum blockchain, the world's second-largest crypto by market cap, the idea isn't restricted to any particular platform or blockchain network. Every blockchain uses different templates, algorithms and encoding techniques.
Bitcoin Smart Contracts
The Bitcoin blockchain is a digital, distributed ledger of transactions across the blockchain's network of computer systems. It aims to decentralize financial services and allows users to be in full control of their digital currency, with no third party needed. It has limited scripting language and prioritizes security over programmability, making it difficult for developers to work with the syntax.
While Bitcoin (BTC) was the first cryptocurrency to support basic smart contracts, it was rarely a part of the discussion on smart contracts until just a few years ago. 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.
Stacks, formerly known as Blockstack, made bitcoin smart contracts possible, allowing developers to build Web3 dApps beyond Ethereum and other blockchains, while enjoying the security of Bitcoin. Stacks functions as the smart contract layer for Bitcoin, bringing the benefits of smart contracts, trustlessness and immutability, to the Bitcoin blockchain.
Stacks uses the Clarity programming language, which offers transparency and scalability and enables developers to write fully expressive smart contracts, allowing the creation of new types of apps, use cases, NFT marketplaces and DeFi apps. 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.
Clarity is an open-source, decidable language, meaning you can know with certainty what the program will do. It gives developers a safe way to build complex smart contracts for the world's most secure blockchain. Being human-readable, the programming language also makes it easier for developers to detect vulnerabilities and potential bugs.
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.
Smart contract use cases
NFTs are one of the most popular smart contract use cases. $17 billion worth of these digital assets were traded in 2021. If you'd like to learn more about Stacks NFTs secured by Bitcoin, head over to Stacks' largest NFT marketplace, Gamma.io.
DeFi (decentralized finance) has also grown to be more than peer-to-peer transactions, with many blockchain platforms and startups diving into it. Smart contracts and cryptocurrencies have allowed sophisticated transactions to take place and DeFi platforms to provide financial services without the need for a third party.
Supply chain management is another example of potential use of smart contracts.An item's location can be tracked in real time with the help of IoT (Internet of Things) sensors and smart contracts, with full visibility and transparency.
Smart contracts can also be useful for platforms where money needs to be held in escrow, to ensure that the funds are sent to a wallet or bank account at the right time.
DAO governance also relies on smart contracts to define a set of rules for the DAO, and how community votes are counted. For example, you could need to own a number of crypto tokens, or hold a specific NFT, to have a say in the DAO's future. This would be specified in the smart contract.
If you're curious to learn more about the above use cases and more, head over to this article.