Chapter 9

Getting Your Hands on Hyperledger

IN THIS CHAPTER

Bullet Uncovering Hyperledger Foundation

Bullet Discovering key Hyperledger projects

Bullet Building an asset tracking platform

Bullet Creating chaincode smart contracts

Hyperledger is a foundation that supports a community of software developers and technology enthusiasts who are building industry standards for blockchain frameworks and platforms. Hyperledger’s work is crucial because they’re creating blockchain technology that fit the needs of businesses. Cryptocurrencies on public blockchains have regulatory implications and liabilities that prevent many companies from utilizing these networks. Hyperledger has many of the same benefits of public blockchain technology but operates without a cryptocurrency. With big supporters such as Intel and IBM, Hyperledger is the “trusted” deployment platform for enterprise teams.

Hyperledger and its unique project are growing every day. As of this writing, it has more than 100 member companies and several blockchain applications in incubation. Hyperledger’s first few projects include Fabric, Iroha, and Sawtooth. These are frameworks that developers can use to build private blockchains, create smart contracts, and build distributed identity for people and things.

In this chapter, I explain how to create an asset tracking and a smart auction application using Hyperledger’s Composer tool. I also introduce you to the Fabric, Iroha, and Sawtooth projects. You gain a deep understanding of what the future of commercialized blockchain will hold for your company and industry. This knowledge will help you as you explore which technologies to utilize and which to avoid, saving you development time and resources.

Getting to Know Hyperledger

At the end of 2015, the Linux Foundation formed the Hyperledger project to develop an enterprise-grade and open-source distributed ledger framework. They hoped to focus the blockchain community on building robust, industry-specific applications, platforms, and hardware systems to support businesses.

The Linux Foundation saw that there were many different groups building blockchain technology without a cohesive direction. The industry was duplicating effort, and the tribalism was leading teams to solve the same problem twice. The foundation members saw similarities between the birth of the Internet and the emergence of blockchain technology: If blockchain was going to realize its fullest potential, an open-source and collaborative development strategy was desperately needed.

The Hyperledger project is led by Executive Director Brian Behlendorf, who has decades of experience dating back to the original Linux Foundation and Apache Foundation, as well as being a chief technology officer (CTO) of the World Economic Forum. So, it’s not surprising that Hyperledger has been well received. Many of the top business and industry leaders have joined the project, including Accenture, Cisco, Fujitsu Limited, IBM, Intel, J.P. Morgan, and Wells Fargo. It has also attracted many of the top blockchain organizations.

Hyperledger’s technical steering committees ensure robustness and interoperability between these different technologies. The hope is that the cross-industry, open-source collaboration will advance blockchain technology and deliver billions of dollars in economic value by sharing the costs of research and development across many organizations.

Hyperledger is identifying and addressing the critical features and requirements missing from the blockchain technology ecosystem. It’s also fostering a cross-industry open standard for distributed ledgers and holding open space for developers to contribute to building better blockchain systems.

Hyperledger has a project life cycle similar to that of the Linux Foundation. A proposal is submitted, and then the accepted proposals are brought into incubation. When a project has reached a stable state, it graduates and is moved into an active state. As of yet, all Hyperledger projects are in the proposal or incubation stage. Each of the projects is led by a large corporation or startup. For example, Fabric is led by IBM, Sawtooth by Intel, and Iroha by the startup Soramitsu.

