Smart contracts

## What is a smart contract

A smart contract is a program that is kept and executed on a blockchain. The results of executing smart contracts are verified and confirmed by many nodes of the network, thus ensuring end-to-end decentralization, as well as the stability of calculations to errors and malicious attacks.

This puts smart contracts in contrast to centralized systems where the results of execution are stored and verified by a single server or a distributed server network controlled by the same entity. In a centralized architecture, users cannot independently verify the correctness of their interaction with the system and perform calculations on their own, which makes centralized IT systems unsuitable for executing smart contracts.

Blockchain networks that are suitable for running smart contracts can be classified in a multitude of ways. One of the most important distinction is between public and permissioned blockchains. In public and permissionless networks such as Free TON, anyone can become a validator and participate in the network's consensus model and transaction verification. In permissioned networks, also called consortium blockchains, all transactions are validated by a rigid set of validators. This improves the scalability of the network and makes the reversal or retroactive alteration of transactions possible, but makes the blockchain partially centralized.

The use cases for smart contracts include:

* Communal wallets that track each depositor's funds (tokens) and allow for the automatic allocation of funds according to the internal smart contract logic.
	+ Multisig wallets with multiple owners who can only make transaction when a minimum number of owners agree.
* Voting, vote counting and decision-making in decentralized organizations.
* Cooperative staking funds (e.g. DePool).
* Decentralized Finance ("DeFi") - programs that implement secure financial services without intermediaries.
	+ Lending markets that allow for the collateralized lending of crypto assets.
	+ Synthetic assets that have their value pegged to another crypto asset, fiat asset, or commodity (e.g. derivatives, stablecoins).
	+ Decentralized Exchanges ("DEXes") that allow the instant swapping of crypto assets.
	+ Vaults that use a predefined investment strategy, allowing depositors to earn a passive income.
	+ Decentralized insurance protocols that automatically issue a payment against the proof of a damage case.
* Decentalized games
	+ Programs that implement simple game mechanics (chess, dice, etc.).
	+ Peer-to-peer gambling (e.g. PokerTON).
	+ Ownership of in-game assets as Non-Fungible Tokens (NFTs).

## The origin of smart contracts

The first concept of smart contracts was proposed by the American cryptographer and programmer Nick Szabo, who developed the concept in order to use advanced methods of contract law in e-Commerce protocols on the Internet. Szabo presented the concept in 1996.

According to Szabo's definition, a smart contract (intelligent contract) is a digital protocol for transmitting information that uses mathematical models to automatically execute a transaction after certain conditions are met and complete control of the process. Practical implementations became possible due to the advent of blockchain technology (with the introduction of Bitcoin in 2008). Some of the principles of smart contracts were already laid down in the first Bitcoin Protocol, but were not implemented in client software, did not have Turing completeness for security reasons, and were not widely used in practice.

This implementation does not allow the Bitcoin blockchain to set conditions for making a transaction in a new block, since it contains only information about the transaction itself. There have however been suggestions that various protocols of a higher level can be created on top of the Bitcoin protocol, including full-fledged support for smart contracts, just as there are many application-layer protocols on top of TCP/IP.

Smart contracts first became widespread with the development of the cryptocurrency industry, in particular the appearance of the Ethereum blockchain. The idea of creating a Turing-complete smart contract platform firstly came up in 2013. At that time, the founder of Bitcoin Magazine, Vitalik Buterin, came to the conclusion that blockchain technology can be used for many other purposes besides cryptocurrencies. He put forward the idea of a universal decentralized blockchain platform, in which anyone can programmatically implement different systems for storing and processing information. The main condition is that actions must be described as mathematical rules.

## Free TON smart contracts

In the Free TON network, the implementation of smart contracts is conceived in a universal way. As a result, all wallets and the implementation of any additional logic in general, is a smart contract, unlike many other blockchains of previous generations. Also, all interactions between smart contracts are asynchronous (unlike, for example, Ethereum), which is essential for scaling the network performance.

An important property of the Free TON network is that any actions of the network to process a smart contract burn a small number of tokens, which is a protection against abuse and DDoS attacks. As a result, it quickly becomes very expensive and unprofitable for the attacker to create a sufficiently high workload for a DDoS attack.

There are several system smart contracts in the TON network:

* a validator elector;
* Referral Giver - new members funding wallet;
* Validator Giver - validators funding wallet;
* Developer Giver - developers funding wallet.

The following smart contracts created by TON Labs are also distributed in the FreeTON network:

* SafeMultisigWallet is a smart contract that implements a multi-signature wallet;
* SetcodeMultisigWallet is a more "advanced" version of SafeMultisigWallet which supports changing keys and even its own code.

az:Ağıllı\_Müqavilələr
be:Смарт-кантракты
bg:Интелигентни договори
de:Smart Contracts
el:Έξυπνα συμβόλαια
fa:قراردادهای هوشمند
fr:Contrats intelligents
hu:Intelligens szerződések
id:Kontrak pintar
it:Smart contracts
lv:Smart-kontrakti
pt:Contratos inteligentes
ru:Смарт-контракты
tr:Akıllı sözleşmeler
uk:Смарт-контракти