paint-brush
Smart Contracts — A Time Saving Primerby@abhib
2,055 reads
2,055 reads

Smart Contracts — A Time Saving Primer

by Abhishek BhattacharyaAugust 29th, 2018
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Blockchain Technology is something so vast and amazing that is is being seen as the next big thing. It is analogous to the Internet, wherein people connect over a network and all their data is worked with, online and everything is stored on the web servers, cloud of other companies (Third parties, ofcourse!). In a blockchain technology, several nodes (or computers) are connected in a decentralized, distributed network.

People Mentioned

Mention Thumbnail
Mention Thumbnail

Coins Mentioned

Mention Thumbnail
Mention Thumbnail
featured image - Smart Contracts — A Time Saving Primer
Abhishek Bhattacharya HackerNoon profile picture

Blockchain Technology

Blockchain Technology is something so vast and amazing that is is being seen as the next big thing. It is analogous to the Internet, wherein people connect over a network and all their data is worked with, online and everything is stored on the web servers, cloud of other companies (Third parties, ofcourse!). In a blockchain technology, several nodes (or computers) are connected in a decentralized, distributed network.

Every transaction that takes place (between two or more parties) is validated by all the nodes present in the network. Let’s get into more detail:

What is a block?

A block is simply a finite collection of transactions that is stored with an encryption code within a network. A single block contains a few transactions that must’ve taken place between two or more parties. Every transaction in a block is verified by all the nodes present in the blockchain network and put together in a chronological order forming a chain. The blockchain technology consists of a public ledger that is a type of a register where all transaction details are noted and verified by all nodes before adding it to the chain.

Every transaction or change, for that matter, that takes place within a blockchain environment needs a distributed consensus for it to be added to the chain. The nodes have to validate each transaction; after which the block is created and added in a chronological order of transactions to create a perfect blockchain.

Now, how does it get chained in a chronological order?

There can be numerous transactions occurring at an instance at multiple nodes. So, to solve the problem of knowing the correct chronological order of transactions, all nodes have to solve a complex mathematical problem to calculate the encryption code of the block. Whoever solves the problem first, becomes the first in order of the blockchain, as it has made efforts and used computational power to solve the problem before others. Also, nodes get incentives for validating other nodes’ transactions (that’s why they do it!) and getting them in a chronological order. As they validated first by solving a problem and adding the perfect block in the blockchain, they “mine” Bitcoins (digital cryptocurrency) in the process.

So, now let’s understand how smart contracts work in a blockchain environment.

Smart contracts are also validated by a distributed consensus in a blockchain environment that means everyone in the network who witnesses the smart contract being executed must agree with what is happening and simultaneously copy the changes into their pages (or blocks, here). In a smart contract, there are steps coded within a program that automatically executes when the initial step has been completed. Just as a step executes, each node automatically has copies of it taking place. If for instance, Instruction 1 gets executed in a contract between two parties, it will get announced to the nodes and will be copied by them. Then, Instruction 2 takes place and consequently, another transaction takes place completing all the steps in a contract. At each step, all the changes will be automatically noted by the nodes and will be validated simultaneously. These nodes/miners validate all the actions/transactions that occurred within a smart contract and all the history is noted and stored in similar blocks in a chronological order that we earlier called a blockchain. So, smart contracts function in a blockchain environment, as a result of which, there can be no fraudulent activities, because each encryption code on a block contains a “hash” (encryption code) of the previous block. The previous block’s encryption code contains the hash of the block preceding it, and so on and so forth. So, it’s impossible for a hacker to breach a transaction as it has to calculate the hashes of all nodes, which is impossible. No node present in the network can turn fraudulent. If it doesn’t follow the contract instructions correctly, all the other nodes will get to know as they receive all information and also validate the steps. The contract will be terminated in the case of any breach or any mistake, which is another advantage of smart contracts.

© attores.com

Characteristics Of Smart Contracts

