Hyperledger- A Brief Introduction

Background

In previous articles, we have learned about the bitcoin blockchain, the flagship of cryptocurrency.  Subsequently, we learned about Ethereum that features smart contracts on top of its cryptocurrency Ether. Smart contracts allow developers to create decentralized applications (dapps) on the Ethereum ecosystem.

Both bitcoin and Ethereum are amazing blockchain platforms. However,  both are facing some very challenging issues, one of them is scalability.  According to Wikipedia,  the transaction processing capacity of the bitcoin network is limited by the average block creation time of 10 minutes and the block size limit.  The transaction rate for bitcoin is between 3.3 and 7 transactions per second.

Ethereum does not fare better, its transaction rate is 15 transactions per second. Comparatively, VISA’s transaction rate is 45,000 transactions per second. Therefore, both platforms fall short in developing practical enterprise applications at the moment.

To overcome the limitations of the blockchain technologies for enterprise usage, Hyperledger was created with the vision to provide viable blockchain solutions for industries and businesses. Hyperledger is an open source effort created to advance cross-industry blockchain technologies hosted by The Linux Foundation.

The Mission of Hyperledger

The philosophy of Hyperledger is

“Only an Open Source, collaborative software development approach can ensure the transparency, longevity, interoperability, and support required to bring blockchain technologies forward to mainstream commercial adoption.” –hyperledger.org


Indeed, the Hyperledger project has been a collaboration of players from various industries and organizations in technology, finance, banking, supply chain management, manufacturing, IoT and more. Since its inception in December 2015, it has managed to enlist many prominent members that include IBM, Intel, NEC, Cisco, J.P Morgan, AMN AMRO, ANZ Bank, Wells Fargo, Accenture, SAP and more. For the complete list, please refer to Wikipedia.

The mission of Hyperledger comprises some ambitious goals, as  illustrated in the following figure,

Adapted from Linux foundation

The Hyperledger Greenhouse

Hyperledger itself is not a platform, but it is an umbrella body that incubates and promotes a range of business blockchain technologies. The technologies include distributed ledger frameworks, smart contract engines, client libraries, graphical interfaces, utility libraries, and sample applications. The umbrella strategy was able to accelerate innovation of DLT components by encouraging the re-use of common building blocks and components(hyperledger.org, 2018).

The Hyperlegder projects known as The Hyperledger Greenhouse consists of five projects and five tools, as shown in the figure below:

Adapted from hyperledger.org

Each of the frameworks operates differently but they also allow certain interoperability among themselves. Hyperledger frameworks are generally permissioned (private)blockchains. It means that the parties need authentication and authorization to participate on the blockchain networks.

I will try to explain some of the frameworks and tools in simple language in a series of future articles. I am not an expert on Hyperledger but I have a decent understanding of the technologies via theories and practice. Recently I have enrolled in a Hyperledger course hosted by the Linux Foundation and managed to obtain a certificate of achievement. I am willing to share my knowledge with you.

Certificate  Link:  https://courses.edx.org/certificates/893fe1d735404398b56460873940ca5d

Open Source and Open Governance

The success of Hyperledger is based on the concepts of open source and open governance.  The concept of open source means that an open source software is a software that is made freely available and may be redistributed and modified. In other words, anyone has the ability to view the code, use the code, copy the code, modify the code, and, depending on the open source license, contribute back changes. (hyperledger.org, 2018)

On the other hand, open governance means that technical decisions for an open source project are made by a group of community-elected developers voted in from a pool of active participants. These decisions include things such as which features to add, how, and when to add them.  (hyperledger.org, 2018).  Hyperledger has formed a  Technical Steering Committee(TSC) to implement open governance pertaining to the Hyperledger projects. You can read about Hyperledger’s open governance by following this link

https://www.hyperledger.org/blog/2017/09/06/abcs-of-open-governance

That’s all for now. I will discuss why Hyperledger blockchain frameworks are better designed for enterprises than the public permissionless blockchains in coming articles.

Meanwhile, you may want to register for the Hyperledger Global Forum in Basel, Switzerland in December. I have registered but not sure of going yet as there is an issue with the credit card payment. By the way, there are no free tickets. It is a four days workshop with hands-on practices. 

