What’s a smart contract? | How Do Bitcoin and Crypto Work? | Get Started with Bitcoin.com

A smart contract is a computer program that is stored and runs on a decentralized ‘trustless’ network, such as a blockchain. By trustless we mean that the validity of information in the network can be verified by anyone. Many people think smart contracts only apply to newer blockchain networks like Ethereum, but Bitcoin also uses smart contracts, albeit with limited functionality.

Ethereum was originally conceived in part as a way to generalize Bitcoin’s smart contract functionality. Thus, the Ethereum network is a ‘Turing complete state machine,’ which is an academic way to say it is a general-purpose computer that is also decentralized. Such a network’s smart contracts can conceivably “compute” anything a program on a normal computer can. This means that the network can, in theory at least, host a messaging app, a video game, or even an entire social media platform. However, in their current state, decentralized networks are severely limited in the types of applications they can support, with speed and cost being the main limiting factors. We go into this in more detail in our Blockchain Trilemma article. It’s also important to note that Ethereum was only the first of many networks to create a general-purpose decentralized computing machine.

Why would someone choose to deploy a smart contract on a decentralized network over a centralized, cloud computing network such as Amazon Web Services (AWS)? Cloud computing, after all, is much faster and cheaper than its decentralized counterparts. The answer is that centralized networks make important trade-offs for their speed and cost.

Since smart contracts exist on a decentralized trustless network, they provide a greater guarantee on the fair execution of programs. For example, you must trust your bank to faithfully execute your online bank transactions. Even if the bank is trustworthy, perhaps an employee in the bank is malicious, a hacker has penetrated the bank’s network, or the computer hardware itself is faulty. Not to mention you have almost no direct way to audit the bank’s transactions, let alone the software they are using. Smart contracts and the decentralized networks they live on greatly reduce the need for these trust assumptions.

For many use cases, the benefits of transparency, trustlessness, and guarantees on execution integrity are not needed. For example, a program that models weather, or an air traffic control monitoring program would likely gain very little benefit from smart contracts, and would incur heavy penalties in terms of speed and cost. However, for many use cases that involve money or property, the tradeoffs of speed and cost are likely worthwhile. For example, a digital trading card game, an asset exchange, or a program to send and receive cryptoassets.

Mục lục bài viết

How smart contracts work

Decentralized trustless networks such as Ethereum can be thought of as a shared computer, with smart contracts being the software programs that run on the shared computer. Developers write smart contracts in a programming language, then deploy them to the shared computer. When you deploy a smart contract to the “computer,” what you’re actually doing is registering a special address on the network. Anyone can interact with a deployed smart contract by sending that network’s native token to the contract address. In the case of the Ethereum network, you would use ETH. This triggers the code in the contract to be executed according to its logic. The code is executed automatically along the ‘if this, then that’ model just like any other programming language.

For example on the Ethereum network, a simple smart contract could be written such that when you send 1 ETH to it, your 1 ETH is divided up into 12 equal pieces, each of which is sent to a specified address at one-month intervals. This would effectively create something similar to a trust fund.

For use cases that exist entirely in the digital world, smart contracts allow people to bypass intermediaries altogether. For instance, in our above “trust fund” example, we’ve effectively eliminated the need for lawyers and managed escrow accounts. Instead, we simply send ETH to the contract and rest assured that it will be sent to the trust fund recipient exactly as the contract states and without any need for further input.

Smart contracts are being used in much more complicated ways to create Decentralized Applications (DApps) to do things such as allow the permissionless exchange of crypto assets, or even games with digital property the players can truly own.

Read more: What’s a DApp?