Smart Contracts In Blockchain In The World Of Internet 3.0

uttam gandhi
10 min readMay 22, 2020

Blockchain isn’t a household buzzword, similar to the cloud or the Artificial Intelligence. It’s not an in-your-face innovation you can see and contact as effectively as a cell phone or a bundle from Amazon. In this present reality where anybody can alter a Wikipedia passage, blockchain is the response to a question we’ve been posing since the beginning of the web age: How can we by and large trust what happens on the web?

Reliably we run a more prominent measure of our lives — core components of our organizations, economies, and societies — on the web. We do our banking on the web. We shop on the web. We sign into applications and administrations that make up our digital selves and send data to and fro. Consider blockchain a historic fabric underneath recording everything that occurs — each digital transaction; trade of value, goods and services; or private information — precisely as it happens. By then the chain lines that data into encoded blocks that can never be adjusted and dissipates the pieces over an overall system of appropriated PCs or “nodes”.

The blockchain by itself has taken a life of its own and permeated a broad range of applications across many industries, including finance, healthcare, government, manufacturing, and distribution. The blockchain is ready to advance and innovate wide scope of applications, including goods transfer, for example, supply chain. Digital media transfer, for example, sale of art. Remote services conveyance, example, travel and tourism. Stage for decentralized business rationale, for example, moving computing to data sources and distributed intelligence, example, education credentialing. Additional applications of blockchain include distributed assets, for example, power generation and distribution. Crowd funding for example, startup fund raising. Crowd operations, for example, electronic voting. Identity management, for example, one ID for all your life’s functions.

And government public records and open governing. Moreover, blockchain can enable an inclusive economy. It can enable a person in a remote corner of the world to partake in a democratic process.

What is a Blockchain?

A Blockchain is a technology that allows users to store information or data in a decentralized or centralized system using strong encryptions and providing anonymity to the users. Immutability lies at the heart of every Blockchain system, making it nearly impossible for users to change any information which has already been recorded on the system.

Blockchain is the brainchild of Satoshi Nakamoto, who used it for creating Bitcoin. He designed a decentralized system which allowed users to authenticate every transaction before it was placed on the block. Only when the transaction is authenticated it is added to the Blockchain.

Once the transaction is placed on the Blockchain, it cannot be altered or deleted. This ensures transparency of the transactions but provides anonymity to the users.

With no central authority, Bitcoin realize trust and security by implementing software programs for validation, verification, consensus in a novel infrastructure called the blockchain. Later on in about 2012, 2013, computation elements were added to the blockchain infrastructure that has opened up a whole world of possibilities beyond simple currency transfer.

The basic structure of a blockchain include the following —

Transaction is the viewed as the fundamental component of the Blockchain. Transactions are validated and broadcast.

Numerous transactions struct a block.

Many box structure a chain through a digital data link.

Blocks go through a consensus process, to select the next block that will be added to the chain.

Chosen block is verified, and added to the current chain.

Validation and consensus process are carried out by special companion nodes called miners.

These are powerful computers executing programming characterized by the blockchain protocol.

Smart Contracts in Blockchain

Many people invariably connect Blockchain with cryptocurrencies. It is true that our introduction to Blockchain was through a cryptocurrency — Bitcoin. We must understand the technology offers far more potential to the world.

Cryptocurrencies such as Bitcoin, enable transfer of values such as money or currency from peer-to-peer without any intermediaries. But we may want the gift to be delivered on a certain date. Buy a product of a particular color and quality. We may need some credentials verified for renewing the license. And we may need a specific tulip bouquet to be delivered to Gaurav. This introduces conditions, rules, policies beyond that of which a simple money transfer cryptocurrency protocols can handle. Smart contract addresses this need for application specific validation for blockchain applications. Smart contract has some advantages including, a smart contract facilitates transaction for transfer of assets other than value or cryptocurrency. Smart contract allows specification of rules for an operation on the blockchain. It facilitates implementation of policies for transfer of assets in a decentralized network. It also adds programmability and intelligence to the blockchain. The smart contract represents a business logic layer, with the actual logic coded in a special high level language. Some couldn’t have even imagined online shopping,mobile application or Uber 20 years ago. Smart contract is ushering the next generation blockchain that goes beyond the transfer of value into a visionary realm.Smart contract allows for implementation of rules, policies and with the help of blockchain, supports the methods for governance and provenance.