Tokenization Explained

What is Tokenization?

Tokenization has become a buzzword today due to its adoption in the payment industry and blockchain. However, Its usage is not limited to the aforementioned industries. It can be applied to many other industries such as healthcare, stock trading, gaming and more.

The primary purpose of tokenization is to ensure data security. It is used for handling sensitive data such as payment, medical record, personal ID and more.

According to Wikipedia,

“Tokenization, when applied to data security, is the process of substituting a sensitive data element with a non-sensitive equivalent, referred to as a token, that has no extrinsic or exploitable meaning or value. The token is a reference (i.e. identifier) that maps back to the sensitive data through a tokenization system. The mapping from original data to a token uses methods which render tokens infeasible to reverse in the absence of the tokenization system, for example using tokens created from random numbers.

The tokenization system must be secured and validated using security best practices applicable to sensitive data protection, secure storage, audit, authentication and authorization. The tokenization system provides data processing applications with the authority and interfaces to request tokens, or detokenize back to sensitive data.”

In short, Tokenization is the process of substituting sensitive data with non-sensitive identification symbols known as tokens. Tokenization retains all the essential information of the data without compromising its security.

A Short History

According to Wikipedia, the concept of tokenization has existed since the invention of the currency system centuries ago. It was adopted as a means to reduce risk in handling financial instruments by replacing them with surrogate equivalents.

In addition, coin tokens have a long history of use replacing the financial instrument of minted coins and banknotes. In more recent history, tokens are used in mass rapid transit payment, casino chips and more.  The adoption of the above systems is to replace physical currency and cash for reducing risks such as theft.

In the digital world, tokenization techniques have been used since the 1970s. They were meant to isolate real data elements from exposure to other data systems(Wikipedia, 2018). In databases, surrogate key values have been used since 1976 to isolate data associated with the internal mechanisms of databases and their external equivalents for a variety of uses in data processing.

More recently, these concepts have been extended to consider this isolation tactic to provide a security mechanism for the purposes of data protection. For example, in the payment card industry, tokenization is one means of protecting sensitive cardholder data in order to comply with industry standards and government regulations.

Definition in Blockchain

In blockchain, tokenization is a method that converts rights to an asset into a digital token. Thus, we can take an asset, tokenize it and create its digital representation that lives on Blockchain. Blockchain guarantees that the ownership information is immutable.  The tokens created in this way is also known as crypto tokens.

For example, you can tokenize an asset such as a book that you authored. The book is kept somewhere while the book token is uploaded to the blockchain network. The book crypto token is a representation of the book ownership. You can specify how many tokens need to be transferred to your crypto wallet before you can transfer the book ownership to a buyer by means of a smart contract.

One of the actual use cases is https://stamp.io , a platform where you can store your tokenized documents on the block and certify it, as shown in the following figure:

Cryptokitties is a brilliant example of the crypto token that allows users to acquire an adorable collectible by transferring some cryptocurrencies to the owner. The owner will then transfer the digital collectible to the buyer. The transaction occurs automatically via the smart contract.

Another use case is we can create a crypto token that represents some customer loyalty points on a blockchain. This type of token is also known as utility token. It can be used to manage customers’ reward schemes for the retail chains. Other examples include the crypto token that gives entitlement to the token holder to view certain hours of video streaming on a video-sharing blockchain. A house owner can sell his house by transferring the tokenized house deed to the buyer. Last but not least, a crypto token may even represent another cryptocurrency.

When to use blockchain?

Factors to Consider before Adopting Blockchain

Blockchain is the coolest and most innovative technology at the moment. Many people believe It has the potential to disrupt many technologies. However, the blockchain technology is still far from mature. It is still facing numerous issues, scalability is one of them. Therefore, it is advisable to conduct a thorough study before adopting the blockchain technology.

Adopting the blockchain technology is akin to business process re-engineering which might incur heavy costs. Besides that, an organization might face certain new risks. Therefore, businesses and other organizations must evaluate many factors before adopting the blockchain technology. They need to carry out an inventory  analysis by asking the following questions like,

  • How many participants are in the system?
  • What is the geographical distribution of the participants?
  • What sort of performance requirements do they have?

