Blockchain Made Simple: No-Code Apps with Hyperledger Fabric and Joget
EDITOR’S NOTE March 2020: This post was originally published in January 2019 for Hyperledger Fabric 1.3, and has been updated for Hyperledger Fabric 2.0.
1. Introduction
Joget is an open source low-code/no-code application platform for faster, simpler digital transformation. In this article, we will look at using a no-code approach to integrating blockchain technology, specifically a Hyperledger Fabric network, into a full-fledged web application.1.1 Blockchain and Digital Ledger Technology (DLT)
In recent times there have been many predictions on blockchain technology revolutionizing the world, transforming everything from banking to supply chains and even government. Even if you are not familiar with the term, you would probably have heard of the rise of cryptocurrency like Bitcoin which utilizes blockchain technology. So what exactly is a blockchain?To start, it’s best to understand a broader term called digital ledger technology (DLT). DLT is simply a decentralized database, where data is stored by a network of computers with no central authority. Blockchain is a specific type of DLT, where records in the network are linked using cryptography and cannot be changed. This lends itself to solving problems where there are issues with trust and inefficiencies due to centralized authorities.
There are many blockchain implementations, which are broadly categorized as either permissionless or permissioned. Permissionless blockchain networks are essentially public so anyone can participate, while permissioned ones are for restricted private use. Permissionless networks work well for public areas such as cryptocurrencies, but in an enterprise environment and in many industries, private networks are essential.
Enterprise blockchain networks might typically span across multiple organizations across an entire industry. With the need for permissioned private networks and participation by multiple organizations, how would a blockchain solution gain enough adoption to succeed? This is where Hyperledger comes in.
1.2 Hyperledger and Hyperledger Fabric
Hyperledger is not a company, nor a specific product, but rather an umbrella of open source blockchain projects for enterprise use cases. Hosted by the Linux Foundation with more than 250 participating organizations, the projects are divided into frameworks and tools. Frameworks are different implementations of blockchain technology, each of which has different strengths for different use cases. Tools, on the other hand, are utilities to help manage or complement the frameworks.
The most popular and mature framework currently is Hyperledger Fabric. Originally contributed by IBM, Fabric is emerging as the de-facto standard for enterprise blockchain platforms, with commercial implementations and support from major vendors including IBM, Oracle and SAP.
1.3 Hyperledger Fabric Concepts
If you are new to blockchain technology, there are quite a lot of concepts to learn and understand. For the purpose of this sample app, here are some of the more important terms that are used to configure the blockchain integration.- Blockchain ledger is a journal of all transactions and data that are stored in a distributed network.
- Peer nodes are the network components where copies of the blockchain ledger are hosted.
- Members are organizations that are part of the blockchain network
- Certificate Authority (CA) issues certificates to identify users that belong to an organization.
- Membership Services Provider (MSP) maps certificates to member organizations.
- Transactions are requests to read or write data into the ledger
- Ordering service are nodes that orders transactions into a block to be written into the ledger
- Channels are private communication mechanisms to keep confidentiality between members in the network.
- Smart contracts (called chaincode in Fabric) are code within the blockchain network that are invoked to query or update the ledger
The diagram provided by the Hyperledger Fabric project below shows how an application integrates with a blockchain network via smart contracts:
More details are available in the Hyperledger Fabric documentation.
2. Overview of the App
To demonstrate the incorporation of blockchain technology in an app, let’s design a Joget app that makes use of the sample Fabcar network provided by Hyperledger Fabric. The Fabcar sample is basically a minimal stripped-down Fabric network for learning purposes.To demonstrate reading from and writing to the blockchain network, the app supports the following use cases:
- Query and list of all records from the blockchain network
- Query and view a specific record from the blockchain network
- Write a new record into the blockchain network after an approval process
To install and try out the final working app:
- Ensure that a Hyperledger Fabric sample Fabcar network is up and running.
- Ensure that an instance of Joget Enterprise Edition is up and running.
- Download the Hyperledger Fabric Plugins JAR file, and upload the downloaded jar file through Manage Plugins under System Settings.
- Download the Joget jwa app and import it.
- Configure the fabric_ environment variables for your Fabcar network.
- Publish the app and access it from the App Center.
Welcome: Home page
Fabcar Listing: List of all records from the blockchain network
Fabcar Form: View specific record from the blockchain network
Approval Process: Approve a creation of a new record
The next few sections provide more detailed information to setup the sample Hyperledger Fabric network, as well as to develop and configure the app.
3. Install and Setup a Hyperledger Fabric Network
To begin, install Hyperledger Fabric v2.0 and the Fabcar Network Sample.The summarized installation steps below were tested on Ubuntu 18.04.
Install cURL:
sudo apt install -y curl
Install Docker and Docker Compose (logout and login after the usermod command):
sudo apt install -y docker.io
sudo apt install -y docker-compose
sudo usermod -aG docker $USER
# logout and login after the usermod command
Install Go and JQ:
Install NodeJS and NPM:
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
curl -sSL https://bit.ly/2ysbOFE | bash -s
Upon successful installation and execution of the last command, you should receive the query response from the blockchain network i.e.
Transaction has been evaluated, result is: [{"Key":"CAR0","Record":{"color":"blue","docType":"car","make":"Toyota","model":"Prius","owner":"Tomoko"}},{"Key":"CAR1","Record":{"color":"red","docType":"car","make":"Ford","model":"Mustang","owner":"Brad"}},{"Key":"CAR2","Record":{"color":"green","docType":"car","make":"Hyundai","model":"Tucson","owner":"Jin Soo"}},{"Key":"CAR3","Record":{"color":"yellow","docType":"car","make":"Volkswagen","model":"Passat","owner":"Max"}},{"Key":"CAR4","Record":{"color":"black","docType":"car","make":"Tesla","model":"S","owner":"Adriana"}},{"Key":"CAR5","Record":{"color":"purple","docType":"car","make":"Peugeot","model":"205","owner":"Michel"}},{"Key":"CAR6","Record":{"color":"white","docType":"car","make":"Chery","model":"S22L","owner":"Aarav"}},{"Key":"CAR7","Record":{"color":"violet","docType":"car","make":"Fiat","model":"Punto","owner":"Pari"}},{"Key":"CAR8","Record":{"color":"indigo","docType":"car","make":"Tata","model":"Nano","owner":"Valeria"}},{"Key":"CAR9","Record":{"color":"brown","docType":"car","make":"Holden","model":"Barina","owner":"Shotaro"}}]
Copy the connection profile JSON from the test-network directory.
Modify the connection profile to match your environment:
An example connection-fabcar.json can be downloaded from the knowledge base page. Please note that this JSON is for reference only and you cannot use this JSON directly since the certificates will not match your servers.
sudo apt install -y docker.io
sudo apt install -y docker-compose
sudo usermod -aG docker $USER
# logout and login after the usermod command
Install Go and JQ:
sudo add-apt-repository ppa:longsleep/golang-backports
sudo apt update
sudo apt install golang-go
sudo apt install jq
Install NodeJS and NPM:
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo apt-get install -y build-essential
3.2 Install Hyperledger Fabric Samples, Binaries and Docker Images
(https://hyperledger-fabric.readthedocs.io/en/release-2.0/install.html)curl -sSL https://bit.ly/2ysbOFE | bash -s
3.3 Setup Sample Fabcar Network
(https://hyperledger-fabric.readthedocs.io/en/release-2.0/write_first_app.html)
cd fabric-samples/fabcar
./startFabric.sh javascript
cd javascript
npm install
node enrollAdmin.js
node registerUser.js
node query.js
Upon successful installation and execution of the last command, you should receive the query response from the blockchain network i.e.
Transaction has been evaluated, result is: [{"Key":"CAR0","Record":{"color":"blue","docType":"car","make":"Toyota","model":"Prius","owner":"Tomoko"}},{"Key":"CAR1","Record":{"color":"red","docType":"car","make":"Ford","model":"Mustang","owner":"Brad"}},{"Key":"CAR2","Record":{"color":"green","docType":"car","make":"Hyundai","model":"Tucson","owner":"Jin Soo"}},{"Key":"CAR3","Record":{"color":"yellow","docType":"car","make":"Volkswagen","model":"Passat","owner":"Max"}},{"Key":"CAR4","Record":{"color":"black","docType":"car","make":"Tesla","model":"S","owner":"Adriana"}},{"Key":"CAR5","Record":{"color":"purple","docType":"car","make":"Peugeot","model":"205","owner":"Michel"}},{"Key":"CAR6","Record":{"color":"white","docType":"car","make":"Chery","model":"S22L","owner":"Aarav"}},{"Key":"CAR7","Record":{"color":"violet","docType":"car","make":"Fiat","model":"Punto","owner":"Pari"}},{"Key":"CAR8","Record":{"color":"indigo","docType":"car","make":"Tata","model":"Nano","owner":"Valeria"}},{"Key":"CAR9","Record":{"color":"brown","docType":"car","make":"Holden","model":"Barina","owner":"Shotaro"}}]
3.4 Obtain the Connection Profile
A connection profile describes a set of components, including peers, orderers and certificate authorities in a Hyperledger Fabric blockchain network.Copy the connection profile JSON from the test-network directory.
fabric-samples/test-network/organizations/peerOrganizations/org1.example.com/connection-org1.json
Modify the connection profile to match your environment:
- Change the name in the connection profile to match the channel e.g. from "test-network-org1" to "mychannel"
- By default, the sample connection profile is configured to be accessible via localhost only. If your sample Hyperledger Fabric blockchain network is not running on localhost, you will need to change the "localhost" URLs in the connection profile to the correct server URLs. If required, add the host names for the nodes into your OS hosts file. For example, assuming your nodes are running on 192.168.56.101, add the following into your /etc/hosts file:
192.168.56.101 peer0.org1.example.com peer1.org1.example.com peer2.org1.example.com peer3.org1.example.co peer0.org2.example.com peer1.org2.example.com ca.org1.example.com orderer.example.com orderer2.example.com orderer3.example.com orderer4.example.com orderer5.example.com org1.example.com org2.example.com example.com - Optional: If your Hyperledger Fabric blockchain network uses an Orderer, add the Orderer configuration and certificate into the connection.json. The Orderer certificate can be copied from
fabric-samples/test-network/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
"orderers": {
"orderer.example.com": {
"url": "grpcs://orderer.example.com:7050",
"tlsCACerts": {
"pem": "-----BEGIN CERTIFICATE-----\nMIICRTCCAeqgAwIBAgI...\n-----END CERTIFICATE-----"
},
"grpcOptions": {
"ssl-target-name-override": "orderer.example.com",
"hostnameOverride": "orderer.example.com"
}
}
}
4. Design Joget App
Now that you have gotten the Fabcar network up and running, let’s start designing the Joget app that will query and update the records in the blockchain ledger. The Joget platform provides a modular dynamic plugin architecture to extend functionality. In this case, we will be using a set of Hyperledger Fabric plugins with Joget Enterprise Edition.4.1 Design New App
The first step is to design a new Joget app. In the Joget App Center, login as an administrator and click on the Design New App button. Key in the relevant details e.g.- App ID: fabcar
- App Name: Hyperledger Fabric Fabcar Sample
4.2 Design Fabcar Form
Using the Joget Form Builder, design a form with fields matching the properties in a Fabcar record.In this case create text fields with IDs that match a Fabcar record
- Key
- make
- model
- color
- owner
4.3 Use App Generator to Create App
Once the form has been saved, click on the Generate App button to use the App Generator. Check the options for Generate Datalist, Generate CRUD and Generate Process - Approval Process, then Generate.NOTE: The App Generator is a Joget Enterprise Edition feature, but you can manually create the list, process and UI in the Community Edition as well.
5. Configure Joget Hyperledger Fabric Plugins
At this point, a full app to manage records, along with an approval process to create a new record has been created. These records are in the internal Joget database though, so now we will start configuring Hyperledger Fabric Plugins to directly integrate with the blockchain network.5.1 Upload Joget Hyperledger Fabric Plugins
Download the Hyperledger Fabric Plugins JAR file, and upload the downloaded jar file through Manage Plugins under System Settings.5.2 Configure List to Query Hyperledger Fabric Ledger
In the app, enable the Quick Edit Mode so that you can view the editable elements. Browse to the Fabcar Listing and click on the quick edit link for the List to open the Datalist Builder.Switch to the Source tab, select the Hyperledger Fabric Datalist Binder then click on Next. In the plugin configuration, key in the relevant details.
The values shown here are suitable for the default Fabcar sample network, but change the fabric_host to the correct hostname or IP in your environment:
Hyperledger Fabric Configuration
Transaction
Property
|
Value
|
Chaincode ID
|
fabcar
|
Function Name
|
queryAllCars
|
JSON Response Primary Key Property
|
Key
|
JSON Response Contains Nested Property
|
true
|
Base Nested Property Name
|
Record
|
If the configuration is correct, the Design tab will display the appropriate Fabcar columns to be used in the datalist. Add the columns to be displayed as required, then Save.
5.3 Configure Form to View Hyperledger Fabric Ledger Record
In the Fabcar Listing and click on View on a record. Click on the Fabcar Form quick edit link to open the Form Builder.Switch to the Properties tab, select the Hyperledger Fabric Form Binder as the Load Binder then click on Next.
In the plugin configuration, key in the relevant details. The Hyperledger Fabric User and Channel values are similar to the configuration used for the datalist binder earlier.
Transaction
Property
|
Value
|
Chaincode ID
|
fabcar
|
Function Name
|
queryCar
|
Function Arguments
|
#requestParam.id#
|
JSON Response Contains Nested Property
|
true
|
Base Nested Property Name
|
Record
|
Note: #requestParam.id# is a request parameter hash variable to represent the id parameter in the URL.
Click on Save.
5.4 Configure Process to Update Hyperledger Fabric Ledger
In the Design App > Processes screen, click on Design Process to launch the Process Builder.In the transition where the status is “Approved”, add a Tool called Invoke Fabric Transaction.
In the Map Tools to Plugins page, select the Hyperledger Fabric Tool for that Tool. In the plugin configuration, key in the relevant details. The Hyperledger Fabric User and Channel values are similar to the configuration used for the datalist binder earlier.
Transaction
Property
|
Value
|
Chaincode ID
|
fabcar
|
Function Name
|
updateCar
|
Function Arguments
|
#form.fabcar.Key#
#form.fabcar.make#
#form.fabcar.model#
#form.fabcar.colour#
#form.fabcar.owner#
|
Transaction Type
|
Update
|
Note: #form.fabcar.field# is a form hash variable that represents the form field value.
6. What’s Next
This example serves to demonstrate the simplicity of building a blockchain app using the Joget platform without coding.Download the app and plugin for this sample, and get started with Hyperledger Fabric and Joget.
To get started on the digital transformation journey with Joget:
- Get started with Joget
- Learn more in the Knowledge Base
- Join the community in the Community Q&A
- Enquire about the Joget Enterprise Edition
Comments
Post a Comment