Guides

Smart Contracts explained

What is a smart contract? A smart contract is one of the key terms when it comes to cryptocurrencies and blockchains. It is essentially a piece of program code stored on a blockchain. This article has smart contracts explained. We’ll go through all the key features of these distributed programs.

Blockchain and various cryptocurrencies

In order to understand smart contracts, you must have at least a basic level understanding of blockchains.  In short, a blockchain is a distributed ledger. The English abbreviation DLT says it all: Distributed Ledger Technology. Blockchains are databases of cryptocurrencies and store the transaction data that is being sent in the network.

There are different types of blockchains. Bitcoin was born already in 2009 and has a blockchain with very different capacity compared to its 3rd generation rivals. Bitcoin’s blockchain needs to be also maintained with physical mining devices, which is no longer needed in the high capacity blockchains.

There are also different types of cryptocurrencies. The best way is to split them into three main categories: platforms, tokens, and currencies.

blockchain smart contract

Platforms are also called ecosystems or Dapp operating systems. The best-known example of a platform is Ethereum. Its main rivals are EOS, TRON, and Tezos. These cryptocurrencies are designed to support Dapps and smart contracts.

Tokens are always created inside of such platforms. Hence, they don’t have their own blockchains. Tokens have usually utility inside a specific program.

The currency category includes Bitcoin and its rivals (Litecoin, Bitcoin Cash, Digibyte). However, be careful of making a claim that Bitcoin doesn’t support smart contracts at all. Some things can be built also on top of Bitcoin, but it really isn’t designed for that.

The development of Bitcoin is progressing slowly and its key features are almost impossible to change. Hence, many 2nd generation platforms were born and designed in 2014-2016 to support the programming of smart contracts and Dapps.

In this article, we are studying smart contracts through Ethereum. It is the best-known platform and therefore a natural choice.

What is a smart contract?

The term smart contract is, in fact, quite misleading. This component isn’t especially smart and it isn’t necessarily a contract either. You often see smart contracts explained as “programmable contracts stored on a blockchain”. Giving only such a view would be just lazy.

A smart contract is simply a piece of code written by an Ethereum developer in Solidity language. This is a programming language designed for the task. Other platforms have their own languages or they support some of the existing ones.

Below you’ll find a simple example of a code written in Solidity (source).

solidity example

When the program is finished it must be compiled into bytecode. This is the format Ethereum Virtual Machine (EVM) understands.

EVM is a program stored on every node of the Ethereum network. Its task is to process the smart contract code and push out the desired actions or outcomes. Many of the readers might remember downloading the Java Virtual Machine (JVM). We are talking about a similar program.

If you have created a smart contract you don’t just throw it out on the Ethereum MainNet. This is what the TestNet is for. You can try the program code without risk of losing real cryptocurrency (Ether).

There is also an important reason why the TestNet is used. Once a smart contract is published on the blockchain it cannot be changed. There is no undo or admin command to change a smart contract afterward. If there were, the whole idea of an immutable contract would disappear.

When a smart contract gets a command, Ethereum miners step in. Smart contracts are being processed every time a new block is being created onto the Ethereum blockchain. This means each miner node has a copy of each smart contract and they run it in their EVM.

This means that each miner will always get the same outcome as well. It is not possible that there would be different versions of a smart contract (or the EVM) on the blockchain.

Smart contracts explained – Ethereum accounts

Let’s take a few steps deeper. Now you have learned that a smart contract is simply a program code, which is run by Ethereum miners. It is only as smart as the developer is who created it and not necessarily a contract.

Smart contracts are enabled through Ethereum’s account model. For example, Bitcoin is using a UTXO model and has no user accounts – there are just addresses and transactions. Ethereum works differently. There are two types of accounts: an EOA (Externally Owned Account) and a Contract Account.

An EOA is a user-controlled account. Access is granted through users’ private key just like in Bitcoin. An EOA has an Ether (ETH) balance and it can send & receive transactions. There is no program code attached to it and it doesn’t cost any ETH to create one.

private key

A contract account can be also called a smart contract account because it is, in fact, a smart contract. Such an account has also an Ethereum address like EOA accounts as well. A contract account can also send & receive transactions, which can be Ether or other information.

The big difference is that it is not free to create or use a contract account. Every line of program code that EVMs must process eats computing power of the network. Therefore, program developers must pay a fee. This is called gas.

The more complex programs (smart contracts) you build, the more gas is required. This makes sense, right? It also limits spamming or other malicious use of the network.

When we talk about the Ethereum platform, gas is paid in Ether (ETH). There are some platforms, which have created another token for this purpose, named also gas. For example, NEO has its native NEO token and also a separate gas token, which both can be bought from cryptocurrency exchanges.

Smart contracts explained – Dapps and features

Hopefully, you The Reader, are beginning to understand smart contracts by now. When we are talking about this subject it’s impossible not to mention Dapps meaning Distributed Apps. How are they related to smart contracts?