On top of that, they need to specify the rules, risks, and responsibilities of each party in your blockchain ecosystem before transferring the present centralized database to a decentralized blockchain network.  According to some expert opinions, blockchain is best suited for business applications where one or more of the following conditions apply:

  • There is a need for a shared common database
  • The parties involved with the process have conflicting incentives in a trustless environment.
  • There are multiple parties involved in the environment.
  • There are uniform rules governing participants in the system
  • Decision making of the parties is transparent, rather than confidential
  • There is a need for an objective, immutable history or log of facts for parties’ reference
  • Transaction frequency does not exceed 10,000 transactions per second.

When Not to Use Blockchain

Although blockchain is a powerful tool,  it is not always the right tool. If a business is contemplating using blockchain technology, it needs to evaluate the issues fully.  The following conditions are not currently well suited to blockchain-based solutions:

  • The process involves confidential data
  • The process stores a lot of static data, or the data is quite large
  • Rules of transactions change frequently
  • The use of external services to gather/store data

Smart Contracts

Introduction

In the blockchain network, a user can send some crypto money to another user in exchange for something of value where the transaction is executed automatically based on a smart contract. In another case, a smart contract is executed when a user acquires a unique virtual kitty from the Cryptokitties collectible marketplace via a bidding process, the highest bidder gets to own the digital asset.

On the other hand, a transaction can occur automatically between two smart devices using an integrated system of IoT technology and blockchain. For example, a smartphone A can top up data for another smartphone B after A received some money from B, the transaction occurs based purely on a smart contract without the awareness of the owners.

According to Investopedia, smart contracts are ,

“self-executing contracts with the terms of the agreement between buyer and seller being directly written into lines of code. The code and the agreements contained therein exist across a distributed, decentralized blockchain network. Smart contracts permit trusted transactions and agreements to be carried out among disparate, anonymous parties without the need for a central authority, legal system, or external enforcement mechanism. They render transactions traceable, transparent, and irreversible.”

Definition of Smart Contract

Based on the aforementioned descriptions, we can define a smart contract as a computer code that can facilitate the exchange of money, content, property, shares, digital assets or anything of value among disparate and anonymous parties without a middle entity.

When a smart contract is installed in a blockchain system, it behaves like a self-operating computer program that automatically executes when some specific terms and conditions are met. Because smart contracts run on the blockchain, they run exactly as programmed without any possibility of censorship, downtime, fraud or third-party interference.

A Brief History of Smart Contracts

In contrary to popular belief, the smart contract is not invented by Vitalik Buterin, the founder of Ethereum. In actual fact, the idea of the smart contract was first conceived by computer scientist and cryptographer Nick Szabo in 1993 as a kind of digital vending machine. In his famous example, he described how users could input data or value, and receive a finite item from a machine, in this case, a real-world snack or a soft drink. Nick Szabo is so smart that some people believe that he could be Satoshi Nakamoto who invented bitcoin.

In addition, though Ethereum is the first blockchain system that has adopted the smart contract technology, it is not the only one using smart contracts. Many Non-Ethereum blockchain platforms such as Hyperledger Fabric, Hyperledger Sawtooth and Corda implement their own versions of smart contracts. The smart contract in Hyperledger Fabric is known as Chaincode that runs in a container known as docker(I will discuss Chaincode and how to install it in Docker in a future article). 

Today, most blockchain platforms run on Ethereum Virtual Machine(EVM) implement Ethereum smart contract while a few enterprise blockchain platforms implement their own version of smart contracts. However, there could be interoperability between the Ethereum platform and the enterprise platforms. For instance, in the Sawtooth-Ethereum integration project,  EVM (Ethereum Virtual Machine) smart contracts can be deployed to Sawtooth using the Seth transaction family.  I will discuss Hyperledger technologies in another article.

Solidity

Solidity is a high-level programming language that is used to create and implement smart contracts on Ethereum platform. The smart contracts created using Solidity can be used for financial transactions, crowdfunding, voting, supply chain management, IoT implementation, ride sharing automation, smart city administration and more.

Solidity has Python, C++ and JavaScript influences. Therefore, it is fairly convenient and easy to grasp for those that are already familiar with the Python, C++ or JavaScript. 

