Chapter 9
IN THIS CHAPTER
Uncovering Hyperledger Foundation
Discovering key Hyperledger projects
Building an asset tracking platform
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.
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.
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.
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.
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.
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:
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.
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:
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.
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.
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:
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:
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.
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.
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.
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.
The first step is to set up a tracking network. Follow these steps:
https://composer-playground.mybluemix.net/login
.After you’ve set up a tracking network, you’re ready to set up a test demo. Follow these steps:
{
"$class": "com.biz.SetupDemo"
}
{
"$class": "com.biz.SetupDemo"
}
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.
{
"$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"
}
{
"$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"
}
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.
{
"$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"
}
{
"$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"
}
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.
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.
To set up an auction network, follow these steps:
https://composer-playground.mybluemix.net/login
.To set up an auction window, follow these steps:
To create an auctioneer, follow these steps:
{
"$class": "org.acme.vehicle.auction.Auctioneer",
"email": "[email protected]",
"firstName": "Jenny",
"lastName": "Jones"
}
{
"$class": "org.acme.vehicle.auction.Auctioneer",
"email": "[email protected]",
"firstName": "Jenny",
"lastName": "Jones"
}
To create two participants, follow these steps:
{
"$class": "org.acme.vehicle.auction.Member",
"balance": 5000,
"email": "[email protected]",
"firstName": "Amy",
"lastName": "Williams"
}
{
"$class": "org.acme.vehicle.auction.Member",
"balance": 5000,
"email": "[email protected]",
"firstName": "Amy",
"lastName": "Williams"
}
To create a new asset, follow these steps:
{
"$class": "org.acme.vehicle.auction.Vehicle",
"vin": "vin:1234",
"owner": "resource:org.acme.vehicle.auction.Member#[email protected]"
}
{
"$class": "org.acme.vehicle.auction.Vehicle",
"vin": "vin:1234",
"owner": "resource:org.acme.vehicle.auction.Member#[email protected]"
}
To create a new listing, follow these steps:
{
"$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"
}
{
"$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"
}
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.
To auction off the car, follow these steps:
{
"$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]"
}
{
"$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]"
}
To close your auction, follow these steps:
{
"$class": "org.acme.vehicle.auction.CloseBidding",
"listing": "resource:org.acme.vehicle.auction.VehicleListing#listingId:ABCD"
}
{
"$class": "org.acme.vehicle.auction.CloseBidding",
"listing": "resource:org.acme.vehicle.auction.VehicleListing#listingId:ABCD"
}
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
.