Smart Contracts On The Blockchain: A deep dive in to Smart Contracts

ABHISHEK KUMAR
11 min readApr 30, 2018

It is becoming difficult for the ordinary person to avoid the Blockchain buzz, and Businesses cannot shy away from blockchain either.

Many multinational companies have already jumped onto the blockchain bandwagon and are working on their own projects to stay ahead of the competition.

According to Accenture research published at the start of 2017, investment banks alone could save up to $12 billion per year by adopting blockchain and smart contracts, effectively a program code that automatically performs some actions when pre-defined conditions occur (i.e. if X does Y, then execute Z).

Gartner has estimated that by 2022, smart contracts will be in use by more than 25% of global organizations.

Major technology providers like IBM ,Microsoft ,TCS ,Accenture are offering blockchain solutions to enterprise clients. Tech start-ups too are aggressively capitalizing on the boom by building new products and services that depend on the technology.

For other businesses, however, the big question is how blockchain adoption can benefit them. There is no question that modern business environments require companies to make technology integral to their strategy.

Cost Reduction & Efficiencies: Cutting out middleman means savings for the business. According to a McKinsey report it is estimated that blockchain could save businesses at least $50 billion in B2B transactions by 2021.

So what are Smart Contracts

A smart contract is a computer protocol intended to digitally facilitate, verify, or enforce the negotiation or performance of a contract. Smart contracts allow the performance of credible transactions without third parties. These transactions are trackable and irreversible.Smart contracts were first proposed by Nick Szabo, who coined the term, in 1994.

Proponents of smart contracts claim that many kinds of contractual clauses may be made partially or fully self-executing, self-enforcing, or both. The aim of smart contracts is to provide security that is superior to traditional contract law and to reduce other transaction costs associated with contracting. Various cryptocurrencies have implemented types of smart contracts.

‘Smart contracts’, are programs that are written on the underlying distributed ledger and are executed automatically by nodes on the network. Smart contract have to be verifiable by each node on the network, it means that all nodes on the network must see the same data. Smart contracts are complex and their potential goes beyond the simple transfer of assets, being able to execute transactions in a wide range of fields. Such as insurance, crowdfunding , logistics, medicine, gaming industry, entertainment industry, etc.

Blockchain was initially designed for P2P money only. But it soon showed the potential to be used for any kind of P2P value transaction on top of the Internet. The Ethereum project thus introduced the idea of decoupling the contract layer from the blockchain layer, where the ledger itself is used by smart contracts that trigger transactions automatically when certain pre-defined conditions are met. By decoupling the smart contract layer from the blockchain layer, Blockchains like Ethereum aim to provide a more flexible development environment than the Bitcoin Blockchain.

A smart contract is a computer code running on top of a blockchain containing a set of rules under which the parties to that smart contract agree to interact with each other. If and when the pre-defined rules are met, the agreement is automatically enforced. The smart contract code facilitates, verifies, and enforces the negotiation or performance of an agreement or transaction. It is the simplest form of decentralized automation.

It is a mechanism involving digital assets and two or more parties, where some or all of the parties deposit assets into the smart contract and the assets automatically get redistributed among those parties according to a formula based on certain data, which is not known at the time of contract initiation.

If and when all parties to the smart contract fulfill the pre-defined arbitrary rules, the smart contract will auto execute the transaction. These smart contracts aim to provide transaction security superior to traditional contract law and reduce transaction costs of coordination and enforcement.

The term smart contract is a bit unfortunate since a smart contract is neither smart nor are they to be confused with a legal contract.

•A smart contract can only be as smart as the people coding taking into account all available information at the time of coding.

•While smart contracts have the potential to become legal contracts if certain conditions are met, they should not be confused with legal contracts accepted by courts and or law enforcement. However, we will probably see a fusion of legal contracts and smart contracts emerge over the next few years as the technology becomes more mature and widespread and legal standards are adopted.

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.

Smart Contract Code is a Law

A smart contract essentially consists of two elements which you need to understand/trust:

  • The code and how this is interpreted
  • 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 if you are not a technical person 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 contracts can be used for simple economic transactions like sending money from A to B. They can also be used for registering any kind of ownership and property rights like land registries and intellectual property, or managing smart access control for the sharing economy, just to name a few. Furthermore, smart contracts can be used for more complex transactions like governing a group of people that share the same interests and goals. Decentralized Autonomous Organizations (DAOs) , are such an example for more complex smart contracts.

How to create a Smart Contract?

To create a smart contract you need:

a) Subject of the contract:The program must have access to goods or services under contract to lock and unlock them automatically.

b) Digital signatures: All the participants initiate an agreement by signing the contract with their private keys.

c) Contract terms: Terms of a smart contract take the form of an exact sequence of operations. All participants must sign these terms.

d) Decentralized platform: The smart contract is deployed to the Blockchain of this platform and distributed among the nodes of the platform.

Benefits of a Smart Contract

Smart contracts use all the benefits of Blockchain technology & provide:

a) Security: The smart contract is encrypted and distributed among nodes. This guarantees that it will not be lost or changed without your permission.

b) Economy and speed:Most processes are automated, and most intermediaries are eliminated.

c) Standardization: There is a wide range of different types of smart contracts nowadays. You can choose one and change it according to your needs.

d) Radically reduce transaction costs (bureaucracy) through machine consensus and auto-enforceable code.

e) Bypass the traditional principal-agent dilemmas of organizations, thus providing an operating system for what some refer to as “trustless trust”.

