A Story About Smart Contracts

MetaX
MetaX Publication
5 min readJan 9, 2018

--

Written by Jon Roethke and Hunter Gebron

When discussing blockchain technology, the topic of smart contracts is at the top of the list. Smart contracts will forever change the way we conduct business transactions. Or so the story goes…but what are smart contracts? And why are forward thinking business minds so fascinated by their existence?

The goal of this blog post is to demystify the most overused buzz phrase surrounding blockchain today. We will dive into an actual smart contract to see what is going on underneath the hood. Don’t worry, we are going to make this a simple and easy exercise. You do not need to be a computer scientist or blockchain wizard to understand smart contracts. They are really quite straightforward.

First, a bit of historical context.

The term “smart contract” was created in 1996 by computer scientist (and lawyer) Nick Szabo, in a blog post titled, Formalizing and Securing Relationships on Public Networks. Nick Szabo is an important figure in the history of blockchains as the inventor of Bit Gold. Bit Gold has been described by legendary silicon investor Naval Ravikant as, “the giant on whose shoulders bitcoin sits”.

Let’s look at what Nick Szabo describes in this now famous blog post as, “the granddaddy of all smart contracts, the vending machine”.

The vending machine? Yes, candy bars and soda cans. The vending machine.

The vending machine shares the exact same properties that smart contracts on the blockchain do today. A vending machine has hard coded rules that define what happens when certain conditions are met and then executes certain actions when those conditions are fulfilled.

For example:

If Bob puts a quarter in the vending machine then he will receive one can of soda.

If Alice puts in one dollar bill, then she will receive one can of soda AND seventy-five cents change back.

Simple rules are defined and enforced in this case by a machine in the physical world. In very much the same way, smart contracts are simple rules defined and enforced by code on the blockchain.

Now let’s look at an example of an actual smart contract and written in the programming language Solidity on the Ethereum blockchain. We will walk you through the code with commentary to explain what is going on and how it works.

To illustrate how smart contracts can provide real world benefit to us in our everyday lives we have drafted a story.

Meet the Jensens

The Jensens are a fictional family facing an interesting dilemma. The story below will set the scene and describe how a simple smart contract can solve their problem. After you read the story, the following section will dive into the code with a high-level explanation.

The Johnny Dilemma

Walter and Pamela Jensen have a 12 year old boy named Johnny.

Johnny is a bit mischievous and his grades are poor.

Walter and Pamela are set to go on a remote vacation to the Himalayas where they will only be accessible by email.

So to incentivize Johnny to do better in school while they are away, they make him a deal.

They tell Johnny that IF he gets an “A” in Civics class then he will get $5.

Johnny agrees to this deal but here is the problem. Johnny is impatient and wants a guarantee that if he gets an “A” in Civics, then he will receive his payment BEFORE his parents return home from their trip.

But remember, Johnny is mischievous, and Walter and Pamela cannot trust him to tell the truth about his grade over email. Johnny could easily lie about his grade just to collect the $5 reward.

So Walter and Pamela write a smart contract and lock up $5. The $5 will only be released to Johnny’s public Ethereum wallet address if he gets an “A”. They entrust Johnny’s teacher, Mrs. Crabapple, to input the grade (data) into the smart contract.

Walter and Pamela give Mrs. Crabapple a cryptographically secure private key so that she is the only one who can write data into the smart contract.

Mrs. Crabapple, in this case, is what is known as a trusted oracle.

Walter and Pamela can rest easy knowing Johnny will only get paid if Mrs. Crabapple inputs an “A” into the smart contract.

And Johnny is happy because he knows that he will get his reward if he works hard and gets the “A” and he will get paid before his parents return from their vacation.

Now let’s look at the code for this smart contract and how it will look on once it’s deployed to the blockchain!

We hope this provides you with a tangible grasp on how smart contracts can be applied in the real world. The story about the Jensen Family is designed to be simple and easy to follow. But it’s core message can be extrapolated and applied to any number of complex business processes. Many large enterprise corporations are looking to smart contracts to streamline supply chain inefficiencies, legal agreements, escrow, and medical records.

Setting certain rules and agreements in place via code ensures all parties agree to the rules beforehand and can reliably trust in the code to execute them.

Smart contracts have limitless application and far-reaching impacts. Most importantly, these “contracts executed via code” provide a natural evolution to the modern day contracts that we all know and love (and sometimes hate). The main differentiator is that these code contracts when hosted on a public blockchain can be executed without the need for trust, as we saw in the story. This eliminates or greatly reduces the amount of legal back-and-forth between parties when transacting. In the case of digital advertising, arguing over insertion order details and payment dates, even after the buy has completed, is an extremely slow and overly-complicated process, often times straining relationships and causing ongoing legal headaches. As we saw in the case of the Jensen family’s story, the money was set aside up front, locked in escrow, and only released once the contract allowed it.

What are some examples of smart contracts you would like to see applied to your organization’s business model?

*Disclaimer

The smart contract code above is intended for educational purposes only. It has not been properly audited or tested for real world use, and there are many optimizations that could be made.

--

--