Many companies have already identified and invested in Blockchain technologies to improve existing business processes. Some end users may not even be aware that the products or services they utilize may be directly or indirectly connected to the use of Blockchain. For example, smart contracts are now paving a way for secure and improved digital commerce services.

What are Smart Contracts?

The concept of the smart contract was there well before the advent of the Bitcoin. Computer scientist Nick Szabo detailed his idea of cryptocurrency Bit gold as a sort of a precursor for Bitcoin. He also outlined the concept of smart contract in his 1996 publication. In fact, Szabo coined the term smart contract more than 20 years ago. Smart contract is a centerpiece and main thrust of Ethereum blockchain. It is the good, bad and the ugly of the blockchain technology.Smart contracts are lines of codes which depict an agreement between two or more parties. The smart contract can be executed only when all requirements for it are fulfilled.

If you buy a mobile and choose to get it financed, you will have to go through a long and tiring process of filling lots of paperwork and completing the credit check. The agents may also require fees or commission to be paid before the finance request can be completed. This increases the price of your mobile and takes a lot of time. The lack of trust between the mobile dealer, the finance company and you also leads to extensive paperwork to ensure that every party has complete information required to hold each other responsible in the court of law if things do not go fine.

With the help of a smart contract, the process can be streamlined. Your identity would be stored on the Blockchain and a credit check will automatically be initiated if you opt to finance the mobile. The financial institution can easily decide to approve or reject your credit request. If approved, a smart contract will be created between you, the financial institution and the mobile dealer.

Once the lending agency releases payment to the dealer, the mobile’s ownership will be under the lender’s details. When you pay the last installment of the mobile, the ownership will automatically be transferred to your name through the smart contract. Since the whole process is handled through a smart contract, you have to face fewer hassles.

In the same way, smart contracts can be used for just about any agreement that you enter.

Blockchains are being used to store smart contracts because they are highly secure. They provide transparency in the transactions so anyone can go through the smart contract but cannot change or delete them.

Benefits of smart contracts include

Autonomy — You’re the one settling on the agreement; there’s no compelling reason to depend on a specialist, legal counselor or different delegates to affirm. Incidentally, this takes out the threat of manipulation by an outsider, since execution is overseen automatically by the network, instead of by at least one or more, possibly biased, individuals who may fail.

Trust — Your documents and transactions are encrypted on a shared ledger. It is extremely unlikely that somebody can say they lost it.

Backup — Imagine if your bank lost your investment account. On the blockchain, all of your companions have your back. Your reports are copied many occasions over.

Safety —Cryptography ,the encryption of sites, protects your records. There is no hacking. Truth be told, it would take an anomalous brilliant programmer to decipher the code and penetrate.

Speed — You’d commonly need to invest loads of energy and administrative work to physically process reports. Smart contracts use programming code to mechanize errands, accordingly shaving hours off a scope of business forms.

Savings — Smart contracts save you money since they take out the presence of a middle person. You would, for example, need to pay a legal official to observe your transaction.

Accuracy — Automated contracts are quicker and less expensive as well as maintain a strategic distance from the blunders that originate from physically filling out stacks of forms.

How do Smart Contracts Work?

Smart contracts are lines of codes that are executed when a series of conditions is fulfilled. If a smart contract is executed, it will be put in the Blockchain as a block, where it will reside forever in proof of the agreement it has executed. The Blockchain can’t be compromised easily which makes them very safe and guarantees the smart contracts won’t be altered or withdrawn.

Every smart contract follows clear statements about “if / when … then ….” On a Blockchain, these statements are written in code. When predefined conditions are met and authenticated, computers linked to the same Blockchain network will perform the actions specified in the contract.

Smart Contract Development — Defective Component Counter Application