This means that you don’t have to trust people and organizations, you trust code, which is open source and provides transparent processes.

With blockchains and smart contracts we can now imagine a world in which contracts are embedded in digital code and stored in transparent, shared databases, where they are protected from deletion, tampering, and revision.

In this world every agreement, every process, task and payment would have a digital record and signature that could be identified, validated, stored, and shared Intermediaries like lawyers, brokers, and bankers, and public administrators might no longer be necessary. Individuals, organizations, machines, and algorithms would freely transact and interact with one another with little friction and a fraction of current transaction costs.

A smart contract can formalize the relationships between people, institutions and the assets they own.

The transaction rulesets (agreement) of the smart contract define the conditions — rights and obligations to which the parties of a protocol or smart contract consent.

Although the concept of smart contracts is not new, blockchain technologies seem to be the catalyst for smart contract implementation.

Below Diagram explains the working of a SmartContract

Example of a Smart contract Explained Below

If A and B don’t know and don’t trust each other, they usually need a trusted third party to serve as an intermediary to verify transactions and enforce them. With smart contracts & blockchains, you don’t need those trusted intermediaries anymore for clearing or settlement of your transactions. Take the example of buying and selling a car:

Below Diagram explains the working a Traditional Contract for the Smart Contract Example

On the Blockchain, once all involved authorities and companies are on a blockchain, a smart contract couldbe used to define all the rules of a valid care sale. If Alice wanted to buy the car from Bob usinga smart contract on the blockchain, the transaction would be verified by each node in the BlockchainNetwork to see if Bob is the owner of the car and if Alice has enough money to pay Bob.

Below Diagram explains the working of the Smart Contract Example

If the network agrees that both conditions are true, Alice automatically gets the access code to the smart lock for the garage. The blockchain registers Alice as the new owner of the car. Bob has € 20,000 more on his account, and Alice € 20,000 less. No middlemen required. On the Blockchain, who owns what is transparent and at the same time anonymous or pseudonymous. This means that every computer running the blockchain protocol could check whether a certain person is the rightful owner of the car or not.Stealing cars won’t be as easy as today, especially once we have smart keys granting access control verified on the blockchain, to unlock our future vehicles. As the owner of the car, you could authorize other people to drive it (stating the public key of the respective individual). In such cases opening the car would only be possible with a smart key on the Blockchain.

Usecases of Smartcontracts can be across many industries

Blockchain and smart contracts have the potential to disrupt many industries. Use cases can be found in banking, insurance, energy, e-government, telecommunication, music & film industry, art world, mobility, education and many more. Smart contract use cases range from simple to complex.

Time-stamping services like ascribe (art registry) or governmental and semi-governmental registries (land titles, birth certificates, birth certificates, school and university degrees) are examples for simpler technological use cases (the regulatory aspects might be more complex). Decentralized autonomous organizations, on the other hand, are the most complex form of a smart contract. TheDAO in 2016 was an example for such a complex smart contract.

Below are the list of usecases where Blockchain & Smartcontracts can disrupt the the industries

Types of Smart Contracts

Below diagram explains the various types of Smart contracts

Given the fact that Blockchain is still a new technology, some industries might adopt smart contracts later than others, especially if they are subject to heavy government regulation or if the uses cases require high network effects — like widespread technology adoption along the supply chain, standardization, etc. In general, it’s advisable to start out with a small pilot project of a less complex use case to build expertize and understand the technology better and move on to more complex use case at a later stage.

Furthe reading

http://internetofagreements.com/files/WorldGovernmentSummit-Dubai2017.pdf

Smart legal Contracts, Florian Glatz

OpenLaw, Consensys

Smart Contract Coding

Solidity is a smart contract programming language. The syntax is similar to that of JavaScript, and it is designed to compile to code for the Ethereum Virtual Machine, to create contracts for voting, crowdfunding, blind auctions, multi-signature wallets and more.

Below are the various links related to Smartcontract coding

1) Official Solidity Documentation, by Ethereum Foundation

https://solidity.readthedocs.io/en/latest/

2) Solidity Tutorial

https://medium.com/@ConsenSys/solidity-integration-with-visual-studio-8bdab2ff8a74

3) Standardized_Contract_APIs

https://github.com/ethereum/wiki/wiki/Standardized_Contract_APIs

4) Interacting with smart contracts

http://ethdocs.org/en/latest/contracts-and-transactions/accessing-contracts-and-transactions.html#interacting-with-smart-contracts

5) Remix Ethereum

https://github.com/ethereum/remix

6) The Hitchhiker’s Guide to Smart Contracts in Ethereum

https://blog.zeppelin.solutions/the-hitchhikers-guide-to-smart-contracts-in-ethereum-848f08001f05

7) trufflesuite/truffle

https://github.com/trufflesuite/truffle

Sources:

1.https://bitcoinmagazine.com/articles/smart-contracts-described-by-nick-szabo-years-ago-now-becoming-reality-1461693751/

2.https://en.wikipedia.org/wiki/Smart_contract

3.https://blockgeeks.com/guides/smart-contracts/

4.https://www.ethereum.org/token

5) PWC

6) Forbes

7) BlockchainHub

Please note: The material has been reproduced from various sources & is strictly for educational ,illustrative purposes & for promotion of Blockchain Technology.

--

--

ABHISHEK KUMAR

DevOps/Cloud | 2x AWS Certified | 1x Terraform Certified | 1x CKAD Certified | Gitlab