by Melvin Barrett
4.3 .. 9 reviews
Smart Contracts And Ethereum Explained

Chapter 1 of 8

Blockchain technology is principally based on the decentralization of trust and was first applied to money in the form of 'Bitcoin'. Don't run away just yet if you don't understand that, we'll cover it in the next few slides. But what's important to understand is that technologists quickly got to applying this idea to other kinds of transactions as well (other than money) where we have traditionally required the oversight of an intermediate 3rd party to maintain trust. 

They developed an instrument called a smart contract that makes this happen, and one company - Ethereum is leading the effort to make smart contracts a part of our daily lives.

This guide is meant to help you learn about all that and the different aspects of smart contracts as easily as possible. 
So let's dive in!

Chapter 2 of 8

'Rule-of-Law' And Not 'Rule-by-Law'
Our society has evolved from being ruled by kings to democratically electing our governments. We take this for granted because the extreme atrocities of the kings and authoritarian systems have nearly disappeared today.

But here's a philosophical question:
If we all became good, honest and virtuous citizens, would there even be a need for us to be governed? Would there even be the need for a central authority to enforce laws and procedures in different aspects of our lives?
Well, if that was really the case, we might not need governance.

Community Enforced Car Speed Limit

Like staying within the speed limit of your lane on a highway while speeding up your car. We need law enforcement agencies to enforce this rule on the people by regularly ticketing offenders. And we know that the idea of honest and virtuous citizens is quite far-fetched and unrealistic.
The only way to remove enforcement agencies could be one where the world of cars is itself self-enforcing. 

What would this look like?
Imagine a future world of automatic cars. Let's say a car wants to speed up while remaining in its lane. Imagine every car having a special software such that, for a car to speed up:
  1. It would have to register its intent "to speed up by a certain amount" with the neighbouring cars running on the highway.
  2. Only if more than 10 neighbouring cars verify that the requesting car will be within speed limit of the lane if sped up, would the speed of the car increase. 
This very rough idea of an autonomously enforced system might seem to be really frustrating, but it fairly does away with the need for a central enforcement authority (highway patrol police).

Thus all cars have been automatically governed under the 'Rule of Law', instead of a 3rd organization ruling the world of cars just to enforce the law ('Rule By Law').

Chapter 3 of 8

Why Get Rid of Central Authorities?
We all know a plenty of cases where the 3rd parties or central authorities have become corrupt and taken advantage of us just because it is in a place of power. So we would want to move to a better future, where law enforcement is distributed to every participant in the system instead of a central authority. 

A future where power is distributed and not concentrated in the hands of a few authorities. 

Chapter 4 of 8

How Do We Make It Happen?
Blockchain is the method that enables this kind of decentralized law enforcement and the instrument will be 'smart contracts'. 

Traditional Contracts:
Contracts traditionally are 'Agreements/Arrangements' between two or more parties that they agree to a certain set of conditions and actions to be performed based on those conditions.
When we implement a smart contract system that utilizes Blockchain, we would have to design a system that specially overcomes the limitations in traditional paper contracts.
Limitations with traditional paper contracts:
1. They are passive - therefore difficult to enforce. A person agrees to pay $50 when he looses a bet, on paper contract. But then absconds without paying it. 

2. Difficult to maintain a record of past behaviour of involved parties - The person who absconded in the previous transaction, goes to a city and places a new bet with a new person. The new person has no idea of his background and thus trusts him fully.

3. Slow and Costly - A third person has to be involved to ensure the bet goes through (skimming through paperwork takes time) and he also needs to be paid(costly).

If you can spare some time, I recommend watching this excellent video below, to hear the speaker explain these points in detail.

Chapter 5 of 8

Blockchain Mechanism
How do we build a smart system (of smart contracts) that can overcome these problems with traditional paper contracts?
The answer lies like I mentioned in the blockchain mechanism.  

So How Does A Blockchain Mechanism Operate?
  • An online ledger (record book) of all transactions from the beginning of time is maintained by all computers on the blockchain network. Each computer has a copy.
  • The ledger is made up of blocks of transactions. New blocks are regularly added and the public ledger keeps growing over time. This public ledger (chain of blocks) is called the 'Blockchain'.

  • When a new block of transactions get added, all the transactions in the block are considered executed. At the same time, all computers update their respective blockchain copies with the new block.

  • In mathematics, a Hash Function is an operation which converts a text of any size into a short unique value fixed in size called the 'hash value'. A SHA-256 Hash Function converts a text of any length to a unique value with a fixed size of 256 bits (32 bytes). 

  • A new block is approved to be added to the blockchain only if the hash value of the {Entire text of the new block + random number} is less than a certain target value. Any computer on the network suggesting to add a new block to the blockchain has to provide the right value of the random number such that the above condition is met. This is the "mathematical puzzle" that the computer would have to solve before it recommends a new block to the rest of the computers on the network. Computers have to do pure guesswork to find the number that fits.

  • Computers on the network called 'miners' keep solving this puzzle with each new block to get their block of transactions added to the blockchain. When the block suggested by them is added they get a financial reward. On the bitcoin network it usually takes about 10mins for a miner to solve the puzzle.

  • Finally: When a miner has solved the puzzle, he broadcasts the new block and the random number. All the computers verify that the hash value meets the criteria and the value of the random number is correct. Then they all add the new block to their copies of the blockchain. All the computers also verify that each transaction in the block being added is valid. 

