Everything you wanted to know about smart contracts, their essence, types, features of creation, and practical application.
What is a smart contract in simple terms
Today, smart contracts (smart contracts, intelligent contracts) are on the lips of everyone who is interested in blockchain and cryptocurrencies in one way or another.
In simple terms, a smart contract is an algorithm that allows assets to be exchanged when clearly defined conditions are met, without intermediaries.
In other words, it is a program that performs certain actions in response to the fulfillment of specified conditions (according to the “if…then…” scheme).
Why “smart”?
Different views on the essence
Since then (and that was in the 1990s), many have been working to unlock the potential of smart contracts, both in theory and in practice.
Here are some more modern definitions of a smart contract:
- A computer algorithm designed to generate, control, and provide information about ownership of something. Most often, this refers to the use of blockchain technology (Wikipedia).
- A legal contract or element thereof that is represented or executed by software (legal perspective).
- a piece of code, a computer algorithm created to perform specific tasks when predetermined conditions are met (technical definition).
In principle, these definitions do not contradict each other; they simply view the subject from different angles. Let’s not get bogged down in theoretical discussions and consider smart contracts as a blockchain-based technology.
A bit of history
Nick Szabo viewed a smart contract as a computer protocol that uses mathematical algorithms to independently conduct transactions, fully controlling the fulfillment of obligations. At the time of its invention, the necessary infrastructure did not exist to bring it to life.
Bitcoin smart contracts
With the spread of blockchain, this idea gained practical significance. Some of the principles of smart contracts were implemented in the Bitcoin protocol.
Initially, the Bitcoin protocol was not intended as a smart contract protocol, but only for transferring the simplest data (transaction inputs and outputs, detailed in the article).
However, it is still possible to perform the simplest logical operations on the Bitcoin blockchain and actually create several variants of smart contracts that do not have Turing completeness (the language of smart contracts is Script; examples of such algorithms are given below).
Turing completeness is an important parameter of a smart contract in a blockchain. It is the ability of a smart contract to implement any computable function, which is achieved by the infinite nesting of some contracts within others and/or special “computational” blocks.
Examples of smart contracts on the Bitcoin blockchain:
- Escrow — a third agent’s signature is required to use the funds.
- Multisig — a transaction can only be completed after several persons from a specified number of contract “owners” have signed it; the number and addresses of participants are determined in advance when such a wallet is created.
- Bequest — if the wallet is inactive, the heirs receive the funds (more precisely, the owner of the address can spend at any time, but the heirs can only spend the funds from the wallet after a block with a specific date; each new transaction sends the change with an extension of this period).
- Safe — funds are not accessible until a certain date.
- Atomic swaps and payment channel creation scripts — layer 2 and decentralized exchanges.
Due to the complexity of implementing more complex logic in the Bitcoin blockchain, there was a need to develop new platforms.
Ethereum smart contracts
Vitalik Buterin assessed the potential of smart contracts and the shortcomings of BTC at the time. He developed the Ethereum platform, which allows the creation of Turing-complete smart contracts.
The main differences are the Solidity programming language and the ability to store state information in the blockchain (statefulness). In other words, the Ethereum network perceives each transaction as part of the system, while Bitcoin perceives it as completely separate.
Ethereum also offers the ability to create smart contracts for generating tokens. The most common token is the ERC-20 standard. This standardization has simplified interaction between wallets, projects, exchanges, etc.
Today, many projects are developing their own platforms for smart contracts (Tron, NEO, EOS, Hyperledger Fabric, Aeternity, Waves, Ontology, VeChain, Stellar), which differ in terms of consensus algorithm, throughput, transaction processing cost, and functionality.