This blogpost is one of a series of articles on the “Blockchain mit SAP” (Blockchain with SAP) book published in 2019 (Rheinwerk Verlag, Bonn, ISBN 978-3-8362-6914-8).
This blog post covers the book’s sixth chapter, which describes the configuration of block chain applications with Hyperledger Fabric.
our book, we have developed comparable examples for Hyperledger Fabric and MultiChain in parallel. We’ll start with Hyperledger Fabric.
Hyperledger Fabric is an enterprise blockchain for industrial applications. Hyperledger Fabric is just one of many projects from the Hyperledger Foundation, although it is by far the most successful. It is modular, meaning that many key components of the blockchain can be adapted. Fabric makes it possible to construct private blockchain networks, which require participants to get approved (“permissive blockchain”). Cryptographic keys are exchanged to deliver encrypted communication within the network.
In comparison to other blockchains, Fabric has a greater number of node types:
- and Certificate Authority nodes.
Peer nodes are broadly comparable to the blockchain nodes in a Bitcoin network and save transaction data in blocks. In addition, peer nodes also save Smart Contracts (Chaincode) and execute them on demand.
Orderers are a special form of node, ensuring consensus in the network. Unlike Bitcoin, Hyperledger Fabric has no consensus algorithm such as proof of work. Instead, it has the Orderer node to establish consensus regarding the ordering of transactional data.
Certificate Authority nodes authenticate participants via existing systems like LDAP and Kerberos.
Another special feature of Hyperledger Fabric is its Channels – encrypted communication channels that must be created between participants and which are in effect a separate blockchain. In most cases, a Hyperledger Fabric has a common communication channel for all participants. But this doesn’t always have to be the case – any number of further channels can be created for individual participants, thus forming subgroups.
First Simple Example
We’ll begin here by creating a simple phonebook in Hyperledger Fabric. When building a blockchain application, the sequence is always the same, no matter how complex things get by the end:
- Setting up the blockchain nodes (network infrastructure)
- Development of the chain code
- Design of the data model
- Setting up additional services (such as a Node.JS web server)
The last step is the linking of various services to a complete SAP Cloud application.
Setting Up the Blockchain Nodes
The first network is very simple – just one node. SAP Cloud offers a dev node option that can be used to develop, install and test the chaincode.
Developing the Chaincode
Hyperledger Fabric has a different name for smart contracts – it calls them chaincode. In Hyperledger Fabric, there’s no blockchain without chaincode. It requires a transaction data model that can be written to the blockchain. Unlike Bitcoin, Fabric has no fixed data scheme, so that is something that has to be developed independently. The Go programming language is used for chaincode. Completed chaincode for the blockchain has to be delivered in a zip file with a determined structure that is then uploaded to a blockchain node for installation.
Writing to the Blockchain
Writing to the blockchain is done with key-value pairs. The command is:
This writes the value to the blockchain by designating the key.
Reading from the Blockchain
Values are read from the blockchain via the key name. The key value is read via GetState.
If successful, the last saved value is returned by the blockchain. Otherwise, an error message is sent (if the key is not available, for instance).
Another core feature of blockchain is the history feature, which lists value changes for a given key. If a user enters
for a valid key name, a chronological list of all value changes for the specified key is returned. This brief overview of the commands is enough for all the features needed for saving data to a blockchain.
The Finished Application
The finished application is based on an SAPUI5 frontend that directly interacts with the blockchain via REST API calls. The buttons can be used to access the entry creation and update features.
One small highlight from our application: it offers a chronological history of value changes from the blockchain. Shown here is an example of data history for a selected entry. The time stamps in the left column make it possible to chronologically reconstruct the changes.
More articles of this series can be found here:
- Blockchain with SAP: What is Blockchain and How Does It Work?
- Blockchain with SAP: Blockchain-as-a-Service Products from the SAP Cloud Platform
- Blockchain with SAP: Cloud Computing from SAP: The SAP Cloud Platform
- Blockchain with SAP: Business application scenarios for blockchains
- Blockchain with SAP: The First Steps to Having Your Own Blockchain
- Blockchain with SAP: Developing Blockchain Applications with Hyperledger Fabric
- Blockchain with SAP: SAP HANA Integration
- Blockchain with SAP: MultiChain Applications
- Blockchain with SAP: MultiChain Applications
- Blockchain with SAP: Hybrid Network Architecture and Camelot Hypertrust Platform
- Blockchain with SAP: Summary and outlook
Do you want to learn more about the possibilities Hyperledger Fabric offers for your business? In our book “Blockchain mit SAP”, we detail the advantages of the Hyperledger Fabric blockchain and how to set it up in the SAP Cloud Platform. A detailed extract from the bookis available on the publisher’s website.