Smart Contracts — A Simple Yet Comprehensive Explanation in Pictures
What exactly are Smart Contracts? The technology community seems to be fascinated by them.
This article will focus on bringing some reality to this fascination, by providing you the most accurate explanation of what they are and what they can do.
Before we delve any deeper into the subject, I have to dedicate a section below to describe What Smart Contracts are NOT. This is purely to address some of the misconceptions of this technology that have become popular in the community.
If you are new to Blockchain and Cryptocurrencies, feel free to skip this section below, and head straight to the next section.
What Smart Contracts are Not
A simple Google search on the internet would yield the following definitions for Smart Contracts
All the above descriptions are not 100% correct. Neither are they a 100% incorrect. The problem with these definitions is that they leave you with a lot of room to imagine the range of possibilities with Smart Contracts, which of course do not exist. Let’s start with a bit of mild myth busting:
1. Smart Contracts are not that smart. Your smartphone is smart
2. Smart Contracts cannot replace real-world contracts and agreements enforced on paper (we are very far from that)
3. Smart Contracts do not automatically execute the way you think they do
4. Smart Contracts cannot automate a lot of things (like payments and invoice clearances) like the way you think they do.
5. Smart Contracts are revolutionary, but perhaps not mind-blowing like the way you think they are.
What Smart Contracts Truly Are
To better understand the real value of Smart Contracts, it is essential to have a fundamental (and a bit over-simplified) understanding of how the internet works. Let’s do that now.
1. How the Internet Works — Oversimplified
When you give your web browser a URL that it should visit, it primarily does two things:
1. Find the server of the website that it should visit from the URL
2. Ask the server mentioned above, what it should load on the site
Simply put, servers are computer systems which tell your browser what to display, or what to do, or where to go. They are coded to respond to any possible request that you could make from your browser. They have their own storage space called a database, and they are capable of handling complex computations with the stored data.
Computer servers are usually owned by firms (like Youtube above) who maintain and update them as per their needs. They constitute a company’s backend infrastructure along with the database, and all the data and processes coded or stored on them. These companies hire backend developers to write high-quality code on these devices, to serve all their organizational IT functions that come from browsers, mobile devices, and other client machines. This includes almost everything you see on the internet and even beyond
So computer servers sound pretty cool. Which begs the question —
2. What does all this have to do with Blockchains?
Now, this is the time we have to recall our lesson from my previous article, “Blockchain — A Short and Simple Explanation in Pictures.” If you do not have prior knowledge about Blockchains then…
Each participant in a Blockchain network owns and runs a computer server called a node. These nodes are running a common Blockchain software which helps them —
1. Connect to other nodes running the same software
2. Listen for transactions in the network and produce blocks linked to the previous block
3. Remain in consensus with each other regarding the correct sequence of generated blocks
4. Maintain a full copy of the Blockchain
Each participant can also read from the Blockchain by directly querying their local Blockchain node to view all data of transactions that have taken place.
3. Sooo… Smart Contracts?
From the previous article, we discussed that Alice sending Bob $100 is an example of a transaction on a Blockchain. At present, however, it is not possible to send US dollars on any Blockchain ledger. We have banks for that, and all transactions with US dollars are managed between banks internally, between a bank and a central bank, or in cash.
Presently banks do not use Blockchain software, and they rely on their servers to manage these financial transactions. Hence the reason why all payments (in $ or other fiat currencies) would have to be done via the bank’s software rather than automated through a Blockchain or Smart Contract.
Transactions which do use a Blockchain are those with cryptocurrencies like bitcoin and ether.
Broadly there are two types of transactions that can be stored on Blockchains that support smart contracts:
1. A transaction where a cryptocurrency moves from one person to another (e.g., Alice sending Bob 0.2 bitcoin)
2. A transaction which deploys or interacts with a smart contract
Entities in a Blockchain are assigned public keys. Public keys are just a fixed-length random sequence of letters and numbers that are unique to an entity. There are two types of public keys on most Blockchains
1. Those belonging to regular users like Alice and Bob (who also own its corresponding private key)
2. Those belonging to Smart Contracts
A Smart Contract is a piece of computer code that is stored and gets executed across all nodes in the peer-to-peer network. It usually consists of the following:
1. A public key which represents and is used to refer to the smart contract (just like how Alice and Bob’s public key can be used to refer to them)
2. The public key of the person who wrote and deployed the smart contract on the Blockchain
3. The computer code associated with the smart contract which can never be changed after deployment
They are typically useful in scenarios where participants wish to conduct rule-based transactions on the internet. The computer code in a smart contract contains rules. These rules may define:
a. What percentage of payment someone should get…
b. What deadlines need to be met for this payment to be valid…
c. What prices should assets be sold or bought…
among many others
4. How is this different from executing code on standard servers?
It is important to realize that such rule-based transactions can be conducted on standard servers owned by a company or business. This has been done for many years and is what has been happening in all businesses, banks and other financial institutions.
Smart Contracts are genuinely revolutionary because such rule-based transactions need not be sitting on servers owned by a company. They can now be implemented over the peer-to-peer network of a Blockchain. The benefits and drawbacks of such an arrangement is a rather lengthy discussion in itself, and there is plenty of literature on the internet which covers the same.
Here are some of the key differences between code stored on a company’s server, against those that are stored on a Blockchain in the form of Smart Contracts
Fun Trivia: Vitalik Buterin (founder of Ethereum) famously said that he regrets using the word ‘Smart Contracts’ for the tech on Ethereum, and would rather have them called ‘Persistent Scripts.’
5. I don’t get it. Break it down and give me an Alice & Bob story
Let’s say some of the top artists in the music industry came together and decided to launch a decentralized music distribution platform called Dotify. This platform allows content creators to upload their music and sell them directly without relying on intermediaries in between such as record companies or distribution platforms who charge fees or take a cut of their potential earnings.
Suppose this platform is built on a smart contract Blockchain such as Ethereum. Such a platform would have two main components
1. A standard server which hosts the website and contains all non-transactional data (such as pictures and music files)
2. Smart contracts deployed on Ethereum which ensures the fair payment and distribution of music on the platform.
Let’s say Alice is the coder of the smart contracts for Dotify. She would write rules on the smart contract which says —
1. When a creator uploads a music file, note down the ID of the song, cost per download and the creator’s public key.
2. When a user sends cryptocurrency to the public key of the smart contract, allow that users’ public key to download the creator’s song from the server(s)
3. Forward all received cryptocurrency to the public key of the creator who uploaded the song after a certain period (say one month)
After Alice writes the above in code, she would have to get her code audited from 3rd party companies, and publish the results of her audit on the Dotify website.
The Process
1. Alice then connects to the Blockchain using the common software and DEPLOYS the smart contract. This is a transaction on the Blockchain. The transaction gets included in a block, gets published across the network and a public key is assigned to the deployed contract.
2. Bob, a creator, wishes to upload his songs on Dotify. He can interact with smart contract using its assigned public key (created in step 1 above).
Bob uploads his song to the server and registers with the smart contract his details including his public key that he wishes to receive payment in. This is again a transaction on the Blockchain. Bob is now INTERACTING with the Smart Contract.
3. Carl wants to purchase Bob’s song. The song costs 0.3 ether, and Carl sends that amount to the smart contract’s public key. This is again a transaction on the Blockchain. Carl is also now INTERACTING with the Smart Contract.
The Smart Contract has a block of code written on it, which executes on receipt of ether from Carl. It checks the received amount against the cost of the song and grants access to Carl’s public key to download the song from the server.
It also conducts a check to see when was the last time a payout was made to Bob (the creator) and forwards the funds owed to him if it has been more than one month since.
This final step is all one transaction on the Blockchain when Carl sends ether to the smart contract’s public key.
From step 3 above, it is important to realize that Smart Contracts do not automatically execute. It is always triggered by some form of human interaction with the smart contract’s public key. In the above case, it was Carl sending Ether to the Smart Contract’s public key.
If you are wondering what an excellent idea this is, such a platform already exists. It is not called Dotify, but Ujo Music.
6. If Smart Contracts happen to be super secure, tamper-proof code, then why not use them everywhere?
There are multiple reasons, the primary one being, that the internet of today does not need tamper-proof code everywhere. Most of the time, it requires code which is easy and cheap to upgrade for developers, while being intuitive and friendly to end-users. Both are presently not possible with Smart Contract technology of today. Finally, when it comes to data storage, it is essential to ask yourself the following question…
Is replicating the lyrics of the song ’99 Problems’ in mp3 format across 9000 computer nodes on the internet really necessary?
Smart Contracts have a varying degree of utility for different use cases. They are an excellent technology for rule-based value transactions. This means that they are ideal to be used in situations where rules regarding a value transfer between participants need to be set in stone. Hence the reason why we do not use them for use cases such as data storage since they are much better ‘served’ using traditional servers.
Another critical discussion to have is deciding what type of Blockchain to use depending upon the degree of value concerned. A use case with low value, high volume transactions such as those which record social media views, subscriber count or likes/dislikes is typically better done on a smaller, less decentralized Blockchain with fewer participants.
Whereas those with a higher value (such as the ownership transfer of land titles) are better settled on a more decentralized Blockchain. This is because the requirement for transaction immutability is much higher in the latter use case. Hence, such transactions are better recorded on Blockchains such as Bitcoin and Ethereum which have more participants and use a battle-tested consensus algorithm.
If you wish to know more about the use of smart contracts or you happen to be in the market for a Blockchain expert for your project, book me for a quick 30-minute online consulting session. I have a new initiative called Consult Me Live which will facilitate this.
I hope you enjoyed the read. Please follow me on Medium for similar breakdowns in the Blockchain and Product Management space :)
Cheers.