Part 3 :- Building User Interface on SAP Business Technology Platform to consume Blockchain
Welcome to the next part of the “Integrating SAP Business Technology Platform with Blockchain Service” blog post series, I am happy to publish the 3rd part where deployed chain code will be integrated with the UI Application which is deployed on SAP BTP.
For a quick recap kindly go through previous blogs as below :
Integrating SAP Business Technology Platform with Blockchain Service
Part 1 :-Deploying a Hyperledger Fabric template on Azure Kubernetes Service (AKS)
Part 2:-Building a Hyperledger Fabric consortium based on Azure Kubernetes Service (AKS) template
So in this blog post, we will perform 2 tasks :
Part A: Enable REST service for AKS HLF
Part B: Integrate UI application with REST API endpoints
Part A :
Enabling REST Service for AKS HLF
We will enable the REST service for the chain code deployed on AKS HLF. It uses fabric node SDKs to establish connectivity as well as to submit chain code transactions by integrating with any third-party application.
We perform below configuration steps
An AKS HLF network
- Deploy an AKS HLF network end-to-end including a HLF orderer member and a HLF peer member.
- Connect the 2 deployments by adding the peer organization to the consortium.
- Create a new application channel and add the peer organization to it. Ask the peer nodes to join
- the channel.
- Deploy the chain code on the channel for testing with the.
We have already configured the above pre-requisites in previous blog posts.
Deploy REST service
Setting up Azure Linux VM
- Create an Azure Linux VM – enabled with SSH on port 22 for creating and deploying the app files. Please follow the guide given here to create and configure the VM correctly as well as create a new SSH session using the VS Code.
- Hyperledger Fabric Node SDK supports Node.js version 10 from 10.15.3 and higher and Node.js version 12 from 12.13.1 and higher. Currently, we will make use of Node.js version 12.18.3 (latest LTS release). You can install this version by following the steps in the VS Code SSH session by opening the command line using Ctrl+J
- Download NVM (the Node.js version manager) using commands as given here.
- Delete and create a new shell in VS Code SSH session to detect the NVM installation.
- Download the specific Node.js version using the command: nvm install 12.18.3.
- If you are already having multiple Node.js versions in the VM, run the command: nvm use 12.18.3 to switch to Node.js version – 12.18.3.
- NPM tool needs to be version 6 or higher. Check by using the command: npm –version.
- We also need the build-essential Linux dependency to configure the VM with binaries like make,GCC, and g++.
Perform: sudo apt-get update -qq && sudo apt-get install -y build-essential.
Setting up the sample REST service for the AKS HLF project
- Get the sample code using the following GitHub links:
Place the files package.json and restapiservice.js in a new project folder, let’s say hlfRestService, inside the Azure VM.
Code performs :
- Check if the User already enrolled or not.
- If not User is enrolled with Admin credentials that we have generated in earlier steps.
- Connect to the gateway with Connection profile details
- Establish connectivity with the corresponding channel on deployed chain code
- Execute the transaction.
- The connection and admin profile of your peer organization in JSON formats using azhlfTool client application.
- Connection Profile JSON file can be obtained using the following command:
- ./azhlf connectionProfile import fromAzure -g $PEER_ORG_RESOURCE_GROUP -s
- $PEER_ORG_SUBSCRIPTION -o $PEER_ORG_NAME
- Admin credentials can be imported as a JSON file using the following command:
- ./azhlf adminProfile import fromAzure -g $PEER_ORG_RESOURCE_GROUP -s
- $PEER_ORG_SUBSCRIPTION -o $PEER_ORG_NAME –importToJSON
Each of the above commands on a successful run will point you to the path of the imported JSON files. You must add the contents of these files by creating new files inside the project directory of the VM using the VS Code SSH session. NOTE: Please do not change the file names while writing or uploading them to the VM.
Running the REST API service
Please follow these commands inside your project directory to run the sample REST service for HLF:
$ npm install$ PEERORG_NAME=<peerOrgName> CHANNEL_NAME=<channelName> CC_NAME=<chaincodeName> noderestapiservice.js
Calling the REST API service
Within the VM
You can call the REST API service from within the Azure Linux VM – where it is running, by opening a new shell instance of the VM in VS Code SSH session and run the following commands:
$ curl http://localhost:7004/api/query/financier/requests/:financier
Outside the VM
- You can call the REST API service from outside the Azure Linux VM – where it is running, by first enabling the network security inbound port rule as described in the prerequisites section.
- You would need to note down the VM’s public IP address as visible in the Overview pane of the Azure VM deployment.
- You can then run these commands from any local command shell having the curl command installed.
Once our REST API is running successfully, we will integrate our UI application with API endpoints.
Part B :
Integrate UI application with REST API Endpoints
UI Application :
The UI application is based on Angular JS V9. It uses dependency injection.
You can also use Business Application Studio as IDE to develop, debug and deploy applications on SAP BTP.
In this case, the Application is deployed to SAP BTP using CF CLI.
CF CLI commands to push the app to SAP BTP can found below :
Let me explain the scenario of Invoice Discounting which we have taken to showcase how blockchain can help.
Invoice financing is a way for businesses to borrow money against the amounts due from customers.
Borrowing is a keyword here as its one form of credit. See more about the definition and process here
By borrowing money against customer invoices businesses can
- Improve cash flow
- Increase working capital will accelerate business growth
- Reduce wait time for payments
The business, not the lender, collects payments from customers, so customers are not aware of the arrangement. With invoice discounting, the lender will advance the business up to 95% of the invoice amount. When clients pay their invoices, the business repays the lender, minus a fee or interest.
- The business retains control over the administration of the sales ledger
- Usually involves a monthly reconciliation with their invoice financier
- Lower management fees
- Customers don’t know there is invoice finance involved in general its a better Option than factoring when it comes to maintaining customer relationships
Proposed Network Participants
- Financier: Purchase the invoice receivable
- Business: Sells the invoice receivable
- Customer: Required to pay for the invoice
In this UI application, we have limited our scope to Financier and Supplier.
Typical activities performed by participants are as follow :
- Vendor provide the goods/services to a customer and invoice them
- The vendor send the invoice details to the invoice finance provider
- Funds are made available of a certain percentage of the invoice
- Either the vendor own a credit controller or the invoice finance provider’s sales ledger service carries out the invoice collection procedure
- When your customer pays, the balance of the invoice is made available to the vendor – less a service fee
Kindly check the below video which shows how the above-mentioned transactions take place.
In summary, in this blog post, we’ve configured a REST API that enables UI applications to integrate with AKS on HLF.
In the next blog post we will see how we can add security to the developed application layer, so watch out for upcoming blog posts. See you soon!
Reference Links :
SAP Business Application Studio
Hyperledger Fabric SDK for Node.js