Chapter 6 of 8

So How Do Smart Contracts Work?
A traditional contract contains the agreement statements in written format, such as, "Rent shall increase after the 11th month of the lease is over."

A smart contract is nothing but such agreement statements written in the form of code which get executed like any other computer program. 

Like considering the example of a bet. 
Traditional Paper Contract/Agreement:
"All the money in the bet, shall be given to Person A, if the football Team X wins. If the team looses, all the money shall be given to Person B."

Smart Contract:
The agreement statements are converted into a computer program with code based on the following algorithm:
  1. Starting Balance in the contract = Take Money From A.
  2. Update Starting Balance = Take Money From B.
  3. Record outcome of the bet as per received signal.
  4. If (Outcome  = 'Team X wins'){ Send Money To A }
    Else{ Send Money To B }
Execution of the Smart Contract Program:
We then upload this executable contract (computer program) onto the 'Smart-Contract Blockchain Network' as a transaction in the new block, which then gets added to the blockchain after verification of the block. When the bet is finished a signal is sent to the contract program to execute along with the bet-outcome value (say 'Team X wins').

When the contract program receives this signal, it executes the code in which the money held with the contract is sent to the rightful winner of the bet.

Chapter 7 of 8

Issues With Traditional Contracts Solved
Using such smart contracts and storing them over a blockchain eliminate the limitations in traditional paper contracts in the following ways.
  1. Execution of Contract is Active 
    The contract code already has the cash from both A and B when it was uploaded to the blockchain database. If B is planning to abscond, he has no way to get his money back. The code will honour and execute all the steps in the contract and no-one can stop it once it is recorded on the blockchain. No one can tamper it either.
  2. Past record available
    Because each contract on the blockchain is present forever, parties that interact with person B can verify his past records, if needed.
  3. Execution is Fast
    When the bet finishes, the processing of the money takes no time at all. The coded-contract executes within seconds and sends the money immediately.

Watch this video below where Mark Pascall discusses the above points and a little bit on what Ethereum is doing to help kick-start the world of smart-contracts.

Chapter 8 of 8

Ethereum - A Platform For Smart Contracts
So converting our contracts into programs ('smart-contracts') and using assurance provided by a decentralised blockchain network that our contracts shall be upheld and kept secure, seems like a great idea to remove middlemen institutions from a number of types of our day-to-day transactions.

So is there any software available to create smart-contracts?
In 2013, a guy named Vitalik Buterin (just 19 years old then) published a white-paper proposing a general purpose platform using which people could create not only smart contracts but other decentralized applications for many other use-cases. He called it Ethereum, and it also uses the concept of blockchain to power its decentralized trust network.
Difference Between Bitcoin And Ethereum:
It is easy to confuse ethereum to be a cryptocurrency like bitcoin, so here is a clarification. 
  1. Bitcoin had explored only the use-case of conducting monetary transactions over a decentralized peer-to-peer network without the need for any trusted middleman authority.
  2. That is why, each node on the network had a very simple and specialized application running on them to take part in the decentralized bitcoin network. 
  1. Ethereum was imagined as a general purpose platform to built applications for all other use-cases, including monetary transactions. The monetary use-case built on Ethereum calls its value unit 'Ether' (counterpart of bitcoin).
  2. Each node on the network has a very powerful general purpose virtual computer, with a very powerful programming language, that you can use to create and host decentralized applications for any use-case, which will then use the network of computers running ethereum software as its decentralized network. 

The ethereum software (the virtual computer) that you install on a computer to act as a node on the ethereum network, can also be used to create smart-contracts.
The contracts then need to be fuelled up with Ethereum's cryptocurrency 'Ether' (also called 'gas') based on the number of lines of code in the contract that need to be executed.

You can watch this brilliant tech-talk by the Joseph Lubin - a cofounder of Ethereum to learn more about Ethereum.
After Joseph's presentation, Kieran, the chief product officer of BlockApp gives a demo of creating and running a smart-contract using the Ethereum software.

Rate this guide
(Doesn't require signup)

Continue Reading ...