paint-brush
Blockchain for non-techies: 3. Smart contractsby@williamrode
11,786 reads
11,786 reads

Blockchain for non-techies: 3. Smart contracts

by William RodeJune 9th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

<em>This is the third post in a series on blockchain technology, where I give a non-technical introduction. In the </em><a href="https://hackernoon.com/blockchain-for-non-techies-1-agreement-4a54857b82ba" target="_blank"><em>first post</em></a><em> I focus on agreement, and in the </em><a href="https://hackernoon.com/blockchain-for-non-techies-2-how-they-work-2f94d313c7e5" target="_blank"><em>second post</em></a><em> I explain how blockchains work.</em>

Company Mentioned

Mention Thumbnail
featured image - Blockchain for non-techies: 3. Smart contracts
William Rode HackerNoon profile picture

This is the third post in a series on blockchain technology, where I give a non-technical introduction. In the first post I focus on agreement, and in the second post I explain how blockchains work.

Smart contracts are an important part of the enthusiasm surrounding blockchain technology, so in this post I will explain what a smart contract is. But first, let’s quickly recap of the magic analogy I use in my previous post to explain a blockchain. A public blockchain can be imagined in the following way:

  • An identical agreement is written on a set of enchanted documents
  • Anyone can take part in maintaining this agreement by owning one of these documents
  • Rules describe the changes you are allowed to make to a document
  • Any valid change to one document is automatically made to all the other documents

These properties result in each participant owning an identical copy of the same agreement, even though the agreement undergoes continuous change.

The magic analogy above describes one set of enchanted documents (blockchain) that follows one set of rules. Different sets of enchanted documents have different rules for what changes are valid. The original set of enchanted documents is called Bitcoin, the rules for this set of documents are:

  1. Each enchanted document contains a list of all accounts and balances.
  2. People own accounts, and can send their own bitcoins to other accounts.

In essence, these rules create a digital cash. Below is an illustration of one of the enchanted documents maintained across the Bitcoin network. The number next to each account denotes the amount of bitcoins in that account.

Another set of documents is called Ethereum. The enchanted documents that make up Ethereum follow very similar rules to Bitcoin:

  1. Each enchanted document contains a list of all accounts and balances.
  2. Owners of accounts can send transactions to other accounts.

Those of you with an eye for details might have noticed slight differences in wording between the second rule of Ethereum and the second rule of Bitcoin. The difference is that some accounts on the Ethereum blockchain are not controlled by people. Instead, the actions of these accounts are controlled by a set of instructions residing on the accounts.

Below is an illustration of one of the enchanted documents on the Ethereum blockchain. In the illustration, the accounts B, E and G are controlled by instructions and not people:

When a set of instructions reside on one of these accounts it is called a smart contract. The instructions are just computer code, essentially just logic. If “poked” by a transaction from another account, the smart contract can:

  • Perform calculations
  • Store information
  • Send transactions to other accounts

As mentioned, the account with the code is not controlled by any person, it is completely autonomous! The original code is written by a person, but once the smart contract code is uploaded to the blockchain, only the logic in the account dictates the actions of that account.

Many people are critical of the name “smart contract”. One reason being that a smart contract is not necessarily smart. It is just a set of instructions that anyone can write, and people are very capable of creating some pretty dumb smart contracts.

The name smart contract is also misleading because it is not really a contract, at least not in the sense that it’s anything that needs to be complied with or upheld. A normal contract has legal consequences in the ‘real world’. If the counterparty of a contract does not uphold their part of the agreement, the legal system can be used to hold them accountable. On the contrary, a smart contract does not have to be upheld by anyone, it’s a set of instructions that self-executes. A smart contact does not have much precedence in the ‘real world’. It is only able to send transactions to other accounts on the blockchain, any other precedence must be acquired by creating a legal wrapper around the blockchain agreement.

Code is law

When entering into a normal contract, several factors play an important role in whether you can trust what you are signing. The most obvious part is an understanding of what is written in the contract. The contract lays out the terms and conditions of an agreement in legalese (lawyer language), which is what you are committing to. Therefore, it is important to understand this legalese and how this is interpreted by the legal system. This is why you always carefully read the terms and conditions of your Spotify/Facebook/etc agreement. You would never sign an agreement that commits you to providing your firstborn as payment for using their service, as 98% of people would.

Secondly, the terms and conditions that are laid out in a contract are constrained by a large body of existing law. This means that you can’t be sure how the contract will play out by just looking at the content of the contract. There are laws that prohibit you from paying with your firstborn, even if you agree to this. Therefore, it is important to understand how this legal context plays in.

These contextual laws often work as a safeguard, at times making contracts work as intended instead of as written. Journalist Matt Levine has an article about JPMorgan receiving a hefty fine, even after following the conditions set forth in a contract. The contract regulated the electricity market, and JPMorgan found a way to game the contract. JPMorgan did not break the rules set forth in the contract, they followed them carefully, but they did break the intent of the contract and were caught in the net of market manipulation laws.

