Sample insurance application using Hyperledger Fabric
This repository will not be updated. I will check periodically for pull requests, but do not expect a quick response.
Read this in other languages: 中国語,日本語.
This project showcases the use of blockchain in insurance domain for claim processing. In this application, we have four participants, namely insurance, police, repair shop and the shop. Furthermore, each participant will own its own peer node. The insurance peer is the insurance company providing the insurance for the products and it is responsible for processing the claims. Police peer is responsible for verifying the theft claims. Repair shop peer is responsible for repairs of the product while shop peer sells the products to consumer. The value of running this network on the IBM Blockchain Platform is that you can easily customize the network infrastructure as needed, whether that is the location of the nodes, the CPU and RAM of the hardware, the endorsement policy needed to reach consensus, or adding new organizations and members to the network.
Note: This code pattern can either be run locally, or connected to the IBM Blockchain Platform. If you only care about running this pattern locally, please find the local instructions here.
Audience level : Intermediate Developers
When the reader has completed this code pattern, they will understand how to:
We find that Blockchain can be finicky when it comes to installing Node. We want to share this StackOverflow response - because many times the errors you see with Compose are derived in having installed either the wrong Node version or took an approach that is not supported by Compose:
To run a local network, you can find steps here
Important Note: This pattern is more advanced because it uses four organizations. For this reason, you will likely have to get a paid kubernetes cluster to run this pattern on the cloud, since a free cluster will not have the CPU/storage necessary to deploy all of the pods that we need to run this pattern. There are other patterns that leverage a free Kubernetes cluster (and only two organizations), so if you want to try that one out first, go here.
Create the IBM Cloud Kubernetes Service. You can
find the service in the Catalog
. Note that for this code pattern, we need to use the 32CPU, 32GB RAM cluster.
Once you reach the create a new cluster page you will need to do the following:
We will build a network as provided by the IBM Blockchain Platform documentation. This will include creating a channel with a single peer organization with its own MSP and CA (Certificate Authority), and an orderer organization with its own MSP and CA. We will create the respective identities to deploy peers and operate nodes.
Insurance CA
.admin
and Admin Secret of adminpw
.
Shop CA
.admin
and Admin Secret of adminpw
.Repair Shop CA
.admin
and Admin Secret of adminpw
.Police CA
.admin
and Admin Secret of adminpw
.insuranceAdmin
, and Enroll Secret of insuranceAdminpw
. Click Next. Set the Type for this identity as client
and select org1
from the affiliated organizations drop-down list. We will leave the Maximum enrollments and Add Attributes fields blank.insurancePeer
, and Enroll Secret of insurancePeerpw
. Click Next. Set the Type for this identity as peer
and select org1
from the affiliated organizations drop-down list. We will leave the Maximum enrollments and Add Attributes fields blank.
shopAdmin
, and Enroll Secret of shopAdminpw
. Click Next. Set the Type for this identity as client
and select org1
from the affiliated organizations drop-down list. We will leave the Maximum enrollments and Add Attributes fields blank.shopPeer
, and Enroll Secret of shopPeerpw
. Click Next. Set the Type for this identity as peer
and select org1
from the affiliated organizations drop-down list. We will leave the Maximum enrollments and Add Attributes fields blank.repairShopAdmin
, and Enroll Secret of repairShopAdminpw
. Click Next. Set the Type for this identity as client
and select org1
from the affiliated organizations drop-down list. We will leave the Maximum enrollments and Add Attributes fields blank.repairShopPeer
, and Enroll Secret of repairShopPeerpw
. Click Next. Set the Type for this identity as peer
and select org1
from the affiliated organizations drop-down list. We will leave the Maximum enrollments and Add Attributes fields blank.policeAdmin
, and Enroll Secret of policeAdminpw
. Click Next. Set the Type for this identity as client
and select org1
from the affiliated organizations drop-down list. We will leave the Maximum enrollments and Add Attributes fields blank.policePeer
, and Enroll Secret of policePeerpw
. Click Next. Set the Type for this identity as peer
and select org1
from the affiliated organizations drop-down list. We will leave the Maximum enrollments and Add Attributes fields blank.Insurance MSP
and an MSP ID of insurancemsp
.Insurance CA
as the root CA for the organization.insuranceAdmin
and insuranceAdminpw
. Then, give the Identity name, Insurance Admin
.
Shop MSP
and an MSP ID of shopmsp
.Shop CA
as the root CA for the organization.shopAdmin
and shopAdminpw
. Then, give the Identity name, Shop Admin
.Repair Shop MSP
and an MSP ID of repairshopmsp
.Repair Shop CA
as the root CA for the organization.repairShopAdmin
and repairShopAdminpw
. Then, give the Identity name, Repair Shop Admin
.Police MSP
and an MSP ID of policemsp
.Police CA
as the root CA for the organization.policeAdmin
and policeAdminpw
. Then, give the Identity name, Police Admin
.Insurance Peer
.Insurance CA
as your Certificate Authority. Then, give the Enroll ID and Enroll secret for the peer identity that you created for your peer, insurancePeer
, and insurancePeerpw
. Then, select the Administrator Certificate (from MSP), Insurance MSP
, from the drop-down list and click Next.admin
, and TLS Enroll secret, adminpw
, the same values are the Enroll ID and Enroll secret that you gave when creating the CA. Leave the TLS CSR hostname blank.Insurance Admin
.
Create a shop peer (same process as shown in gif above)
Shop Peer
.Shop CA
as your Certificate Authority. Then, give the Enroll ID and Enroll secret for the peer identity that you created for your peer, shopPeer
, and shopPeerpw
. Then, select the Administrator Certificate (from MSP), Shop MSP
, from the drop-down list and click Next.admin
, and TLS Enroll secret, adminpw
, the same values are the Enroll ID and Enroll secret that you gave when creating the CA. Leave the TLS CSR hostname blank.Shop Admin
.Create a repair shop peer (same process as shown in gif above)
Repair Shop Peer
.Repair Shop CA
as your Certificate Authority. Then, give the Enroll ID and Enroll secret for the peer identity that you created for your peer, repairShopPeer
, and repairShopPeerpw
. Then, select the Administrator Certificate (from MSP), Repair Shop MSP
, from the drop-down list and click Next.admin
, and TLS Enroll secret, adminpw
, the same values are the Enroll ID and Enroll secret that you gave when creating the CA. Leave the TLS CSR hostname blank.Repair Shop Admin
.Create a police peer (same process as shown in gif above)
Police Peer
.Police CA
as your Certificate Authority. Then, give the Enroll ID and Enroll secret for the peer identity that you created for your peer, policePeer
, and policePeerpw
. Then, select the Administrator Certificate (from MSP), Police MSP
, from the drop-down list and click Next.admin
, and TLS Enroll secret, adminpw
, the same values are the Enroll ID and Enroll secret that you gave when creating the CA. Leave the TLS CSR hostname blank.Police Admin
.Orderer CA
.admin
and Admin Secret of adminpw
.
ordereradmin
, and Enroll Secret of ordereradminpw
. Click Next. Set the Type for this identity as client
and select org1
from the affiliated organizations drop-down list. We will leave the Maximum enrollments and Add Attributes fields blank.orderer1
, and Enroll Secret of orderer1pw
. Click Next. Set the Type for this identity as peer
and select org1
from the affiliated organizations drop-down list. We will leave the Maximum enrollments and Add Attributes fields blank.Orderer MSP
and an MSP ID of orderermsp
.Orderer CA
as the root CA for the organization.ordereradmin
and ordereradminpw
. Then, give the Identity name, Orderer Admin
.
Orderer
.Orderer CA
as your Certificate Authority. Then, give the Enroll ID and Enroll secret for the peer identity that you created for your orderer, orderer1
, and orderer1pw
. Then, select the Administrator Certificate (from MSP), Orderer MSP
, from the drop-down list and click Next.admin
, and TLS Enroll secret, adminpw
, the same values are the Enroll ID and Enroll secret that you gave when creating the CA. Leave the TLS CSR hostname blank.Orderer Admin
.
Insurance MSP
.Shop MSP
, Repair Shop MSP
, and Police MSP
as well.
mychannel
.Orderer
from the orderers drop-down list.Insurance MSP (insurancemsp)
.Insurance Admin
.
Orderer
and click Next.mychannel
and click Next.Insurance Peer
, Shop Peer
, Repair Shop Peer
, and Police Peer
.
mychannel
.channel details
. Scroll all the way down until you see Anchor peers
.Add anchor peer
and add the Insurance, Police, Repair Shop,
and Shop peers.Insurance Peer
, Shop Peer
, Repair Shop Peer
, and Police Peer
.
git clone https://github.com/IBM/build-blockchain-insurance-app
build-blockchain-insurance-app/chaincodePackage
directory.
mychannel
to instantiate the smart contract on. Click Next.insurancemsp
, shopmsp
, repairshopmsp
, policemsp
. Click Next.Init
and leave Arguments blank.
Connect with SDK
from the overflow menu on the right side of the row.insurancemsp
.Insurance CA
.
insuranceApp-admin
and insuranceApp-adminpw
.client
as Type.hf.Registrar.Roles
= *
. This will allow this identity to act as registrar and issues identities for our app. Click Add-attribute.
shopApp-admin
and shopApp-adminpw
.client
as Type.hf.Registrar.Roles
= *
. This will allow this identity to act as registrar and issues identities for our app. Click Add-attribute.repairShopApp-admin
and repairShopApp-adminpw
.client
as Type.hf.Registrar.Roles
= *
. This will allow this identity to act as registrar and issues identities for our app. Click Add-attribute.policeApp-admin
and policeApp-adminpw
.client
as Type.hf.Registrar.Roles
= *
. This will allow this identity to act as registrar and issues identities for our app. Click Add-attribute.web/www/blockchain
directory.
First, navigate to the web/www/blockchain
directory.
cd web/www/blockchain/
Open the config.json
file, and update the caName with the URL
of the insurance certificate authority from your ibpConnection.json
file. Save the file.
Run the enrollAdmin.js
script
node enrollAdmin.js
You should see the following in the terminal:
msg: Successfully enrolled admin user insuranceApp-admin and imported it into the wallet
First, change the appAdmin, appAdminSecret, and caName properties in your config.json
file,
so that it looks something like this (your caName should be different than mine):
{
"connection_file": "ibpConnection.json",
"appAdmin": "shopApp-admin",
"appAdminSecret": "shopApp-adminpw",
"orgMSPID": "shopmsp",
"caName": "https://fa707c454921423c80ec3c3c38d7545c-caf2e287.horeainsurancetest.us-south.containers.appdomain.cloud:7054",
"userName": "shopUser",
"gatewayDiscovery": { "enabled": true, "asLocalhost": false }
}
To find the other CA urls, you will need to click on the Nodes
tab in IBM Blockchain Platform, then on
the Shop CA, and on the settings cog icon at the top of the page. That will take you to the certificate
authority settings, as shown in the picture below, and you can copy that endpoint URL into your config.json
caName
field.
Run the enrollAdmin.js
script
node enrollAdmin.js
You should see the following in the terminal:
msg: Successfully enrolled admin user shopApp-admin and imported it into the wallet
First, change the appAdmin, appAdminSecret, and caName properties in your config.json
file,
so that it looks something like this (your caName should be different than mine):
{
"connection_file": "ibpConnection.json",
"appAdmin": "repairShopApp-admin",
"appAdminSecret": "repairShopApp-adminpw",
"orgMSPID": "repairshopmsp",
"caName": "https://fa707c454921423c80ec3c3c38d7545c-caf2e287.horeainsurancetest.us-south.containers.appdomain.cloud:7054",
"userName": "repairUser",
"gatewayDiscovery": { "enabled": true, "asLocalhost": false }
}
Run the enrollAdmin.js
script
node enrollAdmin.js
You should see the following in the terminal:
msg: Successfully enrolled admin user repairShopApp-admin and imported it into the wallet
First, change the appAdmin, appAdminSecret, and caName properties in your config.json
file,
so that it looks something like this (your caName should be different than mine):
{
"connection_file": "ibpConnection.json",
"appAdmin": "policeApp-admin",
"appAdminSecret": "policeApp-adminpw",
"orgMSPID": "policemsp",
"caName": "https://fa707c454921423c80ec3c3c38d7545c-caf2e287.horeainsurancetest.us-south.containers.appdomain.cloud:7054",
"userName": "policeUser",
"gatewayDiscovery": { "enabled": true, "asLocalhost": false }
}
Run the enrollAdmin.js
script
node enrollAdmin.js
You should see the following in the terminal:
msg: Successfully enrolled admin user policeApp-admin and imported it into the wallet
Navigate to the directory blockchain directory which contains the config.js file:
cd build-blockchain-insurance-app/web/www/blockchain/
In the editor of choice, change line 8 of the config.js
file to isCloud: true
as
shown in the image below:
If you are using Mac, save the changes. Otherwise, if you are using an Ubuntu system, change
line 9 of config.js
file to isUbuntu: true
as shown in the image below:
Next, from the blockchain
directory navigate to the root project directory:
blockchain$ cd ../../../
build-blockchain-insurance-app$
Login using your docker hub credentials.
docker login
Run the build script to download and create docker images for the orderer, insurance-peer, police-peer, shop-peer, repairshop-peer, web application and certificate authorities for each peer. This will run for a few minutes.
For Mac user:
cd build-blockchain-insurance-app
./build_mac.sh
For Ubuntu user Make sure isUbuntu:true is saved in the line 9 of config.js
:
cd build-blockchain-insurance-app
./build_ubuntu.sh
You should see the following output on console:
Creating repairshop-ca ...
Creating insurance-ca ...
Creating shop-ca ...
Creating police-ca ...
Creating orderer0 ...
Creating repairshop-ca
Creating insurance-ca
Creating police-ca
Creating shop-ca
Creating orderer0 ... done
Creating insurance-peer ...
Creating insurance-peer ... done
Creating shop-peer ...
Creating shop-peer ... done
Creating repairshop-peer ...
Creating repairshop-peer ... done
Creating web ...
Creating police-peer ...
Creating web
Creating police-peer ... done
Wait for few minutes for application to install and instantiate the chaincode on network
Check the status of installation using command:
docker logs web
On completion, you should see the following output on console:
> [email protected] serve /app
> cross-env NODE_ENV=production&&node ./bin/server
/app/app/static/js
Server running on port: 3000
Default channel not found, attempting creation...
Successfully created a new default channel.
Joining peers to the default channel.
Chaincode is not installed, attempting installation...
Base container image present.
info: [packager/Golang.js]: packaging GOLANG from bcins
info: [packager/Golang.js]: packaging GOLANG from bcins
info: [packager/Golang.js]: packaging GOLANG from bcins
info: [packager/Golang.js]: packaging GOLANG from bcins
Successfully installed chaincode on the default channel.
Successfully instantiated chaincode on all peers.
Use the link http://localhost:3000 to load the web application in browser.
The home page shows the participants (Peers) in the network. You can see that there is an Insurance, Repair Shop, Police and Shop Peer implemented. They are the participants of the network.
Imagine being a consumer (hereinafter called “Biker”) that wants to buy a phone, bike or Ski. By clicking on the “Go to the shop” section, you will be redirected to the shop (shop peer) that offers you the following products.
You can see the three products offered by the shop(s) now. In addition, you have insurance contracts available for them. In our scenario, you are an outdoor sport enthusiast who wants to buy a new Bike. Therefore, you’ll click on the Bike Shop section.
In this section, you are viewing the different bikes available in the store. You can select within four different Bikes. By clicking on next you’ll be forwarded to the next page which will ask for the customer’s personal data.
You have the choice between different insurance contracts that feature different coverage as well as terms and conditions. You are required to type-in your personal data and select a start and end date of the contract. Since there is a trend of short-term or event-driven contracts in the insurance industry you have the chance to select the duration of the contract on a daily basis. The daily price of the insurance contract is being calculated by a formula that had been defined in the chaincode. By clicking on next you will be forwarded to a screen that summarizes your purchase and shows you the total sum.
The application will show you the total sum of your purchase. By clicking on “order” you agree to the terms and conditions and close the deal (signing of the contract). In addition, you’ll receive a unique username and password. The login credentials will be used once you file a claim. A block is being written to the Blockchain.
note You can see the block by clicking on the black arrow on the bottom-right.
At this point, you should be able to go into your IBM Blockchain Platform console, click on the channels, and then be able to see the contract_create block being added.
For additional steps on how to file more claims, and use the rest of the application, please go here.
Congratulations! You've successfully connection your React app to the IBM Blockchain Platform! Now each time you submit transactions with the UI, they will be logged by the blockchain service.
Following is a list of additional blockchain resources:
clean.sh
to remove the docker images and containers for the insurance network../clean.sh
This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.