Blockchain Basics - Smart Contracts In Blockchain

Introduction

Blockchain has gotten a lot of attention in recent years because it provides a security, trustable, low-cost solution to deal with transactions and data management. Because of that, smart contracts become possible. I am going to talk about Smart Contracts in this article.

Smart Contract Definition

According to Wikipedia, “A smart contract is a computer protocol intended to digitally facilitate, verify, or enforce the negotiation or performance of a contract.”

In plain English, a smart contract is a piece of computer code that runs in a Blockchain network. The code calls a function to do something when all conditions are met. For example, after Tom transfers Jerry 5 cryptocurrencies, a piece of code automatically send Tom a PDF document of Jerry.

Smart Contract History

A smart contract is not a brand new concept. It was proposed by Nick Szabo, a legal scholar and cryptographer, in 1994. The purpose of the smart contract is to allow executing a transaction without third parties. Of course, the transaction must be valid, trackable, and irreversible. However, technology was not ready for a smart contract in 1994. In order to have trust between two parties, people must resort to authorities, such as Banks or Government Agencies. There was no quick and automatic way of transferring something among parties. With the emergence of Blockchain, trust and electronic transaction are not issues anymore. Blockchain uses cryptography and P2P network to verify things and maintain integrity. Therefore, Ethereum was proposed by Vitalik Buterin, a cryptocurrency researcher and programmer, in late 2013. Ethereum is a Blockchain network that allows developers to create and run smart contracts. Today, smart contracts are widely using in many Blockchain networks.

How Do Smart Contracts Work?

A contract is an agreement between two or more parties, such as a sale contract, a rental contract, etc. A traditional contract generally involves contract parties, lawyers, and a lengthy process, several rounds of negotiations, back and forth drafting phases, administration of the finalized agreement, and of course, confirmation of the execution. You may always think that contract must be written on a piece of paper and must have signatures from contract parties. Actually, there are a lot of invisible contracts. One example is online shopping, if you like a book on Amazon, you just need to place an order, and then Amazon must deliver you the book. If somehow, Amazon misprices a $20 book as $2. Because the invisible contract, Amazon must ship you the book after you pay $2 because the contract defines obligation of each side of the contract. Smart contract works same. If one person wants to sell something on a Blockchain. He/she just need to create a smart contract that accepts cryptocurrency and deliver digitized goods or assets. The difference between smart contracts and traditional contracts are

  • no bank or credit card company involved
  • used for exchanging digital or digitized goods or assets
  • contract triggers delivery automatically
  • both parties can be anonymous

Linking Physical Goods or Assets with Blockchain

A traditional blockchain network, such as BitCoin, can only handle transactions that transfer cryptocurrency between two parties. The smart contract deal with exchange cryptocurrency and physical goods or assets, so we need to find a way to link physical goods and assets with a Blockchain network and Blockchain transactions. There are several ways to link them or represent them in a Blockchain network.

Digitizing Physical Goods or Asset

Ownership of physical goods or asset could be a legal document, such as a deed. Having a legal document means ownership of the goods or assets. So, we can digitize the deed of a house and upload it into a Blockchain. And then, the deed can be added into Blockchain transactions. Of course, a third party is still needed to validate the digitized deed when there is a dispute among parties.

Using Smart Lock

Some physical goods or assets are controlled by access, such as a rental car or a rental house. As long as you have the key, you can use or access the physical goods or assets. Therefore, a smart lock was invented to manage this kind of goods or assets. A smart lock assigns a digital identifier to identify a physical good or asset. The identifier is added into a Blockchain and then, it will be transferred to somebody who has paid the owner of the digital identifier. And then, when the buyer is trying to use or access the physical goods or asset, the application in the digital lock will check the Blockchain network to see if the person has the right to use it.

Blockchain

Example of a Smart Contract 

If Henry wants to sell a book at ABC Blockchain. His Blockchain public address is 12345. The process will be

  • Henry uploads a book in PDF file format to a smart lock storage.
  • Smart lock storage generates a smart lock id, say 6789.
  • Henry creates a smart contract in a Blockchain.
    1. <Smart Contract>  
    2. If 1 ABCCoin is sent to my address 12345, the smart lock id 6789 will be transferred to you   
    3.   
    4. If (received(12345) == 1)   
    5. {  
    6.     send(getSenderInfo(12345, 1), smartLockId);  
    7. }  
  • Henry puts the book information on his personal website.
  • Mahesh finds the book information on Henry’s website and wants to buy it.
  • Mahesh uses his ABC Wallet to send 1 AbcCoin to Henry.
  • The smart contract is triggered and the smart lock id 6789 is sent to Mahesh’s public address, say, 54321.
  • Mahesh goes to the smart lock storage to download the book with his public address 54321.
  • The smart lock storage will check ABC Blockchain to see if the address 54321 has the smart lock id.
  • The smart lock storage starts the file download process.

    Blockchain

Benefits of Smart Contract

  • Autonomy
    Anybody can create a smart contract; there are no dependencies on brokers, lawyers or other middle people.

  • Trust
    The contract is encrypted and stored in a shared ledger. Everybody can see it but nobody can change it. This avoids contract tampering.

  • Backup
    Because every single node has a copy of a Blockchain, your electronic documents in your smart contract can be easily recovered when your computer/node run into issues.

  • Safety
    All the documents are protected with cryptography.

  • Speed
    The delivery of digitized goods or assets happens instantly.

  • Savings
    Smart contracts save you money since they knock out the presence of an intermediary.

  • Accuracy
    Automated contracts are not only faster and cheaper but also avoid the errors that come from manually filling out heaps of forms.

Summary

Smart contracts prompt the usage of Blockchain up to the next level. Instead of waiting for weeks on settling a business transaction, it allows a quick and agile way of closing them.