Even if you enslave your firstborn to try and uphold your part of a contract, there is still a risk that this is not enough. You could sell all your belongings and sell your family into debt bondage, but it might still not cover your obligations in the agreement, and so the other guy ends up not getting paid. The risk of entering into a contract with someone who is not able to fulfill their part of the agreement is called counterparty risk, and must also be taken into account when entering a contract.

Last of all, even if you understand the contract and the legal context you still need to trust in the rule of law. Sometimes, de jure ≠ de facto. That’s why you might be hesitant to enter into an agreement with the son of the president in Corruptland. The contract is not worth the paper it’s written on.

So how do these factors compare to smart contracts? A smart contract essentially consists of two elements which you need to understand/trust:

  1. The code and how this is interpreted
  2. The immutability of the blockchain

Just like with normal contracts, it´s important to understand the actual content of a smart contract when interacting with it. But unlike a normal contract, which is written in legalese and interpreted by the legal system, the content of the smart contract is written in computer code and interpreted by computers. So what does smart contract code actually look like? Below is an example, an extract of a smart contract (don’t worry, you’re not expected to understand it):










function payOut(address _recipient, uint _amount) returns (bool) {if (msg.sender != owner || msg.value > 0 || (payOwnerOnly && _recipient != owner))throw;if (_recipient.call.value(_amount)()) {PayOut(_recipient, _amount);return true;} else {return false;}}

The smart contract code is the terms and conditions that you are signing up for when interacting with a smart contract. As long as you trust the blockchain that the smart contract resides on, you know that the code will execute exactly as programmed - so no breach of agreement can exist. It is important to note however, that working as programmed does not mean that it will work as intended if there are errors in the code.

Smart contract applications

As we have already established, smart contracts are a set of instructions residing on a blockchain, written in computer code. This code can be written in an infinite number of ways, just like words specifying the terms and conditions of a normal contract can be written in an infinite number of ways. But like words in a sentence, there is an infinite number of ways to arrange the code in a smart contract that does not make sense. That’s not interesting and no one cares. What is interesting however, are the ways to arrange the logic which makes sense. So what does make sense?

Before we answer that question for smart contracts, let us take a step back and consider the imagined potential applications of blockchains.

After the original Bitcoin paper was published, people started to realize that other types of agreements could be maintained using the same underlying technology. People imagined other agreements which would specify ownership of different types of assets and the rules for how the agreements would be updated. Some of these other applications were:

  • Digital identities (e.g. websites)
  • Non-digital assets such as gold, oil and real estate
  • A country’s currency, and other new types of currency
  • Financial instruments such as shares, mortgages and bonds
  • Provably fair gambling and betting
  • Rules for a data storage market
  • Rules for a computational market

The challenge was that each blockchain was being built with one application in mind. Every new application required a whole new blockchain, and creating a new blockchain requires a lot of resources, since a set of participants need to start maintaining a new agreement.

Smart contracts changed this. The magic rules that define the functionality of one blockchain can be replicated into smart contracts on an existing smart contract blockchain. This means that instead of building a new blockchain for every type of application, it is possible to add several types of applications to one blockchain by using smart contracts. You essentially have many blockchains on the same blockchain.

As an example, the blockchains which specify ownership of different types of assets, the “magic document” is essentially just a list that describes who owns what. Instead of using a whole blockchain for this application, this information can be included in a smart contract. Like the blockchain, the smart contract would essentially just be a list of accounts and their ownership, with rules describing valid updates to this list.

Smart contracts have the same applications as blockchains

Smart contracts also allow you to create smaller niche agreements, that would never be feasible to create a whole new blockchain for. Imagine I want to gamble with some people I have met on an internet forum, we could make a smart contract that locked our funds for 10 days and then paid one of us randomly. Making a whole new blockchain for this specific use case really does not make any sense, but creating a smart contract that utilizes the existing infrastructure of a smart contract blockchain does.

The power of smart contract blockchains is not fully apparent before you think about the value of the interaction between the different applications. As an example, if you have two smart contracts, one for the ownership of dollars and one for the ownership of real estate, you can use a third smart contract as an escrow, allowing a purchase of real estate without an intermediary third party.

There are many use-cases being built on blockchains, and building them as smart contracts on the same platform creates an ecosystem of applications that complement each other.

Programmable agreement

Blockchain technology is a new way of maintaining an agreement in a decentralized manner. Smart contracts enable anyone to define their own agreements within this larger agreement.

It is not clear which agreements will be maintained by blockchains in the future, but smart contracts make it easier for anyone to create the applications they think are promising. For money, which is arguably blockchain technology’s killer app, I enjoy taking a step back to look at the bigger picture:

From the cradle of civilization when money was first invented, people could own money. Eventually, entities that people imagined, such as states and companies, were able to own money. Now, for the first time in history, a machine (logic) can independently own money.

The consequences of this are hard to know, but I think it is fair to say that we have interesting times ahead.

If you liked this post, you can help me share it by recommending it below ❤

If you really liked it, you can tip me some Ether or Tokens at the following address: 0xAEe32096745dbf51362E2984fC0fFb78d7a47f47