Tip Hyperledger, like many open-source projects, uses GitHub (www.github.com/hyperledger) and Slack (https://slack.hyperledger.org) to connect with teams working on each of the projects. These are great places to get the latest updates and to check on the progress that these projects are making in development.

Identifying Key Hyperledger Projects

Hyperledger has several revolutionary projects under incubation. In this section, I fill you in on the three most prominent and well-developed projects. These blockchain technologies include distributed ledger frameworks, smart contract engines, client libraries, graphical interfaces, utility libraries, and sample applications.

Focusing on Fabric

Fabric was the first blockchain implementation on Hyperledger. It has become the foundation for developing most blockchain applications. Fabric is unique within the blockchain ecosystem because it allows developers to use pieces of Fabric without committing to all the functionality — a truly tailored plug-and-play experience. Fabric also can create smart contracts called chaincode.

Fabric is a permissioned blockchain and does not utilize a cryptocurrency. This means that all the participants are known (as opposed to on a typical public blockchain where all the participants are anonymous by default). Fabric works like most blockchains in that it keeps a ledger of digital events. These events are structured as transactions and shared among the different participants. The transactions are executed without a cryptocurrency (in contrast, a public blockchain uses its native cryptocurrency to pay the network to operate and to allow all the participants to remain anonymous). To dive deeper into the subject of Fabric, go to https://trustindigitallife.eu/wp-content/uploads/2016/07/marko_vukolic.pdf.

All transactions are secured, private, and confidential. Fabric preserves its integrity by only allowing updates by consensus of the participants. When records have been inputted, they can never be altered.

Fabric is an enterprise solution interested in scalability and complying with regulations. All participants must register proof of identity to membership services to gain access to the system. Fabric issues transactions with derived certificates that are unlinkable to the owning participant, thereby offering anonymity on the network. Also, the content of each transaction is encrypted to ensure only the intended participants can see the content.

Fabric has a modular architecture. You can add or take away components by implementing its protocol specification. Its container technology can handle most of the mainstream languages for smart contracts development.

Investigating the Iroha project

Hyperledger’s Iroha project is building on the work completed in the Fabric project. It’s meant to complement Fabric, Sawtooth Lake, and the other projects under Hyperledger. Hyperledger added the Iroha project to incubation because the other projects didn’t have any infrastructure projects written in C++. Not having a C++ project severely limited how many people could benefit from the work on Hyperledger and the number of developers who could contribute to the project.

Besides, most blockchain development at this point has been at the lowest infrastructure level, and there has been little to no development work on user interaction or mobile applications. Hyperledger believes that Iroha is necessary for the popularization of blockchain technology. This project fills the gap in the market by bringing in more developers and providing libraries for mobile user interface development.

At the time of this writing, Iroha is a very new project and has not integrated with Fabric or Sawtooth Lake. Hyperledger has plans to expand functionality to work with the other blockchain projects soon. Its iOS, Android, and JavaScript libraries will provide supportive functions like digitally signing transactions. It will be handy for commercial app development, and it will add new layers of security and business models only possible with blockchain technology.

Introducing Sumeragi: The new consensus algorithm

Blockchains have systems that allow them to first agree on a single version of the truth and then record that agreed-upon truth in their ledger. An agreement system is called a consensus. A consensus is complicated. Grasping the nuances of how and why consensuses act in the way they do is well beyond the scope of this book. It’s also far more then you’ll ever need as a business professional. What does matter for you are the consequences of different consensus mechanisms and how they affect what you’re doing on that particular blockchain. I’m highlighting Iroha’s consensus, Sumeragi, because it’s very different from traditional blockchains.

Here are a few key things that make Sumeragi different:

  • Sumeragi does not have a cryptocurrency.
  • Nodes that start consensus are added into the system by the Fabric member services. Nodes build a reputation over time based on how they’ve interacted with the ledger. This is a permission blockchain run by known entities.
  • New entries are added to the ledger in a unique way. The first node that starts consensus, called the leader, broadcasts the entry to a group of other nodes; those nodes then validate. If they don’t validate, the first node will rebroadcast after a predetermined duration of time.

Depending on your use case for blockchain, Iroha may be positive or negative. If you’re worried about censorship, Iroha may not be right for you. In this case, you’ll be better off looking at a blockchain that is censorship resistant. If you’re worried about other players on the network committing arbitrage, Iroha may also not be right — further investigation is needed. If you want to know all the players in your blockchain, Iroha may be exactly what you’re looking for.

Developing mobile apps

Tip Skip this section if you aren’t part of the app development space.

Iroha is built for the web and mobile app developers so they can access the strengths of the Hyperledger systems. The Iroha team saw that having a distributed ledger wasn’t useful if there were no applications utilizing it.

Iroha has a development path for the following encapsulated C++ components:

  • Sumeragi consensus library
  • Ed25519 digital signature library
  • SHA-3 hashing library
  • Iroha transaction serialization library
  • P2P broadcast library
  • API server library
  • iOS library
  • Android library
  • JavaScript library
  • Blockchain explorer/data visualization suite

One of the major hurdles of the blockchain industry has been in making systems user-friendly. Iroha has created open-source software libraries for iOS, Android, and JavaScript and made common application programming interface (API) functions convenient to call. It’s still early in development, but Iroha is a good resource to explore for business use cases.

Diving into Sawtooth Lake

Sawtooth Lake by Intel is another distributed ledger project in Hyperledger. It’s focused on being a highly modular platform for building new distributed ledgers for companies.

Warning As of this writing, the release version has software that is only simulating the consensus. It doesn’t provide security for your project and should only be utilized for testing out new ideas.

Sawtooth Lake does not operate with a cryptocurrency. It maintains the security of the platform by allowing businesses to create private blockchains. These businesses running private blockchains then share the burden of computational requirements of the network. In its documentation, Sawtooth Lake states that this type of setup will ensure universal agreement on the state of the shared ledger.

Sawtooth Lake has taken the basic model of blockchains and turned it on its head. Most blockchains have three elements:

  • A shared record of the current state of the blockchain
  • A way of inputting new data
  • A way of agreeing on that data

Sawtooth Lake merges the first two into a signal process it calls a transaction family. This model is best in use cases where all the participating parties have a mutual benefit to having a correct record.

Intel has allowed its software to be flexible enough to accommodate custom transaction families that reflect the unique requirements of each business. It also built three templates for building digital assets:

  • EndPointRegistry: A place to record items in a blockchain
  • IntegerKey: A shared ledger that is used for supply chain management
  • MarketPlace: A blockchain trading platform for buying, selling, and trading digital assets

Exploring the consensus algorithm: Proof of Elapsed Time

The consensus algorithm for Sawtooth Lake is called Proof of Elapsed Time (PoET). It was built to run in a secure area of the main processor of your computer, called a trusted execution environment (TEE). PoET leverages the security of the TEE to prove that time has passed by time-stamping transactions.

Other consensus algorithms have some kind of time-stamping element as well. The way they ensure that the records have not been changed is through publicly publishing their blockchains as proof that they have not been altered. The published ledger acts as a public witness that anyone can roll back and check. It’s sort of like publishing an ad in a newspaper to prove something happened.

PoET also has a lottery system that works a bit differently from other blockchains using proof of work. It randomly selects a node from the pool of validating nodes. The probability of a node being selected increases proportionally to how much processing resources that node contributed to the shared ledger. Measures may be put in place to prevent nodes from gaming the system and corrupting the ledger.

Deploying Sawtooth

Intel has put together some fantastic documentation and tutorials at https://intelledger.github.io/tutorial.html. There, Intel walks you through the process of setting up a virtual development environment for a blockchain, and it even has one for building a blockchain Tic-Tac-Toe game. You need to be familiar with Vagrant and VirtualBox in order to take advantage of what Intel has to offer.

Tip You may also want to review Coding For Dummies, by Nikhil Abraham (Wiley), prior to trying these tutorials.

Building Your System in Fabric

A lot of work has gone into making Fabric accessible. The Hyperledger Composer is an easy-to-use tool that allows you to create blockchain application proof of concepts (POCs). The best part is that it will enable you to define your business network with JavaScript, one of the most popular development languages in the world. This feature alone will significantly cut down on your need for specialized blockchain developers.

The Hyperledger Composer will decrease the development time and cost and allow you to be production ready sooner. Another benefit of the Composer is that it utilizes LoopBacks. LoopBacks communicates digital data streams back to your existing business system, keeping your operations in sync. You still need a good development team to do this, but you can easily mock up your business logic.

Technical stuff A LoopBack is a bit of code that sits in your software and communicates a digital data stream back to a source without intentional processing or modification.

Building asset tracking with Hyperledger Composer

You can try the Hyperledger Composer in your browser without needing to download any special software. The Composer also has a download option that works great if you need to work offline or need to use the Composer’s full application development capabilities.

For this quick tutorial, you need a web browser and an Internet connection. In the following sections, I show you how to deploy your own network, set up a tracking demo, and move assets from one location to another. It’s mostly a point-and-click demo, but you also need to copy and paste a few snippets of code.

You’ll use the Animal Tracking Business Network framework. It was built as a use case for the UK government and farmers. In this demo, a farmer can move animals between fields, and the UK regulator can track the locations of the cows. The assets in this demo happen to be animals, but they could represent any type of object that needs to have its location tracked by a third party, such as a regulator or insurance provider.

Step 1: Setting up a tracking network

The first step is to set up a tracking network. Follow these steps:

  1. Go to the Hyperledger Composer website at https://composer-playground.mybluemix.net/login.
  2. Click Deploy a New Business Network.
  3. Name your network animal-tracking.
  4. Enter a description for the network
  5. Give the network an admin card to be created.
  6. Select your business network project under samples on npm animaltracking-network.
  7. Click Deploy.

Step 2: Setting up a test demo

After you’ve set up a tracking network, you’re ready to set up a test demo. Follow these steps:

  1. Open a second browser tab.
  2. Copy and paste the URL from your first tab into the second tab.
  3. On your first tab, click Define.
  4. On your second tab, click Test.
  5. Open the Define window.
  6. Copy this command:

    {
    "$class": "com.biz.SetupDemo"
    }

  7. Open the Test window.
  8. Click All Transactions.
  9. Click Submit Transaction.
  10. Select SetupDemo from the pull-down menu.
  11. Paste this command:

    {
    "$class": "com.biz.SetupDemo"
    }

  12. Click Submit.

Step 3: Moving your cow

In this section, you digitally track the movement of your asset from one location to another. Often assets move location, and it’s beneficial to allow other people you collaborate with to know where they are at any given time.

  1. Open the Define window.
  2. Copy this command:

    {
    "$class": "com.biz.AnimalMovementDeparture",
    "fromField": "resource:com.biz.Field#FIELD_1",
    "animal": "resource:com.biz.Animal#ANIMAL_1",
    "from": "resource:com.biz.Business#BUSINESS_1",
    "to": "resource:com.biz.Business#BUSINESS_2"
    }

  3. Open the Test window.
  4. Click All Transactions.
  5. Select AnimalMovementDeparture.
  6. Paste this command:

    {
    "$class": "com.biz.AnimalMovementDeparture",
    "fromField": "resource:com.biz.Field#FIELD_1",
    "animal": "resource:com.biz.Animal#ANIMAL_1",
    "from": "resource:com.biz.Business#BUSINESS_1",
    "to": "resource:com.biz.Business#BUSINESS_2"
    }

  7. Click Submit.

Step 4: Receiving your cow

In this section, you complete the transfer of the asset by accepting its new location. This is a double-entry feature that allows for accountability among team members.

  1. Open the Define window.
  2. Copy this command:

    {
    "$class": "com.biz.AnimalMovementArrival",
    "arrivalField": “resource:com.biz.Field#FIELD_2",
    "animal": "resource:com.biz.Animal#ANIMAL_1",
    "from": "resource:com.biz.Business#BUSINESS_1",
    "to": "resource:com.biz.Business#BUSINESS_2"
    }

  3. Open the Test window.
  4. Click All Transactions.
  5. Select AnimalMovementDeparture.
  6. Paste this command:

    {
    "$class": "com.biz.AnimalMovementArrival",
    "arrivalField": "resource:com.biz.Field#FIELD_2",
    "animal": "resource:com.biz.Animal#ANIMAL_1",
    "from": "resource:com.biz.Business#BUSINESS_1",
    "to": "resource:com.biz.Business#BUSINESS_2"
    }

  7. Click Submit.

Congratulations! You’ve now documented the movement of your cow from one location to another on a platform that a third party can use to verify the location and identity of that animal.

Working with Smart Contracts on Hyperledger

A smart contract is computer code that is written inside a blockchain protocol. Smart contracts are created to facilitate, verify, or enforce the prenegotiated terms between two or more parties. The blockchain protocol takes the place of enforcement of contracts. Smart contracts, in effect, allow two or more parties to work together without trust or the need to have authoritative judgment or settlement if things go wrong. At least that’s how they work in theory. Many different platforms enable smart contracts. On Hyperledger, they’re called chaincode.

Chaincode is conveniently written in Go, node.js, and Java and runs in a secured Docker container. Unlike other smart contract platforms that must expose your contract to a public network to enforce them, chaincode is isolated from the endorsing peer process of public blockchains. This allows you to keep your business logic private.

Another feature that distinguishes chaincode from many other platforms is that each chaincode contract is isolated. Other organizations using Hyperledger can’t access your chaincode directly unless permissioned. This feature may reduce attack vectors on your contracts by keeps third parties from accessing them.

A smart auction is a type of smart contract. Its function is to transfer ownership of an item after predetermined parameters of the agreement are met. In this demo, you’re going to create an auction for cars. You’ll list assets for sale, set a reserve price, and test what happens when assets have met or exceeded their price at the end of the auction.

Because you’re going to be using Hyperledger Composer, you don’t need coding experience to complete this demo. You also don’t need to download any special software. A Chrome browser and a good Internet connection will be enough.

Step 1: Setting up an auction network

To set up an auction network, follow these steps:

  1. Go to the Hyperledger Composer website at https://composer-playground.mybluemix.net/login.
  2. Click carauction-network under the Samples on NPM section.
  3. Click Connect Now on the carauction-network.

Step 2: Setting up auction windows

To set up an auction window, follow these steps:

  1. Open a second browser tab.
  2. Copy and paste the URL from your first tab into the second browser tab.
  3. On your first tab, click Define.
  4. On your second tab, click Test.

Step 3: Creating an auctioneer

To create an auctioneer, follow these steps:

  1. Open the Define window.
  2. Copy this command:

    {
    "$class": "org.acme.vehicle.auction.Auctioneer",
    "email": "[email protected]",
    "firstName": "Jenny",
    "lastName": "Jones"
    }

  3. Open the Test window.
  4. Click Create New Participant.
  5. Paste this command:

    {
    "$class": "org.acme.vehicle.auction.Auctioneer",
    "email": "[email protected]",
    "firstName": "Jenny",
    "lastName": "Jones"
    }

  6. Click Create New.

Step 4: Creating two participants

To create two participants, follow these steps:

  1. Open the Define window.
  2. Copy this command:

    {
    "$class": "org.acme.vehicle.auction.Member",
    "balance": 5000,
    "email": "[email protected]",
    "firstName": "Amy",
    "lastName": "Williams"
    }

  3. Open the Test window.
  4. Click Member.
  5. Click Create New Participant.
  6. Paste this command:

    {
    "$class": "org.acme.vehicle.auction.Member",
    "balance": 5000,
    "email": "[email protected]",
    "firstName": "Amy",
    "lastName": "Williams"
    }

  7. Click Create New.
  8. Repeat steps 1 through 6 for the second participant.

Step 5: Creating a new asset

To create a new asset, follow these steps:

  1. Open the Define window.
  2. Copy this command:

    {
    "$class": "org.acme.vehicle.auction.Vehicle",
    "vin": "vin:1234",
    "owner": "resource:org.acme.vehicle.auction.Member#[email protected]"
    }

  3. Open the Test window.
  4. Click Vehicle.
  5. Click Create New Asset.
  6. Paste this command:

    {
    "$class": "org.acme.vehicle.auction.Vehicle",
    "vin": "vin:1234",
    "owner": "resource:org.acme.vehicle.auction.Member#[email protected]"
    }

  7. Click Create New.

Step 6: Creating a new listing

To create a new listing, follow these steps:

  1. Open the Define window.
  2. Copy this command:

    {
    "$class": "org.acme.vehicle.auction.VehicleListing",
    "listingId": "listingId:ABCD",
    "reservePrice": 3500,
    "description": "Arium Nova",
    "state": "FOR_SALE",
    "vehicle": "resource:org.acme.vehicle.auction.Vehicle#vin:1234"
    }

  3. Open the Test window.
  4. Click VehicleListing.
  5. Click Create New Asset.
  6. Paste this command:

    {
    "$class": "org.acme.vehicle.auction.VehicleListing",
    "listingId": "listingId:ABCD",
    "reservePrice": 3500,
    "description": "Arium Nova",
    "state": "FOR_SALE",
    "vehicle": "resource:org.acme.vehicle.auction.Vehicle#vin:1234"
    }

  7. Click Create New.

Congratulations! You’ve now created a smart auction, listed a car for sale, and created the three parties needed to execute the contract. Now that everything is all set to go, you’re going to trigger the smart auction and transfer the car from owner to buyer.

Step 7: Auctioning off the car

To auction off the car, follow these steps:

  1. Open the Define window.
  2. Copy this command:

    {

    "$class": "org.acme.vehicle.auction.Offer",
    "bidPrice": 3500,
    "listing": "resource:org.acme.vehicle.auction.VehicleListing#listingId:ABCD",
    "member": "resource:org.acme.vehicle.auction.Member#[email protected]"
    }

  3. Open the Test window.
  4. Click Submit Transaction.
  5. Select Offer from the pull-down menu.
  6. Paste this command:

    {

    "$class": "org.acme.vehicle.auction.Offer",
    "bidPrice": 3500,
    "listing": "resource:org.acme.vehicle.auction.VehicleListing#listingId:ABCD",
    "member": "resource:org.acme.vehicle.auction.Member#[email protected]"
    }

  7. Click Submit.

Step 8: Closing your auction

To close your auction, follow these steps:

  1. Open the Define window.
  2. Copy this command:

    {
    "$class": "org.acme.vehicle.auction.CloseBidding",
    "listing": "resource:org.acme.vehicle.auction.VehicleListing#listingId:ABCD"
    }

  3. Open the Test window.
  4. Click Submit Transaction.
  5. Select CloseBidding from the pull-down menu.
  6. Paste this command:

    {
    "$class": "org.acme.vehicle.auction.CloseBidding",
    "listing": "resource:org.acme.vehicle.auction.VehicleListing#listingId:ABCD"
    }

  7. Click Submit.

You’ve created a smart auction, listed an asset for sale, created a buyer, and sold the asset. Not bad! To learn more check out the Hyperledger community found at https://hyperledger.github.io/composer/latest/support/support-index.html.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.154.16