Writing and Deploying the Smart Contract

The Integrated Development Environment (IDE)

The best tool to write, compile, test and deploy smart contracts is RemixRemix is a browser-based IDE that provides an inbuilt compiler as well as a run-time environment without server-side components. You can access Remix from the following link: https://remix.ethereum.org

We can also use other code editors for Solidity . I suggest we use Visual Studio Code or Solidity Plugin for Visual Studio. For Solidity plugin, you need to download it from https://marketplace.visualstudio.com/items?itemName=ConsenSys.Solidity

Besides that, you need to install Visual Studio 2015. I shall skip the technical details for now. (I will discuss how to use Visual Studio Code in compiling and deploying smart contracts in another article).

The Smart Contract Code

A smart contract is a data, that can be referred to as its state, and code, which can be referred to as its functions, collection, that resides on a specific address in the Ethereum blockchain. Let us begin with the most basic example. It is fine if you do not understand everything right now, we will go into more detail later. Enter the follow codes in the Remix IDE and save the file as MyStorage.sol

pragma solidity ^0.4.25;

contract MyStorage {
   uint storedData;

   function set(uint x) public {
       storedData = x;
   }

   function get() public view returns (uint) {
       return storedData;
   }
}

Understanding the Code

The first line simply tells that the source code is written for Solidity version 0.4.25 or anything newer that does not break functionality .This is to ensure that the contract does not suddenly behave differently with a new compiler version. The keyword pragma is called that way because, in general, pragmas are instructions for the compiler about how to treat the source code.

A contract in the sense of Solidity is a collection of code (its functions) and data (its state) that resides at a specific address on the Ethereum blockchain. The line uint storedData; declares a state variable called storedData of type uint(unsigned integer of 256 bits). You can think of it as a single slot in a database that can be queried and altered by calling functions of the code that manages the database. In the case of Ethereum, this is always the owning contract. And in this case, the functions set and get can be used to modify or retrieve the value of the variable.

To access a state variable, you do not need to use the prefix this that is commonly used in other programming languages. This is just a simple contract that does not do much yet apart from allowing anyone to store a single number. This number is accessible by anyone in the world without a feasible way to prevent you from publishing this number. Of course, anyone could just call set again with a different value and overwrite your number. However, the number will still be stored in the history of the blockchain. Later, we will see how you can impose access restrictions so that only you can alter the number.

The Remix IDE

Now enter the code in the Remix IDE, as shown in the following figure:

The Metamask Wallet

In addition, you need to install the Metamask wallet using the Chrome or Firefox extension plugin. After installing Metamask, create an account and connect it to Ropsten Test Network, as shown in the figure below:

Besides that, you need to get some free Ethers to run the test. You can get 1 free Ether for Rospten Testnet from  https://faucet.ropsten.be/. Upon loading the website, copy and enter your Metamask wallet address, and click the send me test Ether button, as shown in the following figure:

After a  while, you can see 1 Ether is deposited into your Metamask wallet, as shown in the figure below:

Next, in the Remix IDE, change the environment to Injected web3, the Ropsten Test Network. You can see that your wallet address appears in the account box, as shown in the first Figure. Now click on the Deploy button. After clicking this button, the Metamask wallet will pop up, prompting for confirmation, as shown in the following figure:

After clicking the CONFIRM button, you will see that some Ether had been deducted from your account which showed that the contract has been successfully deployed, as shown in the following Figure:

Besides that, you can also view the transaction on Etherscan, as shown in the following Figure:

Finally, you can also check the deployment of the smart contact in the Remix debug window, as shown in the following figure:

In addition, you can view some extra information on the right column on the Remix windows, like the name of the smart contract(Mystorage) , how much gas limit and how many transaction etc.

If you are sure the smart contract is bugs free, you may want to deploy it to the Ethereum Mainnet. In that case, change the Environment to Web3 Provider. You will be prompted with the following dialog:

Wait, you need to install Go Ethereum, the client commonly referred to as geth, which is the command line interface for running a full Ethereum node implemented in Go. Install Go Ethereum from the following link: https://geth.ethereum.org/downloads/