Let’s understand some key characteristics of smart contracts to see how amazingly useful they are:

  1. Smart contracts can call other contracts, if needed. This means that if there are two parts of a contract, wherein the first part is concerned with checking a requirement, then after the condition gets validated the second part of the contract where the task might be to carry out a transaction, will receive the output of the first part and the transaction will take place successfully.
  2. Smart contracts act as accounts that need multiple signatures. Unless a required number of people sign, funds won’t be transferred.
  3. Smart contracts help in managing the agreement between two or more users, for example if one person sells an insurance to the other.
  4. You don’t need to rely on any intermediaries to carry out or confirm your agreements. This removes the risk of a third party manipulation, as execution is done by the network in an automated way.
  5. All the documents are encrypted in a shared ledger so nobody can claim to have lost something of yours.
  6. Everything is backed up in the blockchain, as all the nodes have a copy of it so you can’t really worry about losing data.
  7. The smart contracts are built on a blockchain environment so everything is well encrypted so it would take a really smart hacker to tamper with data.
  8. Smart contracts save your time as all tasks are automated due to them written in software code. This also removes the paperwork and endless settlements and other legalities.
  9. Smart contracts also save you money since no middleman is being paid here, thanks to the blockchain environment!
  10. Smart contracts are pretty accurate as they are automated, which removes the possibility of human errors that may occur in filling out heaps of forms.

Ethereum

Now, as we read that bitcoin (a digital currency) was used in a blockchain environment for carrying out transactions and so they were used earlier for basic smart contracts in a way that concerned the value getting transferred from one node to another. The nodes only validate the movements if some specific conditions are fulfilled. But, Bitcoin is limited to the case of currency use. It is a restrictive code of a few hundred lines that deals mainly in currency transactions. To accommodate various rules and regulations of a smart contract, a less restrictive platform called Ethereum is used. It is basically a platform for all smart contract programs and applications. It replaces Bitcoin (restrictive) and allows the developers to write their own smart contracts as programs as “autonomous entities”. The programming language in which developers can write smart contracts is known to be “Turing-complete” which means it supports a wider range of computational instructions.

Ethereum aims to decentralize and in a way “democratize” the client-server model that exists. Ethereum provides a platform for the smart contracts to run wherein the usual Internet “servers” or “cloud” are replaced by many “nodes” that are run by people volunteering from all around the world, thus creating a “world network” analogous to the Internet. The basic idea is to give complete authority to the user itself rather than depending on third parties like other company servers etc. No other entity can have control over your work any longer, that eliminates the possibility of anything going wrong from the third parties’ end. Every change you make, let’s say to a document that you own or an application you are working on in an Ethereum environment, will be made only by you, any edit, save or delete that you do, will let all other nodes on the network to make similar changes on their end. So, you don’t have to worry about other problems like the application getting banned or corrupt due to some technical failure and you losing your files. Also, whatever work you do in an Ethereum environment reflects in all nodes, so you have backup, apart from just validation of some tasks.

Just as miners get Bitcoins in a usual blockchain network, here in an Ethereum environment, miners earn “ethers” (currency), or tokens for validating all transactions and maintaining the smooth flow of contracts and a correct blockchain.

The difference between Bitcoin and Ethereum is that Ethereum nodes are concerned with the most recent “state” of every smart contract and store that along with all the code in smart contract, each user’s account balance and all the Ether transactions.

In case of Bitcoin, the amount of money left is used to know who has what amount of bitcoin.

Each time a transaction happens, the network distributes the total bitcoin as if it is just actual money (physical), giving back bitcoins in a fashion that appears to be in dividends of actual coins and notes.

In contrast, Ethereum makes use of accounts. Ethereum behaves like a bank account in which ether tokens are present in an ethereum wallet and can be transferred into another account, hence changing the states of the accounts.

In Ethereum, each time a program is to be used, a network of nodes (computers) processes it. The smart contract code that is written by developers in the programming language ‘Solidity’ and ‘Serpent’ (that is easily understood by humans), is compiled into ‘bytecode’, a combination of zeros and ones (01101..), which can be read and executed by a run-time environment called the ‘Ethereum Virtual Machine’ (EVM) in the Ethereum environment. Every node executes a contract using the EVMs.

