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

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:

  • Peer
  • Orderer
  • 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
    • Programming
    • Testing
    • Installation
  • 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:

PutState(key, value)

 

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.

GetState(key, value)

 

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).

History

Another core feature of blockchain is the history feature, which lists value changes for a given key. If a user enters

GetHistoryForKey(key)

 

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.

(c) Rheinwerk Verlag

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.

(c) Rheinwerk Verlag

More articles of this series can be found here:

Wollen Sie mehr zur SAP Cloud Platform und der Funktionsweise der Blockchains erfahren? In unserem Buch „Blockchain mit SAP“ erläutern wir Ihnen ausführlich die Funktionsweise und demonstrieren Ihnen anhand zahlreicher Beispiele die Vorzüge dieser innovativen Technologie. Eine ausführliche Leseprobe zum Buch stellt der Verlag online bereit.

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.

 

SAP S/4 Transformation: Survey on Expectations

The study "Expectations on S/4HANA in 2022" by techconsult and CamelotITLab shows possible painpoints in any migration and how they can be avoided. With data from 200 companies in Germany.

Download the complete study here

Recommended articles

Data & Analytics

How to Approach Data Protection in the Smartest Possible Way

Uncoordinated initiatives and activities have often been a quick reaction to the demanding legal landscape regarding data protection. Having built the …

read more
Data & Analytics

An 8-Step Guide to Enable a Culture of Data Quality

Data quality issues are increasingly seen as a problem that affects the entire business, not just the IT department. Learn how …

read more
Supply Chain Management

Demand-Driven SCM: A Boost for the Digital Supply Chain

Digital supply chain initiatives often don’t deliver the expected outcomes. The reason: outdated processes. A recent study reveals how Demand-Driven …

read more

Reimagine your Value Chain with us

Contact us