After installing Go Ethereum, there a few more windows system set up before you can run geth. I will not go through the steps here, a bit tedious, I have documented them in another document. If you are keen I can share it with you in the future. Let’s say your environment is ready, you can key in the following command in the command line:

geth --rpc --rpccorsdomain "https://remix.ethereum.org" console

Your computer will now link to the Ethereum mainnet via Remix, as shown in the following figure:

Now click OK on the Remix dialog and bring up the next dialog that prompts you to connect to the Web3 Provider Endpoint, as shown in the figure below:

Click OK and now you can deploy the contract to the Ethereum Main Network. Notice that now the Environment is Web3 Provider, which is the Ethereum Mainnet, as shown in the following Figure:

Before you can deploy the smart contract to the Ethereum mainnet ,you need to have the actual Ether to deploy the contract. I suggest you don’t do it here unless you have developed the actual use case and ready to go for ICO.

Happy Learning!

Creating Your Own Token for ICO

ICO is a hot topic in the crypto world today. In this article, I will attempt to explain how to create your own token for an ICO project. 

First of all, you need to set up a private Ethereum network, before you can proceed to create the token. After setting up the private network, you need to run it. (The detail steps for setting up a private Ethereum network is discussed in another article)

Next, you need to install the Ethereum wallet before you proceed. Follow the steps below to install the Ethereum Wallet.

  1. Install Ethereum Mist Wallet for Windows 10.
  2. Visit the link https://github.com/ethereum/mist/releases
  3. Download Ethereum-Wallet-win64-0-11-0.zip
  4. Create a folder Ethereum under the Program Files folder and extract the zip files there.

Launch the Ethereum wallet after successful installation. Also, create an account in the wallet.

Next, Open the Wallet app and then go to the Contracts tab as shown in the figure below:

Click on DEPLOY NEW CONTRACT and bring up the  Solidity Contract Source code text editor as shown the following figure:

Now type the following smart contract  code in the code editor.

pragma solidity ^0.4.24;

contract BestToken {
    /* This creates an array with all balances */
    mapping (address => uint256) public balanceOf;
     string public name;
     string public symbol;
     uint8 public decimals;

    /* Initializes contract with initial supply tokens to the creator of the contract */
 constructor(
     uint256 initialSupply,
     string tokenName,
     string tokenSymbol,
     uint8 decimalUnits
     ) public {
     balanceOf[msg.sender] = initialSupply;  // Give the creator all initial tokens
     name = tokenName;                        // Set the name for display purposes
     symbol = tokenSymbol;                   // Set the symbol for display purposes
     decimals = decimalUnits;               // Amount of decimals for display purposes
    }
    

    /* Send coins */
    function transfer(address _to, uint256 _value) public returns (bool success) {
     require(balanceOf[msg.sender] >= _value);   // Check if the sender has enough
     require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows
     balanceOf[msg.sender] -= _value;                    // Subtract from the sender
     balanceOf[_to] += _value;                        // Add the same to the recipient
     return true;
    }
}

Don’t worry about the code first, I will explain them in another article.

If the code compiles without any error, you should see a “pick a contract” drop-down list on the right, as shown in the figure below:

Click Pick a contract button and select the “BestToken” contract. On the right column, you’ll see all the parameters you need to personalize your own token. You can tweak them as you like, I use the following parameters: 10,000 as the supply, BestCoin for the token name, “#” as the symbol and 2 decimal places. Your wallet should be looking like this:

Scroll to the end of the page and you’ll see an estimate of the computation cost of that contract and you can select a fee on how much Ether you are willing to pay for it. Any excess Ether you don’t spend will be returned to you so you can leave the default settings if you wish. Press “deploy”, type your account password and wait a few seconds for your transaction to be picked up.

Now click the DEPLOY button to deploy the smart contract, the output dialog is as follows:

Upon entering the password for your account and click send transaction, the contract is successfully deployed, as follows:

Now the new token Best Token is shown in your wallet, as follows:

Tokens are currencies and other fungibles built on the Ethereum platform. In order for accounts to watch for tokens and send them, you have to add their address to this list. Proceed to add BestCoin to the list, as shown in the following figure.

Now the new token BestCoin will be shown in the list, as shown in the figure below.  

Now you can send some funds from BestCoin to a wallet, as shown in the figure below:

References