© lightrains.com

The main thing to understand here is that Ethereum isn’t just like any other cryptocurrency, it is a complete environment, wherein anyone can take benefit of the blockchain technology and create their own DAPPS (decentralized applications) using smart contracts.

Smart Contract Applications

  1. Healthcare through smart contracts — We can use smart contracts to encode and store the personal health reports, using a private key that would be available to only authenticated people for access. Various medical bills and receipts could be stored and can be sent directly to insurance agents as per the smart contract guidelines.
  2. Music — The central problems associated with the music industry are the copyright, ownership, transparency and distribution of royalty. Smart contracts can solve this problem by creating a music rights database that is decentralized. It will provide transfer of artist royalties and distributions in real time. Music players will be paid using the digital currency as per the contract.
  3. Voting system — Many governments claim that the EVMs (Electronic Voting Machines, here) are tampered with, during the elections. By enabling a voting system in a blockchain environment, it would be ensured that the votes cannot be rigged by hackers. The system would prevent such a situation as the votes will be encrypted, and this will save a lot of money too.

Some Imperfections

Let’s consider cases where the smart contracts can go wrong.

What if there’s a bug in the code, or a mistake in any of the listed regulations. Developers are humans and humans can err, right? In that case, the smart contract would still keep on executing in an automated way and that may lead to some incorrect transactions.

If someone sends the wrong code, the incorrect agreement will keep on executing and that is a serious drawback of smart contracts.

Also, how would government think of levying taxes on the transactions going on in the blockchain? That’s got some sure thinking to do about.

If the agreements were being carried out in a traditional way, or any change were to take place, such as extending a date for some submission, then any problem related to these situations would be handled in the court with someone to guide how to rectify this. But in case of a problem that cannot be avoided, there is no court in the blockchain environment.

The future related to smart contracts holds a part of considering these problems and finding out any potential ones.

A sidenote: NEO — China’s competition to Ethereum

Formerly known as Antshares, NEO has recently risen by 376 percent. That’s a whopping number for a crypto currency that was trading at a mere $4 — $6 for quite sometime about a month or so back. NEO is an iteration on Ethereum’s Smart Contracts and uses a unique blockchain algorithm that improve’s upon Ethereum’s current model. NEO closes some loopholes that have made Ethereum smart contracts to be vulnerable to hackers, apart from providing similar basics such as decentralized commerce and digitization of assets.

Let us take a look at the wild jump of this crypto currency which is being considered as an entity that can prove to be the next Alibaba, and its founder, Sun, the next Jack Ma:

© highcharts.com | coinmarketcap.com

Clearly, Ethereum has brought a revolutionary future tech to the world, which is being competed in parallel by innovations across the world. Ultimately, the tech is here to stay. Contracts are old now; decentralization in the form of smart contracts which work in a completely autonomous manner eradicating the need for interventions by any third (centralized) party is taking over as the need of the hour.

And, the unfathomable behavior of the exchange rates of crypto currencies as compared to the general stocks we have been investing into till now shows the volatility of the market for now — maybe till regulatory bodies start to come up and be established. But then, if the market would be regulated by an independent body, wouldn’t it be relying on centralization to control decentralisation, which ultimately sounds paradoxical and is something the world shouldn’t resort to.

Conclusively, Satoshi Nakamoto has given the world a technology that is so futuristic that it makes it bound to stay. On top of that, Vitalik Buterin has given us a technology based on the same blockchain tech that has taken the world of crypto currencies and decentralization steps further, and has brought way more meaning to the associated currencies as compared to the intrinsic valuation of the Bitcoin originally.


I get the views, I don’t get the claps. Is it that you don’t like what I write 😢_, or do you just forget to clap_ 🤔_?_Whatever it is, please let me know? 😌