What is a Smart Contract?

A smart contract is a piece of code that can be executed automatically and in a deterministic way. The smart contract code is usually stored and executed on the blockchain to make it trustless and secure. Smart contracts also have capabilities of receiving, storing and sending funds and even calling other smart contracts. They follow if-then semantics which makes them fairly easy to program.

Smart contracts aim at removing the human factor from decision making. The human factor is often proven to be the most error-prone and unreliable element of the standard, traditional contracts.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/31f16e39-ed05-47c0-a9ec-2c10e58b14d6/Untitled.png

A vending machine comes very often as a good analogy to a smart contract as it shares some of the similarities. A typical vending machine is programmed in a way that allows certain actions and state transitions based on the input. It also works in a fully deterministic way. For example, if you want to buy a can of coke that costs $2 and you only have $1 no matter how many times you try you won't be able to get the drink. On the other hand, if you insert $3, the machine will give you a can of coke and appropriate change. Even the change that is given is selected in a predefined and programmed way based on which coins are available and which coins the machine wants to get rid of first.

A smart contract can rely purely on the information available on the blockchain, for example, if you give me 10 tokens A, I'll give you 10 tokens B (assuming both tokens are available on the same blockchain) or it can rely on external data sources, for example on the Ethereum or S&p500 price. The latter example makes smart contracts more difficult as they have to trust real-world data. The needed trust can be minimized by using oracle services, but even the oracle services have to be trusted. There are already a few projects that by using certain incentives make oracles more likely to provide correct data. Chainlink is a project that clearly stands out in this category.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/7f761195-b12a-4ead-8e4e-3e802c6e9a19/Untitled.png

Ethereum is a good example of a blockchain that supports smart contracts and make it possible for a programmer to implement their own smart contracts. A smart contract can be written in a programming language called Solidity which was created specifically for that purpose. In Ethereum, all the deployed smart contracts are immutable. This means that once deployed they cannot be modified which creates certain risks that we're going to discuss later. Smart contracts on Ethereum are also decentralized which means there is no single machine controlling the contract. In fact, all the nodes of the Ethereum network store the same contract with exactly the same state.

Although Ethereum is currently the most popular general-purpose smart contract platform, it is not the only one and it has a few competitors. Some of them are Cardano, Tezos, EOS, Tron, but not all of them share the same characteristics.

Smart Contracts vs Traditional Contracts

To see the benefits of smart contracts, let's compare a hypothetical smart contract to its equivalent in the traditional space.