16/05/2020
Essay / Crypto

Smart contracts for laymen

This is the second part in a series introducing people to blockchain technology and its offerings. If you haven’t read the first part yet, check out “Blockchain for laymen”.
Introduction
In 1994, a computer scientist, Nick Szabo, proposed the idea of being able to create and perform contracts digitally, without the need of an intermediary watching over the parties involved in the contract. This type of contract would be activated automatically when certain conditions were met.

What differentiates a digital contract with a traditional one? Guarantee of records.

And what benefit would a smart contract add over a digital contract? Removal of middle-men.

With smart contracts, you would no longer need trusted third parties while conducting a monetary or non-monetary interaction with each other (transactions, deals, time-locks, employment, etc.).

What makes a digital contract “smart”? Self-execution + Consensus.

The contracts are deployed and facilitated on/by a network, unlike basic digital contracts which would be hosted on a centralised server or facilitated by a trusted intermediary. This network that runs the contracts would follow a set of rules on how they agree on things. These rules are what you would call ‘consensus’ protocols. Instead of needing a middle-man verifying the validity of interactions in a contract, the network would validate them. This validation process is where those rules come into play. The reason smart contracts are considered self-executable is because the participants on the network don’t manually validate and perform the contracts. The contracts are executed automatically by their computers, phones, or any other digital equipment that verify the validity of the conditions being met.

"If the idea was proposed over 2 decades ago, why wasn't it implemented?" Szabo worked on this idea for many years and even wrote a book called “Smart Contracts: Building Blocks for Digital Free Markets“, but back in 1994 this was only possible in theory and not practically feasible as the concept of consensus protocols was non existent. Until 2009, when a pseudonymous entity going by the name, Satoshi Nakamoto, introduced Bitcoin. Bitcoin itself wasn’t the solution to make smart contracts feasible, but its underlying technology was. That underlying technology was Blockchain. Blockchain brought us the missing component of consensus, which is why we have so much hype surrounding it. It didn’t just bring us bitcoin and other cryptocurrencies but enabled all the usecases that smart contracts could bring.

The primary component that differentiates smart contract networks like Ethereum from networks like Bitcoin is smart contracts. Bitcoin is a single-purpose network with its focus on electronic peer-to-peer money. Ethereum, being a general-purpose platform, would be able to facilitate that usecase with a single smart contract.

The term ‘smart contract’ is a bit misleading in the sense that it would make you believe that they have something to do with the law or legally binding agreements. Let’s get this out of the way — They have nothing to do with the law. They are just pieces of code (or machine logic) that can run on Distributed Ledger Platforms (like Blockchain).
Components of a smart contract
Smart contracts are held on their platforms as accounts, similar to the ones you would have on those platforms but with additional components.

A user account is just
- An address
- A balance

A smart contract account has:
- An address
- A balance
- A state
- Code

The address — Unique identifier for the account.

The balance — assets held in the account (also the same thing as a user account). The cool thing here is that code can hold and manage money.

The state — current state of all fields and variables declared in the smart contract. As mentioned in the previous article, this refers to the values held in the cells on the ledger underlying the blockchain in question.

The code of the smart contract is compiled byte-code that the blockchains clients and nodes can run. It is the code that is executed on the creation of the smart contract, and it contains functions that you can call. This code runs on what you would call a ‘virtual machine’. More on virtual machines in a separate article.
In action
Smart contracts potential goes beyond the simple concept of ‘tokens’, they can execute interactions/transactions in a wide range of fields, from legalities and insurance premiums to fundraising and derivatives. Smart contracts have the potential to disintermediate functions pertaining to trusted middlemen, let alone entire industries. They achieve this by simplifying, automating and assuring processes for which people currently pay entities like lawyers and banks.