Awesome
WARNING: This repository is no longer maintained :warning:
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: 中国語,日本語.
Build Blockchain Insurance Application
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. <b>If you only care about running this pattern locally, please find the local instructions here.</b>
Audience level : Intermediate Developers
When the reader has completed this code pattern, they will understand how to:
- Create a Kubernetes Cluster using the IBM Kubernetes Service
- Create an IBM Blockchain service, and launch the service onto the Kubernetes cluster
- Create a network, including all relevant components, such as Certificate Authority, MSP (Membership Service Providers), peers, orderers, and channels.
- Deploy a packaged smart contract onto the IBM Blockchain Platform by installing and instantiating it on the peers.
- Use the connection profile from IBM Blockchain Platform to create application admins, and submit transactions from our client application.
- View transaction details on our channel from IBM Blockchain Platform.
Application Workflow Diagram
- The blockchain operator creates a IBM Kubernetes Service cluster (<b>32CPU, 32RAM, 3 workers recommended</b>) and an IBM Blockchain Platform 2.0 service.
- The IBM Blockchain Platform 2.0 creates a Hyperledger Fabric network on an IBM Kubernetes Service, and the operator installs and instantiates the smart contract on the network.
- The Node.js application server uses the Fabric SDK to interact with the deployed network on IBM Blockchain Platform 2.0.
- The React UI uses the Node.js application API to interact and submit transactions to the network.
- The user interacts with the insurance application web interface to update and query the blockchain ledger and state.
Included Components
- IBM Blockchain Platform V2 Beta gives you total control of your blockchain network with a user interface that can simplify and accelerate your journey to deploy and manage blockchain components on the IBM Cloud Kubernetes Service.
- IBM Cloud Kubernetes Service creates a cluster of compute hosts and deploys highly available containers. A Kubernetes cluster lets you securely manage the resources that you need to quickly deploy, update, and scale applications.
Featured technologies
- Hyperledger Fabric v1.4 is a platform for distributed ledger solutions, underpinned by a modular architecture that delivers high degrees of confidentiality, resiliency, flexibility, and scalability.
- Node.js is an open source, cross-platform JavaScript run-time environment that executes server-side JavaScript code.
- React A declarative, efficient, and flexible JavaScript library for building user interfaces.
- Docker Docker is a computer program that performs operating-system-level virtualization. It was first released in 2013 and is developed by Docker, Inc.
Watch the Video - Multiple Organization and Multiple Peer App Demo #1 - Intro
Watch the Video - IBM Blockchain Tutorial: Multiple Organization and Multiple Peer App Demo #2 - Build Nodes
Watch the Video - Multiple Organization and Multiple Peer App Demo #1 - Intro
Prerequisites
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:
- IBM Cloud account
- Docker - latest
- Docker Compose - latest
- NPM - latest
- nvm - latest
- Node.js - Node v8.9.x
- Git client - latest
- Python - 2.7.x
- React - 15.6.1
Steps
Steps (Local Network)
To run a local network, you can find steps here
Steps (Cloud Network)
- Create IBM Cloud services
- Build a network - Certificate Authority
- Build a network - Create MSP Definitions
- Build a network - Create Peers
- Build a network - Create Orderer
- Build a network - Create and Join Channel
- Deploy Insurance Smart Contract on the network
- Connect application to the network
- Enroll App Admin Identities
- Run the application
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.
Step 1. Create IBM Cloud services
-
Create the IBM Cloud Kubernetes Service. You can find the service in the
Catalog
. Note that <b>for this code pattern, we need to use the 32CPU, 32GB RAM cluster.</b> -
Once you reach the <b> create a new cluster page </b> you will need to do the following:
- Choose <b>standard</b> cluster type
- Fill out cluster name
- choose Geography: <b>North America</b>
- Choose Location and availability: <b>Multizone</b>
- Choose Metro: <b>Dallas</b>
- Choose Worker nodes: <b>Dallas 10 only</b>
- Choose Master service endpoint: <b>Both private & public endpoints</b>
- Choose Default worker pool: <b>1.12.7 (Stable, Default)</b>
- Choose Master service endpoint: <b>Both private & public endpoints</b>
- Choose Flavor <b>32 Cores 32GB RAM, Ubuntu 18</b>
- Choose Encrypt local disk <b>Yes</b>
- Choose Worker nodes <b>3</b>
- Click on <b>create cluster. </b> <b>The cluster takes around 15-20 minutes to provision, so please be patient!</b>
- After your kubernetes cluster is up and running, you can deploy your IBM Blockchain Platform V2 Beta on the cluster. The service walks through few steps and finds your cluster on the IBM Cloud to deploy the service on.
- Once the Blockchain Platform is deployed on the Kubernetes cluster, you can launch the console to start operating on your blockchain network.
Step 2. Build a network - Certificate Authority
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.
-
Create your insurance organization CA
- Click <b>Add Certificate Authority</b>.
- Click <b>IBM Cloud</b> under <b>Create Certificate Authority</b> and <b>Next</b>.
- Give it a <b>Display name</b> of
Insurance CA
. - Specify an <b>Admin ID</b> of
admin
and <b>Admin Secret</b> ofadminpw
.
-
Create your shop organization CA (process is same as shown in gif above)
- Click <b>Add Certificate Authority</b>.
- Click <b>IBM Cloud</b> under <b>Create Certificate Authority</b> and <b>Next</b>.
- Give it a <b>Display name</b> of
Shop CA
. - Specify an <b>Admin ID</b> of
admin
and <b>Admin Secret</b> ofadminpw
.
-
Create your repair shop organization CA (process is same as shown in gif above)
- Click <b>Add Certificate Authority</b>.
- Click <b>IBM Cloud</b> under <b>Create Certificate Authority</b> and <b>Next</b>.
- Give it a <b>Display name</b> of
Repair Shop CA
. - Specify an <b>Admin ID</b> of
admin
and <b>Admin Secret</b> ofadminpw
.
-
Create your police organization CA (process is same as shown in gif above)
- Click <b>Add Certificate Authority</b>.
- Click <b>IBM Cloud</b> under <b>Create Certificate Authority</b> and <b>Next</b>.
- Give it a <b>Display name</b> of
Police CA
. - Specify an <b>Admin ID</b> of
admin
and <b>Admin Secret</b> ofadminpw
.
-
Use your CA to register insurance identities
- Select the <b>Insurance CA</b> Certificate Authority that we created.
- First, we will register an admin for our Insurance Organization. Click on the <b>Register User</b> button. Give an <b>Enroll ID</b> of
insuranceAdmin
, and <b>Enroll Secret</b> ofinsuranceAdminpw
. Click <b>Next</b>. Set the <b>Type</b> for this identity asclient
and selectorg1
from the affiliated organizations drop-down list. We will leave the <b>Maximum enrollments</b> and <b>Add Attributes</b> fields blank. - We will repeat the process to create an identity of the peer. Click on the <b>Register User</b> button. Give an <b>Enroll ID</b> of
insurancePeer
, and <b>Enroll Secret</b> ofinsurancePeerpw
. Click <b>Next</b>. Set the <b>Type</b> for this identity aspeer
and selectorg1
from the affiliated organizations drop-down list. We will leave the <b>Maximum enrollments</b> and <b>Add Attributes</b> fields blank.
-
Use your CA to register shop identities (process is same as shown in gif above)
- Select the <b>Shop CA</b> Certificate Authority that we created.
- First, we will register an admin for our Insurance Organization. Click on the <b>Register User</b> button. Give an <b>Enroll ID</b> of
shopAdmin
, and <b>Enroll Secret</b> ofshopAdminpw
. Click <b>Next</b>. Set the <b>Type</b> for this identity asclient
and selectorg1
from the affiliated organizations drop-down list. We will leave the <b>Maximum enrollments</b> and <b>Add Attributes</b> fields blank. - We will repeat the process to create an identity of the peer. Click on the <b>Register User</b> button. Give an <b>Enroll ID</b> of
shopPeer
, and <b>Enroll Secret</b> ofshopPeerpw
. Click <b>Next</b>. Set the <b>Type</b> for this identity aspeer
and selectorg1
from the affiliated organizations drop-down list. We will leave the <b>Maximum enrollments</b> and <b>Add Attributes</b> fields blank.
-
Use your CA to register repair shop identities (process is same as shown in gif above)
- Select the <b>Repair Shop CA</b> Certificate Authority that we created.
- First, we will register an admin for our Insurance Organization. Click on the <b>Register User</b> button. Give an <b>Enroll ID</b> of
repairShopAdmin
, and <b>Enroll Secret</b> ofrepairShopAdminpw
. Click <b>Next</b>. Set the <b>Type</b> for this identity asclient
and selectorg1
from the affiliated organizations drop-down list. We will leave the <b>Maximum enrollments</b> and <b>Add Attributes</b> fields blank. - We will repeat the process to create an identity of the peer. Click on the <b>Register User</b> button. Give an <b>Enroll ID</b> of
repairShopPeer
, and <b>Enroll Secret</b> ofrepairShopPeerpw
. Click <b>Next</b>. Set the <b>Type</b> for this identity aspeer
and selectorg1
from the affiliated organizations drop-down list. We will leave the <b>Maximum enrollments</b> and <b>Add Attributes</b> fields blank.
-
Use your CA to register police shop identities (process is same as shown in gif above)
- Select the <b>Police CA</b> Certificate Authority that we created.
- First, we will register an admin for our Insurance Organization. Click on the <b>Register User</b> button. Give an <b>Enroll ID</b> of
policeAdmin
, and <b>Enroll Secret</b> ofpoliceAdminpw
. Click <b>Next</b>. Set the <b>Type</b> for this identity asclient
and selectorg1
from the affiliated organizations drop-down list. We will leave the <b>Maximum enrollments</b> and <b>Add Attributes</b> fields blank. - We will repeat the process to create an identity of the peer. Click on the <b>Register User</b> button. Give an <b>Enroll ID</b> of
policePeer
, and <b>Enroll Secret</b> ofpolicePeerpw
. Click <b>Next</b>. Set the <b>Type</b> for this identity aspeer
and selectorg1
from the affiliated organizations drop-down list. We will leave the <b>Maximum enrollments</b> and <b>Add Attributes</b> fields blank.
Step 3. Build a network - Create MSP Definitions
-
Create the insurance MSP definition
- Navigate to the <b>Organizations</b> tab in the left navigation and click <b>Create MSP definition</b>.
- Enter the <b>MSP Display name</b> as
Insurance MSP
and an <b>MSP ID</b> ofinsurancemsp
. - Under <b>Root Certificate Authority</b> details, specify the peer CA that we created
Insurance CA
as the root CA for the organization. - Give the <b>Enroll ID</b> and <b>Enroll secret</b> for your organization admin,
insuranceAdmin
andinsuranceAdminpw
. Then, give the Identity name,Insurance Admin
. - Click the <b>Generate</b> button to enroll this identity as the admin of your organization and export the identity to the wallet. Click <b>Export</b> to export the admin certificates to your file system. Finally click <b>Create MSP definition</b>.
-
Create the shop MSP definition (same process as shown in gif above)
- Navigate to the <b>Organizations</b> tab in the left navigation and click <b>Create MSP definition</b>.
- Enter the <b>MSP Display name</b> as
Shop MSP
and an <b>MSP ID</b> ofshopmsp
. - Under <b>Root Certificate Authority</b> details, specify the peer CA that we created
Shop CA
as the root CA for the organization. - Give the <b>Enroll ID</b> and <b>Enroll secret</b> for your organization admin,
shopAdmin
andshopAdminpw
. Then, give the Identity name,Shop Admin
. - Click the <b>Generate</b> button to enroll this identity as the admin of your organization and export the identity to the wallet. Click <b>Export</b> to export the admin certificates to your file system. Finally click <b>Create MSP definition</b>.
-
Create the repair shop MSP definition (same process as shown in gif above)
- Navigate to the <b>Organizations</b> tab in the left navigation and click <b>Create MSP definition</b>.
- Enter the <b>MSP Display name</b> as
Repair Shop MSP
and an <b>MSP ID</b> ofrepairshopmsp
. - Under <b>Root Certificate Authority</b> details, specify the peer CA that we created
Repair Shop CA
as the root CA for the organization. - Give the <b>Enroll ID</b> and <b>Enroll secret</b> for your organization admin,
repairShopAdmin
andrepairShopAdminpw
. Then, give the Identity name,Repair Shop Admin
. - Click the <b>Generate</b> button to enroll this identity as the admin of your organization and export the identity to the wallet. Click <b>Export</b> to export the admin certificates to your file system. Finally click <b>Create MSP definition</b>.
-
Create the police MSP definition (same process as shown in gif above)
- Navigate to the <b>Organizations</b> tab in the left navigation and click <b>Create MSP definition</b>.
- Enter the <b>MSP Display name</b> as
Police MSP
and an <b>MSP ID</b> ofpolicemsp
. - Under <b>Root Certificate Authority</b> details, specify the peer CA that we created
Police CA
as the root CA for the organization. - Give the <b>Enroll ID</b> and <b>Enroll secret</b> for your organization admin,
policeAdmin
andpoliceAdminpw
. Then, give the Identity name,Police Admin
. - Click the <b>Generate</b> button to enroll this identity as the admin of your organization and export the identity to the wallet. Click <b>Export</b> to export the admin certificates to your file system. Finally click <b>Create MSP definition</b>.
Step 4. Build a network - Create Peers
- Create an insurance peer
- On the <b>Nodes</b> page, click <b>Add peer</b>.
- Click <b>IBM Cloud</b> under Create a new peer and <b>Next</b>.
- Give your peer a <b>Display name</b> of
Insurance Peer
. - On the next screen, select
Insurance CA
as your <b>Certificate Authority</b>. Then, give the <b>Enroll ID</b> and <b>Enroll secret</b> for the peer identity that you created for your peer,insurancePeer
, andinsurancePeerpw
. Then, select the <b>Administrator Certificate (from MSP)</b>,Insurance MSP
, from the drop-down list and click <b>Next</b>. - Give the <b>TLS Enroll ID</b>,
admin
, and <b>TLS Enroll secret</b>,adminpw
, the same values are the Enroll ID and Enroll secret that you gave when creating the CA. Leave the <b>TLS CSR hostname</b> blank. - The last side panel will ask you to <b>Associate an identity</b> and make it the admin of your peer. Select your peer admin identity
Insurance Admin
. - Review the summary and click <b>Submit</b>.
-
Create a shop peer (same process as shown in gif above)
- On the <b>Nodes</b> page, click <b>Add peer</b>.
- Click <b>IBM Cloud</b> under Create a new peer and <b>Next</b>.
- Give your peer a <b>Display name</b> of
Shop Peer
. - On the next screen, select
Shop CA
as your <b>Certificate Authority</b>. Then, give the <b>Enroll ID</b> and <b>Enroll secret</b> for the peer identity that you created for your peer,shopPeer
, andshopPeerpw
. Then, select the <b>Administrator Certificate (from MSP)</b>,Shop MSP
, from the drop-down list and click <b>Next</b>. - Give the <b>TLS Enroll ID</b>,
admin
, and <b>TLS Enroll secret</b>,adminpw
, the same values are the Enroll ID and Enroll secret that you gave when creating the CA. Leave the <b>TLS CSR hostname</b> blank. - The last side panel will ask you to <b>Associate an identity</b> and make it the admin of your peer. Select your peer admin identity
Shop Admin
. - Review the summary and click <b>Submit</b>.
-
Create a repair shop peer (same process as shown in gif above)
- On the <b>Nodes</b> page, click <b>Add peer</b>.
- Click <b>IBM Cloud</b> under Create a new peer and <b>Next</b>.
- Give your peer a <b>Display name</b> of
Repair Shop Peer
. - On the next screen, select
Repair Shop CA
as your <b>Certificate Authority</b>. Then, give the <b>Enroll ID</b> and <b>Enroll secret</b> for the peer identity that you created for your peer,repairShopPeer
, andrepairShopPeerpw
. Then, select the <b>Administrator Certificate (from MSP)</b>,Repair Shop MSP
, from the drop-down list and click <b>Next</b>. - Give the <b>TLS Enroll ID</b>,
admin
, and <b>TLS Enroll secret</b>,adminpw
, the same values are the Enroll ID and Enroll secret that you gave when creating the CA. Leave the <b>TLS CSR hostname</b> blank. - The last side panel will ask you to <b>Associate an identity</b> and make it the admin of your peer. Select your peer admin identity
Repair Shop Admin
. - Review the summary and click <b>Submit</b>.
-
Create a police peer (same process as shown in gif above)
- On the <b>Nodes</b> page, click <b>Add peer</b>.
- Click <b>IBM Cloud</b> under Create a new peer and <b>Next</b>.
- Give your peer a <b>Display name</b> of
Police Peer
. - On the next screen, select
Police CA
as your <b>Certificate Authority</b>. Then, give the <b>Enroll ID</b> and <b>Enroll secret</b> for the peer identity that you created for your peer,policePeer
, andpolicePeerpw
. Then, select the <b>Administrator Certificate (from MSP)</b>,Police MSP
, from the drop-down list and click <b>Next</b>. - Give the <b>TLS Enroll ID</b>,
admin
, and <b>TLS Enroll secret</b>,adminpw
, the same values are the Enroll ID and Enroll secret that you gave when creating the CA. Leave the <b>TLS CSR hostname</b> blank. - The last side panel will ask you to <b>Associate an identity</b> and make it the admin of your peer. Select your peer admin identity
Police Admin
. - Review the summary and click <b>Submit</b>.
Step 5. Build a network - Create Orderer
-
Create your orderer organization CA
- Click <b>Add Certificate Authority</b>.
- Click <b>IBM Cloud</b> under <b>Create Certificate Authority</b> and <b>Next</b>.
- Give it a unique <b>Display name</b> of
Orderer CA
. - Specify an <b>Admin ID</b> of
admin
and <b>Admin Secret</b> ofadminpw
.
-
Use your CA to register orderer and orderer admin identities (shown in gif above)
- In the <b>Nodes</b> tab, select the <b>Orderer CA</b> Certificate Authority that we created.
- First, we will register an admin for our organization. Click on the <b>Register User</b> button. Give an <b>Enroll ID</b> of
ordereradmin
, and <b>Enroll Secret</b> ofordereradminpw
. Click <b>Next</b>. Set the <b>Type</b> for this identity asclient
and selectorg1
from the affiliated organizations drop-down list. We will leave the <b>Maximum enrollments</b> and <b>Add Attributes</b> fields blank. - We will repeat the process to create an identity of the orderer. Click on the <b>Register User</b> button. Give an <b>Enroll ID</b> of
orderer1
, and <b>Enroll Secret</b> oforderer1pw
. Click <b>Next</b>. Set the <b>Type</b> for this identity aspeer
and selectorg1
from the affiliated organizations drop-down list. We will leave the <b>Maximum enrollments</b> and <b>Add Attributes</b> fields blank.
-
Create the orderer organization MSP definition
- Navigate to the <b>Organizations</b> tab in the left navigation and click <b>Create MSP definition</b>.
- Enter the <b>MSP Display name</b> as
Orderer MSP
and an <b>MSP ID</b> oforderermsp
. - Under <b>Root Certificate Authority</b> details, specify the peer CA that we created
Orderer CA
as the root CA for the organization. - Give the <b>Enroll ID</b> and <b>Enroll secret</b> for your organization admin,
ordereradmin
andordereradminpw
. Then, give the <b>Identity name</b>,Orderer Admin
. - Click the <b>Generate</b> button to enroll this identity as the admin of your organization and export the identity to the wallet. Click <b>Export</b> to export the admin certificates to your file system. Finally click <b>Create MSP definition</b>.
-
Create an orderer
- On the <b>Nodes</b> page, click <b>Add orderer</b>.
- Click <b>IBM Cloud</b> and proceed with <b>Next</b>.
- Give your peer a <b>Display name</b> of
Orderer
. - On the next screen, select
Orderer CA
as your <b>Certificate Authority</b>. Then, give the <b>Enroll ID</b> and <b>Enroll secret</b> for the peer identity that you created for your orderer,orderer1
, andorderer1pw
. Then, select the <b>Administrator Certificate (from MSP)</b>,Orderer MSP
, from the drop-down list and click <b>Next</b>. - Give the <b>TLS Enroll ID</b>,
admin
, and <b>TLS Enroll secret</b>,adminpw
, the same values are the Enroll ID and Enroll secret that you gave when creating the CA. Leave the <b>TLS CSR hostname</b> blank. - The last side panel will ask to <b>Associate an identity</b> and make it the admin of your peer. Select your peer admin identity
Orderer Admin
. - Review the summary and click <b>Submit</b>.
-
Add organizations as Consortium Member on the orderer to transact
- Navigate to the <b>Nodes</b> tab, and click on the <b>Orderer</b> that we created.
- Under <b>Consortium Members</b>, click <b>Add organization</b>.
- From the drop-down list, select
Insurance MSP
. - Click <b>Submit</b>.
- Repeat the same steps, but add
Shop MSP
,Repair Shop MSP
, andPolice MSP
as well.
Step 6. Build a network - Create and Join Channel
-
Create the channel
- Navigate to the <b>Channels</b> tab in the left navigation.
- Click <b>Create channel</b>.
- Give the channel a name,
mychannel
. - Select the orderer you created,
Orderer
from the orderers drop-down list. - Select the MSP identifying the organization of the channel creator from the drop-down list. This should be
Insurance MSP (insurancemsp)
. - Associate available identity as
Insurance Admin
. - Click <b>Add</b> next to the insurance organization. Make the insurance organization an <b>Operator</b>.
- Click <b>Add</b> next to the shop organization. Make the shop organization an <b>Operator</b>.
- Click <b>Add</b> next to the repair shop organization. Make the repair shop organization an <b>Operator</b>.
- Click <b>Add</b> next to the police organization. Make the insurance organpoliceization an <b>Operator</b>.
- Click <b>Create</b>.
-
Join your peer to the channel
- Click <b>Join channel</b> to launch the side panels.
- Select your
Orderer
and click <b>Next</b>. - Enter the name of the channel you just created.
mychannel
and click <b>Next</b>. - Select which peers you want to join the channel, click
Insurance Peer
,Shop Peer
,Repair Shop Peer
, andPolice Peer
. - Click <b>Submit</b>.
-
Add anchor peers to the channel
- In order to communicate between organizations, we need to enroll anchor peers.
- From the channels tab, click on the channel you have created,
mychannel
. - From the channel overview page, click on
channel details
. Scroll all the way down until you seeAnchor peers
. - Click
Add anchor peer
and add the Insurance, Police, Repair Shop, and Shop peers. - Select which peers you want to join the channel, click
Insurance Peer
,Shop Peer
,Repair Shop Peer
, andPolice Peer
. - Click <b>Add anchor peer</b>.
- If all went well, your channel Anchor peers should look like below:
Step 7. Deploy Insurance Smart Contract on the network
-
Install a smart contract
- Clone the repository:
git clone https://github.com/IBM/build-blockchain-insurance-app
- Click the <b>Smart contracts</b> tab to install the smart contract.
- Click <b>Install smart contract</b> to upload the insurance smart contract package file.
- Click on <b>Add file</b> and find your packaged smart contract. It is the file in the
build-blockchain-insurance-app/chaincodePackage
directory. - Select all peers - we need to install the contract on each peer.
- Once the contract is uploaded, click <b>Install</b>.
-
Instantiate smart contract
- On the smart contracts tab, find the smart contract from the list installed on your peers and click <b>Instantiate</b> from the overflow menu on the right side of the row.
- On the side panel that opens, select the channel,
mychannel
to instantiate the smart contract on. Click <b>Next</b>. - Select the organization members to be included in the policy,
insurancemsp
,shopmsp
,repairshopmsp
,policemsp
. Click <b>Next</b>. - Give <b>Function name</b> of
Init
and leave <b>Arguments</b> blank. - Click <b>Instantiate</b>.
Step 8. Connect application to the network
-
Connect with sdk through connection profile
- Under the Instantiated Smart Contract, click on
Connect with SDK
from the overflow menu on the right side of the row. - Choose from the dropdown for <b>MSP for connection</b>,
insurancemsp
. - Choose from <b>Certificate Authority</b> dropdown,
Insurance CA
. - Download the connection profile by scrolling down and clicking <b>Download Connection Profile</b>. This will download the connection json which we will use soon to establish connection.
- You can click <b>Close</b> once the download completes.
- Under the Instantiated Smart Contract, click on
-
Create insurance application admin
- Go to the <b>Nodes</b> tab on the left bar, and under <b>Certificate Authorities</b>, choose your <b>Insurance CA</b>.
- Click on <b>Register user</b>.
- Give an <b>Enroll ID</b> and <b>Enroll Secret</b> to administer your application users,
insuranceApp-admin
andinsuranceApp-adminpw
. - Choose
client
as <b>Type</b>. - You can leave the <b>Use root affiliation</b> box checked.
- You can leave the <b>Maximum enrollments</b> blank.
- Under <b>Attributes</b>, click on <b>Add attribute</b>. Give attribute as
hf.Registrar.Roles
=*
. This will allow this identity to act as registrar and issues identities for our app. Click <b>Add-attribute</b>. - Click <b>Register</b>.
-
Create shop application admin (same process as shown above in the gif)
- Go to the <b>Nodes</b> tab on the left bar, and under <b>Certificate Authorities</b>, choose your <b>Shop CA</b>.
- Click on <b>Register user</b>.
- Give an <b>Enroll ID</b> and <b>Enroll Secret</b> to administer your application users,
shopApp-admin
andshopApp-adminpw
. - Choose
client
as <b>Type</b>. - You can leave the <b>Use root affiliation</b> box checked.
- You can leave the <b>Maximum enrollments</b> blank.
- Under <b>Attributes</b>, click on <b>Add attribute</b>. Give attribute as
hf.Registrar.Roles
=*
. This will allow this identity to act as registrar and issues identities for our app. Click <b>Add-attribute</b>. - Click <b>Register</b>.
-
Create repair shop application admin (same process as shown above in the gif)
- Go to the <b>Nodes</b> tab on the left bar, and under <b>Certificate Authorities</b>, choose your <b>Repair Shop CA</b>.
- Click on <b>Register user</b>.
- Give an <b>Enroll ID</b> and <b>Enroll Secret</b> to administer your application users,
repairShopApp-admin
andrepairShopApp-adminpw
. - Choose
client
as <b>Type</b>. - You can leave the <b>Use root affiliation</b> box checked.
- You can leave the <b>Maximum enrollments</b> blank.
- Under <b>Attributes</b>, click on <b>Add attribute</b>. Give attribute as
hf.Registrar.Roles
=*
. This will allow this identity to act as registrar and issues identities for our app. Click <b>Add-attribute</b>. - Click <b>Register</b>.
-
Create police application admin (same process as shown above in the gif)
- Go to the <b>Nodes</b> tab on the left bar, and under <b>Certificate Authorities</b>, choose your <b>Police CA</b>.
- Click on <b>Register user</b>.
- Give an <b>Enroll ID</b> and <b>Enroll Secret</b> to administer your application users,
policeApp-admin
andpoliceApp-adminpw
. - Choose
client
as <b>Type</b>. - You can leave the <b>Use root affiliation</b> box checked.
- You can leave the <b>Maximum enrollments</b> blank.
- Under <b>Attributes</b>, click on <b>Add attribute</b>. Give attribute as
hf.Registrar.Roles
=*
. This will allow this identity to act as registrar and issues identities for our app. Click <b>Add-attribute</b>. - Click <b>Register</b>.
Update application connection
- Copy the connection profile you downloaded into the
web/www/blockchain
directory. - Copy and paste everything in the connection profile, and overwrite the ibpConnection.json.
Step 9. Enroll App Admin Identities
-
Enroll insurnaceApp-admin
-
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 <b>insurance</b> certificate authority from youribpConnection.json
file. Save the file. -
Run the
enrollAdmin.js
scriptnode enrollAdmin.js
-
You should see the following in the terminal:
msg: Successfully enrolled admin user insuranceApp-admin and imported it into the wallet
-
- Enroll shopApp-admin
-
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 yourconfig.json
caName field.
-
-
Run the
enrollAdmin.js
scriptnode enrollAdmin.js
-
You should see the following in the terminal:
msg: Successfully enrolled admin user shopApp-admin and imported it into the wallet
-
Enroll repairShopApp-admin (same process as shown in gif above)
-
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
scriptnode enrollAdmin.js
-
You should see the following in the terminal:
msg: Successfully enrolled admin user repairShopApp-admin and imported it into the wallet
-
-
Enroll policeApp-admin (same process as shown in gif above)
-
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
scriptnode enrollAdmin.js
-
You should see the following in the terminal:
msg: Successfully enrolled admin user policeApp-admin and imported it into the wallet
-
Step 10. Run the application
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
<p align="center">
<img src="images/gifs/buildApp.gif">
</p>
<br>
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:
> blockchain-for-insurance@2.1.0 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.
<p align="center"> <img src="images/gifs/runAppIBP.gif"> </p> <br>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.
Additional resources
Following is a list of additional blockchain resources:
Troubleshooting
- Run
clean.sh
to remove the docker images and containers for the insurance network.
./clean.sh
License
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.