Dapps are applications just like traditional apps as well. It can be a desktop app, mobile app or a web browser app. Dapp is a larger program with its own GUI and operations. A smart contract is basically a component inside a Dapp.

dapps

Smart contracts have several key features, which have been mostly covered already. Let’s list them all here:

  • Smart contracts are open source programs
  • The program code is stored on a blockchain
  • The program code cannot be changed once it’s published
  • A smart contract is executing all commands automatically
  • The program code, logic, and results of a smart contract are visible to all
  • Smart contracts cannot be altered or stopped from running

A smart contract is a distributed program stored on a blockchain, which is open for all, immutable and secure at the same time.

Of course, anyone could build their own private blockchain, which is controlled by a centralized entity. If the network is not truly distributed, it ruins the whole idea of a blockchain and smart contracts. Why wouldn’t you then use a traditional database and programs instead?

Real-life examples of using smart contracts

Let’s go through some of the real-life examples of smart contracts. How they can be used and executed?

Investing

The easiest example is trading or commerce. We can talk about selling or buying a house, a car, a bunch of stocks or any other financial instruments. This is where you often see the term tokenization, which means converting real-life objects on a blockchain.

Think about your car, for example. The ownership history is currently stored in a centralized database. In the future, it could be in the blockchain and you could have the ownership of your car in a token format.

If you want to sell your car, it could be done through a smart contract. When a desired amount of Ether would be sent to a certain smart contract, it would change the ownership automatically and move the car token to a new person.

Prediction markets

Prediction markets are already using smart contracts. Traditionally, these markets have been dominated by centralized entities, which leave little or no room for complaints in case of errors.

smart contracts prediction market

There are already online platforms, where betting is done P2P on the blockchain. This could be the way of the future. All prediction markets could be blockchain-based, and results would be always 100% accurate and payouts automated.

Smart contracts could help to remove the middleman in the betting industry.

Insurances

Insurances are often used as examples of how smart contracts could revolutionize the world we know. There are cases all the time, where the insurance company refuses to pay claims to the person thinking he was be covered.

With smart contracts, there would be no arguments or lawyers needed. All terms of the insurance would be stored on the blockchain, where they are visible to all parties and immutable. If something happens, the smart contract would be triggered automatically.

ICOs

The crypto boom of 2017 was so huge thanks to ICOs, which helped to boost Ethereum and all tokens created inside the platform. An ICO is crowdfunding done in the crypto world. A new project raises funds by selling part of their tokens to the public.

Smart contracts are used in ICOs all the time. If you want to participate in an ICO, you simply send Ether to a given address. A smart contract is then triggered and it will send you back X number of new tokens.

General

In general, there are endless uses for smart contracts. You can think about it like this: any situation where a contract is needed between X and Y to purchase an item. All real-life instruments can be tokenized onto a blockchain and managed with smart contracts.

The benefits are obvious: savings in costs, speed, and reliability. This is, of course, only IF the smart contracts are stored on a truly decentralized blockchain.

Smart contracts help to remove the middlemen from any financial process. This makes the whole process faster, simpler, and more reliable. There is no more room for a human error and each party can be always sure that the desired outcomes are performed.

Oracles and Chainlik

Let’s go quickly through oracles as well, which are important components in the blockchain world.

The big limitation of a smart contract is that it cannot access any outside information by default. It can only operate with the information that is on the blockchain. For example, you cannot program a smart contract to fetch weather information, football results or stock prices.

This is why there are oracles, which provide data feeds from the outside world. There lies a problem, though. If your smart contract is using an oracle provided by a third-party, the decentralization benefits are instantly gone.

An oracle feed could contain false information or the whole oracle could be out of action. This would jeopardize the whole smart contract. This is the problem Chainlink will solve.

chainlink api

Chainlink has created a distributed network of oracles with incentives for each oracle to provide 100% correct information all the time. This is essentially a software built on Ethereum, but it will expand in the future to other platforms as well.

Chainlink has also SWIFT as a partner, which enables linking the fiat world with smart contracts. Keep an eye on this project!

Overview: what is a smart contract?

This article explained the true nature of smart contracts. As you have understood now, the whole term smart contract is misleading. There is nothing “smart” or “contracts” built into it. A smart contract is simply a program code that can be told to process all kinds of tasks. It is only as smart as the developer, who created it. It is not necessarily a contract either – it can do anything, really!

There are currently several platforms created to support smart contracts and Dapps. Ethereum is the best-known one, but EOS, TRON, and many others offer similar support. It’s important to understand that the benefits of smart contracts come from a truly distributed environment. If a blockchain is controlled by a simple entity and therefore centralized, the whole concept loses its meaning.

The oracle problem is also a very important one to comprehend. Smart contracts need oracles in order to access the outside world. Oracles must be also decentralized and distributed to make sure the smart contract information is not corrupted.

2229   btrz ancient egyptbtc 728x90 en

What is your reaction?

Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0

You may also like

Comments are closed.

More in:Guides