The Defective Component Counter application is an example of using a fixed length array of integers in Azure Blockchain Workbench. The application lets a manufacturer get the total number of defective components over twelve months. The main objective of this simple application is to show how arrays of fixed length can be declared in a contract’s configuration file and used in the corresponding contract code file in Azure Blockchain Workbench.

pragma solidity >=0.4.25 <0.6.0;contract DefectiveComponentCounter {//Set of States
enum StateType {Create, ComputeTotal}
//List of properties
StateType public State;
address public Manufacturer;
int[12] public DefectiveComponentsCount;
int public Total;
// constructor function
constructor(int[12] memory defectiveComponentsCount) public
{
Manufacturer = msg.sender;
DefectiveComponentsCount = defectiveComponentsCount;
Total = 0;
State = StateType.Create;
}
// call this function to send a request
function ComputeTotal() public
{
if (Manufacturer != msg.sender)
{
revert();
}
// calculate total for only the first 12 values, in case more than 12 are entered
for (uint i = 0; i < 12; i++)
{
Total += DefectiveComponentsCount[i];
}
State = StateType.ComputeTotal;
}
// add the required getter function for array DefectiveComponentsCount
function GetDefectiveComponentsCount() public view returns (int[12] memory) {
return DefectiveComponentsCount;
}
}

An instance of the Defective Component Counter application’s workflow starts when a Manufacturer creates a contract by specifying the number of defective components for the last twelve months. The manufacturer calls the function ‘ComputeTotal’ to compute the total number of defective components after the contract is created. The total number of defective components is tracked as a property in the contract and is updated when the ComputeTotal function executes.

Testing:

{ “ApplicationName”: “DefectiveComponentCounter”,
“DisplayName”: “Defective Component Counter”,
“Description”: “A simple application to total the number of defective components over 12 months.”,
“ApplicationRoles”: [{
“Name”: “Manufacturer”,
“Description”: “A person manufacturing components.” } ],
“Workflows”: [{
“Name”: “DefectiveComponentCounter”,
“DisplayName”: “Defective Component Counter”,
“Description”: “A simple workflow to total the number of defective components over 12 months.”,
“Initiators”: [“Manufacturer”],
“StartState”: “Create”,
“Properties”: [{
“Name”: “State”,
“DisplayName”: “State”,
“Description”: “Holds the state of the contract.”,
“Type”: {
“Name”: “state”}},
{ “Name”: “Manufacturer”,
“DisplayName”: “Manufacturer”,
“Description”: “A person manufacturing components.”,
“Type”: {
“Name”: “Manufacturer” }},
{ “Name”: “DefectiveComponentsCount”,
“DisplayName”: “Monthly count of defective components”,
“Description”: “…”,
“Type”: {
“Name”: “array”,
“ElementType”: {
“Name”: “int” } } },
{ “Name”: “Total”,
“DisplayName”: “Total number of defective components”,
“Description”: “…”,
“Type”: {
“Name”: “int”
} } ],
“Constructor”: {
“Parameters”: [{
“Name”: “defectiveComponentsCount”,
“Description”: “…”,
“DisplayName”: “Enter number of defective components for 12 months.”,
“Type”: {
“Name”: “array”,
“ElementType”: {
“Name”: “int”
} } } ] },
“Functions”: [{
“Name”: “ComputeTotal”,
“DisplayName”: “Compute Total”,
“Description”: “…”,
“Parameters”: []
}],
“States”: [{
“Name”: “Create”,
“DisplayName”: “Create”,
“Description”: “…”,
“PercentComplete”: 50,
“Value”: 0,
“Style”: “Success”,
“Transitions”: [{
“AllowedRoles”: [],
“AllowedInstanceRoles”: [“Manufacturer”],
“Description”: “…”,
“Function”: “ComputeTotal”,
“NextStates”: [“ComputeTotal”],
“DisplayName”: “Compute Total”
}]},
{ “Name”: “ComputeTotal”,
“DisplayName”: “Compute Total”,
“Description”: “…”,
“PercentComplete”: 100,
“Value”: 1,
“Style”: “Success”,
“Transitions”: []
} ] }]}

Thank You

--

--