Home
Softono
i

ibm

Professional software vendor delivering innovative solutions on the Softono platform. Specialized in both open-source and proprietary software development.

Total Products
5

Software by ibm

MAX-Image-Resolution-Enhancer
Open Source

MAX-Image-Resolution-Enhancer

[![Build Status](https://travis-ci.com/IBM/MAX-Image-Resolution-Enhancer.svg?branch=master)](https://travis-ci.com/IBM/MAX-Image-Resolution-Enhancer) [![API demo](https://img.shields.io/website/http/max-image-resolution-enhancer.codait-prod-41208c73af8fca213512856c7a09db52-0000.us-east.containers.appdomain.cloud/swagger.json.svg?label=API%20demo&down_message=down&up_message=up)](http://max-image-resolution-enhancer.codait-prod-41208c73af8fca213512856c7a09db52-0000.us-east.containers.appdomain.cloud) [<img src="docs/deploy-max-to-ibm-cloud-with-kubernetes-button.png" width="400px">](http://ibm.biz/max-to-ibm-cloud-tutorial) # IBM Developer Model Asset Exchange: Image Resolution Enhancer This repository contains code to instantiate and deploy an image resolution enhancer. This model is able to upscale a pixelated image by a factor of 4, while generating photo-realistic details. The GAN is based on [this GitHub repository](https://github.com/brade31919/SRGAN-tensorflow) and on [this research article](https://arxiv.org/pdf/1609.04802.pdf). The model was trained on 600,000 images of the [OpenImages V4](https://storage.googleapis.com/openimages/web/index.html) dataset, and the model files are hosted on [IBM Cloud Object Storage](https://max-cdn.cdn.appdomain.cloud/max-image-resolution-enhancer/1.0.0/assets.tar.gz). The code in this repository deploys the model as a web service in a Docker container. This repository was developed as part of the [IBM Developer Model Asset Exchange](https://developer.ibm.com/exchanges/models/) and the public API is powered by [IBM Cloud](https://ibm.biz/Bdz2XM). ## Model Metadata | Domain | Application | Industry | Framework | Training Data | Input Data Format | | ------------- | -------- | -------- | --------- | --------- | -------------- | | Vision | Super-Resolution | General | TensorFlow | [OpenImages V4](https://storage.googleapis.com/openimages/web/index.html) | Image (RGB/HWC) | ## Benchmark | Set5 | Author's SRGAN | This SRGAN | | -------- | ------------------ | ----------- | | PSNR | 29.40 | 29.56 | | SSIM | 0.85 | 0.85 | | Set14 | Author's SRGAN | This SRGAN | | -------- | ------------------ | ----------- | | PSNR | 26.02 | 26.25 | | SSIM | 0.74 | 0.72 | | BSD100 | Author's SRGAN | This SRGAN | | -------- | ------------------ | ----------- | | PSNR | 25.16 | 24.4 | | SSIM | 0.67 | 0.67 | The performance of this implementation was evaluated on three datasets: Set5, Set14, and BSD100. The PSNR (peak signal to noise ratio) and SSIM (structural similarity index) metrics were evaluated, although the paper discusses the MOS (mean opinion score) as the most favorable metric. In essence, the SRGAN implementation trades a better PSNR or SSIM score for a result more appealing to the human eye. This leads to a collection of output images with more crisp and realistic details. _NOTE: The SRGAN in the paper was trained on 350k ImageNet samples, whereas this SRGAN was trained on 600k [OpenImages V4](https://storage.googleapis.com/openimages/web/index.html) pictures._ ## References * _C. Ledig, L. Theis, F. Huszar, J. Caballero, A. Cunningham, A. Acosta, A. Aitken, A. Tejani, J. Totz, Z. Wang, W. Shi_, [Photo-Realistic Single Image Super-Resolution Using a Generative Adversarial Network](https://arxiv.org/pdf/1609.04802.pdf), ArXiv, 2017. * [SRGAN-tensorflow (model code source)](https://github.com/brade31919/SRGAN-tensorflow) * [tensorflow-SRGAN](https://github.com/trevor-m/tensorflow-SRGAN) * [Deconvolution and Checkerboard Artefacts](https://distill.pub/2016/deconv-checkerboard/) ## Licenses | Component | License | Link | | ------------- | -------- | -------- | | This repository | [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) | [LICENSE](https://github.com/IBM/max-image-resolution-enhancer/blob/master/LICENSE) | | Model Weights | [Apache 2.0](https://www.apache.org/licenses/LICENSE-2.0) | [LICENSE](https://github.com/IBM/max-image-resolution-enhancer/blob/master/LICENSE) | | Model Code (3rd party) | [MIT](https://opensource.org/licenses/MIT) | [LICENSE](https://github.com/brade31919/SRGAN-tensorflow/blob/master/LICENSE.txt) | | Test samples | [CC BY 2.0](https://creativecommons.org/licenses/by/2.0/) | [Asset README](samples/README.md) | | | [CC0](https://creativecommons.org/publicdomain/zero/1.0/) | [Asset README](samples/README.md) | ## Pre-requisites: * `docker`: The [Docker](https://www.docker.com/) command-line interface. Follow the [installation instructions](https://docs.docker.com/install/) for your system. * The minimum recommended resources for this model is 8 GB Memory (see Troubleshooting) and 4 CPUs. * If you are on x86-64/AMD64, your CPU must support [AVX](https://en.wikipedia.org/wiki/Advanced_Vector_Extensions) at the minimum. # Deployment options * [Deploy from Quay](#deploy-from-quay) * [Deploy on Red Hat OpenShift](#deploy-on-red-hat-openshift) * [Deploy on Kubernetes](#deploy-on-kubernetes) * [Run Locally](#run-locally) ## Deploy from Quay To run the docker image, which automatically starts the model serving API, run: ``` $ docker run -it -p 5000:5000 quay.io/codait/max-image-resolution-enhancer ``` This will pull a pre-built image from the Quay.io container registry (or use an existing image if already cached locally) and run it. If you'd rather checkout and build the model locally you can follow the [run locally](#run-locally) steps below. ## Deploy on Red Hat OpenShift You can deploy the model-serving microservice on Red Hat OpenShift by following the instructions for the OpenShift web console or the OpenShift Container Platform CLI [in this tutorial](https://developer.ibm.com/tutorials/deploy-a-model-asset-exchange-microservice-on-red-hat-openshift/), specifying `quay.io/codait/max-image-resolution-enhancer` as the image name. ## Deploy on Kubernetes You can also deploy the model on Kubernetes using the latest docker image on Quay. On your Kubernetes cluster, run the following commands: ``` $ kubectl apply -f https://github.com/IBM/max-image-resolution-enhancer/raw/master/max-image-resolution-enhancer.yaml ``` The model will be available internally at port `5000`, but can also be accessed externally through the `NodePort`. A more elaborate tutorial on how to deploy this MAX model to production on [IBM Cloud](https://ibm.biz/Bdz2XM) can be found [here](http://ibm.biz/max-to-ibm-cloud-tutorial). ## Run Locally 1. [Build the Model](#1-build-the-model) 2. [Deploy the Model](#2-deploy-the-model) 3. [Use the Model](#3-use-the-model) 4. [Development](#4-development) 5. [Cleanup](#5-cleanup) ### 1. Build the Model Clone this repository locally. In a terminal, run the following command: ``` $ git clone https://github.com/IBM/max-image-resolution-enhancer.git ``` Change directory into the repository base folder: ``` $ cd max-image-resolution-enhancer ``` To build the docker image locally, run: ``` $ docker build -t max-image-resolution-enhancer . ``` All required model assets will be downloaded during the build process. _Note_ that currently this docker image is CPU only (we will add support for GPU images later). ### 2. Deploy the Model To run the docker image, which automatically starts the model serving API, run: ``` $ docker run -it -p 5000:5000 max-image-resolution-enhancer ``` ### 3. Use the Model The API server automatically generates an interactive Swagger documentation page. Go to `http://localhost:5000` to load it. From there you can explore the API and also create test requests. Use the `model/predict` endpoint to load a test image (you can use one of the test images from the `samples/test_examples/low_resolution` folder) in order to get a high resolution output image returned. The ideal input image is a PNG file with a resolution between 100x100 and 500x500, preferably without any post-capture processing and flashy colors. The model is able to generate details from a pixelated image (low DPI), but is not able to correct a 'blurred' image. ![input](docs/example.png) _Left: input image (128×80). Right: output image (512×320)_ ![Swagger UI screenshot](docs/swagger-screenshot.png) You can also test it on the command line, for example: ``` $ curl -F "image=@samples/test_examples/low_resolution/food.png" -XPOST http://localhost:5000/model/predict > food_high_res.png ``` The above command will send the low resolution `food.png` file to the model, and save the high resolution output image to the `food_high_res.png` file in the root directory. ### 4. Development To run the Flask API app in debug mode, edit `config.py` to set `DEBUG = True` under the application settings. You will then need to rebuild the docker image (see [step 1](#1-build-the-model)). Please remember to set `DEBUG = False` when running the model in production. ### 5. Cleanup To stop the Docker container, type `CTRL` + `C` in your terminal. # Troubleshooting - Calling the ```model/predict``` endpoint kills the Docker container with the message ```Killed``` > This is likely caused due to the default limitation of Docker's memory allocation to 2 GB. Navigate to the ```Preferences``` menu under the Docker Desktop application. Use the slider to increase the available memory to 8 GB and restart Docker Desktop. - The details in the output image are different than what may be expected and are sometimes not physically possible > This model generates details basically 'out of thin air'. Creating something out of nothing is not possible without making assumptions. The network attempts to recognize elements in the low-resolution image from which it can infer what the reality (human eye | super-resolution) could have looked like. If a group of pixels strongly resembles an observation that is not related to the content of the image, it might lead to observing results that are not 'physically possible'. >For example: a white pixel in a low-resolution image might have been converted to a snowflake, although the original picture might have been taken in the desert. This example is imaginary and has not actually been observed. - Artefacts in the output image > Observing artefacts in some images is unfortunately inevitable as any neural network is subject to technical limitations and characteristics of the training data. > Keep in mind that the best results are achieved with the following: > * A PNG image > * An image that is sufficiently zoomed in. During the process, the network groups a block of pixels together. If the block contains more details than the network produces, the result will be spurious. > * An image taken under natural light, without filters, and with few bright or flashy colors. The neural network was not trained on heavily edited images. > * An image that has sufficiently high resolution to not confuse the network with multiple possibilities (e.g. a sole pixel in a very low-resolution image could represent an entire car, person, sandwich,..) > * The model is able to generate details from a pixelated image (low DPI), but is not able to correct a 'blurred' image. ## Resources and Contributions If you are interested in contributing to the Model Asset Exchange project or have any queries, please follow the instructions [here](https://github.com/CODAIT/max-central-repo).

AI & Machine Learning Image Editing
1K Github Stars
unitxt
Open Source

unitxt

<div align="center"> <img src="https://www.unitxt.ai/en/latest/_static/banner.png" alt="Image Description" width="100%" /> </div> # [![version](https://img.shields.io/pypi/v/unitxt)](https://pypi.org/project/unitxt/) ![license](https://img.shields.io/github/license/ibm/unitxt) ![python](https://img.shields.io/badge/python-3.8%20|%203.9-blue) ![tests](https://img.shields.io/github/actions/workflow/status/ibm/unitxt/library_tests.yml?branch=main&label=tests) [![Coverage Status](https://coveralls.io/repos/github/IBM/unitxt/badge.svg)](https://coveralls.io/github/IBM/unitxt) ![Read the Docs](https://img.shields.io/readthedocs/unitxt) [![downloads](https://static.pepy.tech/personalized-badge/unitxt?period=total&units=international_system&left_color=grey&right_color=green&left_text=downloads)](https://pepy.tech/project/unitxt) ### 🦄 Unitxt is a Python library for enterprise-grade evaluation of AI performance, offering the world's largest catalog of tools and data for end-to-end AI benchmarking # ## Why Unitxt? - 🌐 **Comprehensive**: Evaluate text, tables, vision, speech, and code in one unified framework - 💼 **Enterprise-Ready**: Battle-tested components with extensive catalog of benchmarks - 🧠 **Model Agnostic**: Works with HuggingFace, OpenAI, WatsonX, and custom models - 🔒 **Reproducible**: Shareable, modular components ensure consistent results ## Quick Links - 📖 [Documentation](https://www.unitxt.ai) - 🚀 [Getting Started](https://www.unitxt.ai) - 📁 [Browse Catalog](https://www.unitxt.ai/en/latest/catalog/catalog.__dir__.html) # Installation ```bash pip install unitxt ``` # Quick Start ## Command Line Evaluation ```bash # Simple evaluation unitxt-evaluate \ --tasks "card=cards.mmlu_pro.engineering" \ --model cross_provider \ --model_args "model_name=llama-3-1-8b-instruct" \ --limit 10 # Multi-task evaluation unitxt-evaluate \ --tasks "card=cards.text2sql.bird+card=cards.mmlu_pro.engineering" \ --model cross_provider \ --model_args "model_name=llama-3-1-8b-instruct,max_tokens=256" \ --split test \ --limit 10 \ --output_path ./results/evaluate_cli \ --log_samples \ --apply_chat_template # Benchmark evaluation unitxt-evaluate \ --tasks "benchmarks.tool_calling" \ --model cross_provider \ --model_args "model_name=llama-3-1-8b-instruct,max_tokens=256" \ --split test \ --limit 10 \ --output_path ./results/evaluate_cli \ --log_samples \ --apply_chat_template ``` ## Loading as Dataset Load thousands of datasets in chat API format, ready for any model: ```python from unitxt import load_dataset dataset = load_dataset( card="cards.gpqa.diamond", split="test", format="formats.chat_api", ) ``` ## 📊 Available on The Catalog ![Tasks](https://img.shields.io/badge/Tasks-68-blue) ![Datasets](https://img.shields.io/badge/Datasets-3254-blue) ![Prompts](https://img.shields.io/badge/Prompts-357-blue) ![Benchmarks](https://img.shields.io/badge/Benchmarks-11-blue) ![Metrics](https://img.shields.io/badge/Metrics-584-blue) ## 🚀 Interactive Dashboard Launch the graphical user interface to explore datasets and benchmarks: ``` pip install unitxt[ui] unitxt-explore ``` # Complete Python Example Evaluate your own data with any model: ```python # Import required components from unitxt import evaluate, create_dataset from unitxt.blocks import Task, InputOutputTemplate from unitxt.inference import HFAutoModelInferenceEngine # Question-answer dataset data = [ {"question": "What is the capital of Texas?", "answer": "Austin"}, {"question": "What is the color of the sky?", "answer": "Blue"}, ] # Define the task and evaluation metric task = Task( input_fields={"question": str}, reference_fields={"answer": str}, prediction_type=str, metrics=["metrics.accuracy"], ) # Create a template to format inputs and outputs template = InputOutputTemplate( instruction="Answer the following question.", input_format="{question}", output_format="{answer}", postprocessors=["processors.lower_case"], ) # Prepare the dataset dataset = create_dataset( task=task, template=template, format="formats.chat_api", test_set=data, split="test", ) # Set up the model (supports Hugging Face, WatsonX, OpenAI, etc.) model = HFAutoModelInferenceEngine( model_name="Qwen/Qwen1.5-0.5B-Chat", max_new_tokens=32 ) # Generate predictions and evaluate predictions = model(dataset) results = evaluate(predictions=predictions, data=dataset) # Print results print("Global Results:\n", results.global_scores.summary) print("Instance Results:\n", results.instance_scores.summary) ``` # Contributing Read the [contributing guide](./CONTRIBUTING.md) for details on how to contribute to Unitxt. # # Citation If you use Unitxt in your research, please cite our paper: ```bib @inproceedings{bandel-etal-2024-unitxt, title = "Unitxt: Flexible, Shareable and Reusable Data Preparation and Evaluation for Generative {AI}", author = "Bandel, Elron and Perlitz, Yotam and Venezian, Elad and Friedman, Roni and Arviv, Ofir and Orbach, Matan and Don-Yehiya, Shachar and Sheinwald, Dafna and Gera, Ariel and Choshen, Leshem and Shmueli-Scheuer, Michal and Katz, Yoav", editor = "Chang, Kai-Wei and Lee, Annie and Rajani, Nazneen", booktitle = "Proceedings of the 2024 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies (Volume 3: System Demonstrations)", month = jun, year = "2024", address = "Mexico City, Mexico", publisher = "Association for Computational Linguistics", url = "https://aclanthology.org/2024.naacl-demo.21", pages = "207--215", } ```

ML Frameworks Testing & QA
214 Github Stars
ai-privacy-toolkit
Open Source

ai-privacy-toolkit

[![OpenSSF Best Practices](https://bestpractices.coreinfrastructure.org/projects/5836/badge)](https://bestpractices.coreinfrastructure.org/projects/5836) # ai-privacy-toolkit <p align="center"> <img src="docs/images/logo with text.jpg?raw=true" width="467" title="ai-privacy-toolkit logo"> </p> <br /> A toolkit for tools and techniques related to the privacy and compliance of AI models. The [**anonymization**](apt/anonymization/README.md) module contains methods for anonymizing ML model training data, so that when a model is retrained on the anonymized data, the model itself will also be considered anonymous. This may help exempt the model from different obligations and restrictions set out in data protection regulations such as GDPR, CCPA, etc. The [**minimization**](apt/minimization/README.md) module contains methods to help adhere to the data minimization principle in GDPR for ML models. It enables to reduce the amount of personal data needed to perform predictions with a machine learning model, while still enabling the model to make accurate predictions. This is done by by removing or generalizing some of the input features. The [**dataset assessment**](apt/risk/data_assessment/README.md) module implements a tool for privacy assessment of synthetic datasets that are to be used in AI model training. Official ai-privacy-toolkit documentation: https://ai-privacy-toolkit.readthedocs.io/en/latest/ Installation: pip install ai-privacy-toolkit For more information or help using or improving the toolkit, please contact Abigail Goldsteen at [email protected], or join our Slack channel: https://aip360.mybluemix.net/community. We welcome new contributors! If you're interested, take a look at our [**contribution guidelines**](https://github.com/IBM/ai-privacy-toolkit/wiki/Contributing). **Related toolkits:** ai-minimization-toolkit - has been migrated into this toolkit. [differential-privacy-library](https://github.com/IBM/differential-privacy-library): A general-purpose library for experimenting with, investigating and developing applications in, differential privacy. [adversarial-robustness-toolbox](https://github.com/Trusted-AI/adversarial-robustness-toolbox): A Python library for Machine Learning Security. Includes an attack module called *inference* that contains privacy attacks on ML models (membership inference, attribute inference, model inversion and database reconstruction) as well as a *privacy* metrics module that contains membership leakage metrics for ML models. Citation -------- Abigail Goldsteen, Ola Saadi, Ron Shmelkin, Shlomit Shachor, Natalia Razinkov, "AI privacy toolkit", SoftwareX, Volume 22, 2023, 101352, ISSN 2352-7110, https://doi.org/10.1016/j.softx.2023.101352.

AI Agents Compliance & Governance
114 Github Stars
data-science-best-practices
Open Source

data-science-best-practices

# IBM Data Science - Best Practices &middot; [![License](https://img.shields.io/badge/license-CC%20BY%204.0-blue)](./LICENSE.txt) ## Read Me Go to [IBM Data Science - Best Practices website](https://ibm.github.io/data-science-best-practices). ## License See [License](./license.md) ## Need Help Reach us at on Slack [#datascience-best-practices](https://slack.com/app_redirect?channel=CUZGJN43V) (IBM Internal)

AI & Machine Learning ML Frameworks
95 Github Stars
build-blockchain-insurance-app
Open Source

build-blockchain-insurance-app

# 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: [中国語](README-cn.md),[日本語](README-ja.md).* # 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](./README-local.md).</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 ![Workflow](images/app-arch.png) 1. The blockchain operator creates a IBM Kubernetes Service cluster (<b>32CPU, 32RAM, 3 workers recommended</b>) and an IBM Blockchain Platform 2.0 service. 2. 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. 3. The Node.js application server uses the Fabric SDK to interact with the deployed network on IBM Blockchain Platform 2.0. 4. The React UI uses the Node.js application API to interact and submit transactions to the network. 5. 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](https://console.bluemix.net/docs/services/blockchain/howto/ibp-v2-deploy-iks.html#ibp-v2-deploy-iks) 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](https://www.ibm.com/cloud/container-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](https://hyperledger-fabric.readthedocs.io) is a platform for distributed ledger solutions, underpinned by a modular architecture that delivers high degrees of confidentiality, resiliency, flexibility, and scalability. * [Node.js](https://nodejs.org) is an open source, cross-platform JavaScript run-time environment that executes server-side JavaScript code. * [React](https://reactjs.org/) A declarative, efficient, and flexible JavaScript library for building user interfaces. * [Docker](https://www.docker.com/) 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 [![](images/part1.png)](https://www.youtube.com/watch?v=Lr3EFKayP0o) # Watch the Video - IBM Blockchain Tutorial: Multiple Organization and Multiple Peer App Demo #2 - Build Nodes [![](images/part2.png)](https://www.youtube.com/watch?v=wi6i28vRigs) # Watch the Video - Multiple Organization and Multiple Peer App Demo #1 - Intro [![](images/part3.png)](https://www.youtube.com/watch?v=3dRckqZvFqw) ## Prerequisites We find that Blockchain can be finicky when it comes to installing Node. We want to share this [StackOverflow response](https://stackoverflow.com/questions/49744276/error-cannot-find-module-api-hyperledger-composer) - 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](https://cloud.ibm.com/registration) * [Docker](https://www.docker.com/products) - latest * [Docker Compose](https://docs.docker.com/compose/overview/) - latest * [NPM](https://www.npmjs.com/get-npm) - latest * [nvm]() - latest * [Node.js](https://nodejs.org/en/download/) - Node v8.9.x * [Git client](https://git-scm.com/downloads) - latest * **[Python](https://www.python.org/downloads/) - 2.7.x** * [React](https://reactjs.org/) - 15.6.1 # Steps # Steps (Local Network) > To run a local network, you can find steps [here](./README-local.md) ### Steps (Cloud Network) 1. [Create IBM Cloud services](#step-1-Create-IBM-Cloud-services) 2. [Build a network - Certificate Authority](#step-2-Build-a-network---Certificate-Authority) 3. [Build a network - Create MSP Definitions](#step-3-Build-a-network---Create-MSP-Definitions) 4. [Build a network - Create Peers](#step-4-build-a-network---Create-Peers) 5. [Build a network - Create Orderer](#step-5-Build-a-network---Create-Orderer) 6. [Build a network - Create and Join Channel](#step-6-Build-a-network---Create-and-Join-Channel) 7. [Deploy Insurance Smart Contract on the network](#step-7-Deploy-Insurance-Smart-Contract-on-the-network) 8. [Connect application to the network](#step-8-Connect-application-to-the-network) 9. [Enroll App Admin Identities](#step-9-Enroll-App-Admin-Identities) 10. [Run the application](#step-10-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](https://github.com/IBM/blockchainbean2). ## Step 1. Create IBM Cloud services * Create the [IBM Cloud Kubernetes Service](https://cloud.ibm.com/catalog/infrastructure/containers-kubernetes). 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> <br> <p align="center"> <img src="images/gifs/createCluster.gif"> </p> <br> * 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. <br> <p align="center"> <img src="images/gifs/deploy-blockchain-on-cluster.gif"> </p> <br> * Once the Blockchain Platform is deployed on the Kubernetes cluster, you can launch the console to start operating on your blockchain network. <br> <p align="center"> <img src="images/gifs/launch-ibm-blockchain.gif"> </p> <br> ## Step 2. Build a network - Certificate Authority We will build a network as provided by the IBM Blockchain Platform [documentation](https://console.bluemix.net/docs/services/blockchain/howto/ibp-console-build-network.html#ibp-console-build-network). 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> of `adminpw`. <br> <p align="center"> <img src="images/gifs/insuranceIBP2.gif"> </p> <br> * #### 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> of `adminpw`. * #### 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> of `adminpw`. * #### 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> of `adminpw`. * #### 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> of `insuranceAdminpw`. Click <b>Next</b>. Set the <b>Type</b> for this identity as `client` and select `org1` 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> of `insurancePeerpw`. Click <b>Next</b>. Set the <b>Type</b> for this identity as `peer` and select `org1` from the affiliated organizations drop-down list. We will leave the <b>Maximum enrollments</b> and <b>Add Attributes</b> fields blank. <br> <p align="center"> <img src="images/gifs/registerInsuranceAdminPeer.gif"> </p> <br> * #### 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> of `shopAdminpw`. Click <b>Next</b>. Set the <b>Type</b> for this identity as `client` and select `org1` 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> of `shopPeerpw`. Click <b>Next</b>. Set the <b>Type</b> for this identity as `peer` and select `org1` 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> of `repairShopAdminpw`. Click <b>Next</b>. Set the <b>Type</b> for this identity as `client` and select `org1` 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> of `repairShopPeerpw`. Click <b>Next</b>. Set the <b>Type</b> for this identity as `peer` and select `org1` 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> of `policeAdminpw`. Click <b>Next</b>. Set the <b>Type</b> for this identity as `client` and select `org1` 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> of `policePeerpw`. Click <b>Next</b>. Set the <b>Type</b> for this identity as `peer` and select `org1` 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> of `insurancemsp`. - 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` and `insuranceAdminpw`. 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>. <br> <p align="center"> <img src="images/gifs/insuranceMSP.gif"> </p> <br> * #### 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> of `shopmsp`. - 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` and `shopAdminpw`. 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> of `repairshopmsp`. - 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` and `repairShopAdminpw`. 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> of `policemsp`. - 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` and `policeAdminpw`. 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`, and `insurancePeerpw`. 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>. <br> <p align="center"> <img src="images/gifs/addInsurancePeer.gif"> </p> <br> * 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`, and `shopPeerpw`. 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`, and `repairShopPeerpw`. 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`, and `policePeerpw`. 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> of `adminpw`. <br> <p align="center"> <img src="images/gifs/createOrderer.gif"> </p> <br> * #### 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> of `ordereradminpw`. Click <b>Next</b>. Set the <b>Type</b> for this identity as `client` and select `org1` 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> of `orderer1pw`. Click <b>Next</b>. Set the <b>Type</b> for this identity as `peer` and select `org1` 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> of `orderermsp`. - 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` and `ordereradminpw`. 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>. <br> <p align="center"> <img src="images/gifs/ordererMSP.gif"> </p> <br> * #### 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`, and `orderer1pw`. 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>. <br> <p align="center"> <img src="images/gifs/createOrdererNode.gif"> </p> <br> * #### 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`, and `Police MSP` as well. <br> <p align="center"> <img src="images/gifs/addConsortium.gif"> </p> <br> ## 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>. <br> <p align="center"> <img src="images/gifs/createChannel.gif"> </p> <br> * #### 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`, and `Police Peer`. - Click <b>Submit</b>. <br> <p align="center"> <img src="images/gifs/joinChannel.gif"> </p> <br> * #### 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 see `Anchor 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`, and `Police Peer`. - Click <b>Add anchor peer</b>. - If all went well, your channel Anchor peers should look like below: <br> <p align="center"> <img src="images/gifs/addAnchorPeer.gif"> </p> <br> ## Step 7. Deploy Insurance Smart Contract on the network * #### Install a smart contract * Clone the repository: ```bash 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>. <br> <p align="center"> <img src="images/gifs/installSmartContract.gif"> </p> <br> * #### 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>. <br> <p align="center"> <img src="images/gifs/instantiateContract.gif"> </p> <br> ## 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. <br> <p align="center"> <img src="images/gifs/downloadConnection.gif"> </p> <br> * #### 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` and `insuranceApp-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>. <br> <p align="center"> <img src="images/gifs/appAdmin.gif"> </p> <br> * #### 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` and `shopApp-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` and `repairShopApp-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` and `policeApp-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**. <p align="center"> <img src="images/gifs/ibpConnection.gif"> </p> ## Step 9. Enroll App Admin Identities * #### Enroll insurnaceApp-admin - First, navigate to the `web/www/blockchain` directory. ```bash cd web/www/blockchain/ ``` - Open the `config.json` file, and update the caName with the URL of the <b>insurance</b> certificate authority from your `ibpConnection.json` file. Save the file. - Run the `enrollAdmin.js` script ```bash node enrollAdmin.js ``` - You should see the following in the terminal: ```bash msg: Successfully enrolled admin user insuranceApp-admin and imported it into the wallet ``` <p align="center"> <img src="images/gifs/enrollAdmin.gif"> </p> * 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): ```js { "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. <p align="center"> <img src="images/gifs/enrollShopAdmin.gif"> </p> <br> - Run the `enrollAdmin.js` script ```bash node enrollAdmin.js ``` - You should see the following in the terminal: ```bash 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): ```js { "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 ```bash node enrollAdmin.js ``` - You should see the following in the terminal: ```bash 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): ```js { "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 ```bash node enrollAdmin.js ``` - You should see the following in the terminal: ```bash 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](https://github.com/IBM/build-blockchain-insurance-app/blob/ubuntu/local-fix/web/www/blockchain/config.js): ```bash cd build-blockchain-insurance-app/web/www/blockchain/ ``` In the editor of choice, change [line 8](https://github.com/IBM/build-blockchain-insurance-app/blob/ubuntu/local-fix/web/www/blockchain/config.js#L8) of the `config.js` file to `isCloud: true` as shown in the image below: ![Is Cloud](images/isCloud.png) If you are using Mac, save the changes. Otherwise, if you are using an Ubuntu system, change [line 9](https://github.com/IBM/build-blockchain-insurance-app/blob/ubuntu/local-fix/web/www/blockchain/config.js#L9) of `config.js` file to `isUbuntu: true` as shown in the image below: ![Is Ubuntu](images/isUbuntuAndCloud.png) Next, from the `blockchain` directory navigate to the root project directory: ```bash blockchain$ cd ../../../ build-blockchain-insurance-app$ ``` Login using your [docker hub](https://hub.docker.com/) credentials. ```bash 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: ```bash cd build-blockchain-insurance-app ./build_mac.sh ``` For Ubuntu user **Make sure isUbuntu:true is saved in the [line 9](https://github.com/IBM/build-blockchain-insurance-app/blob/ubuntu/local-fix/web/www/blockchain/config.js#L9) of `config.js`**: ```bash 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: ```bash 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. ![Blockchain Insurance](images/home.png) 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. ![Customer Shopping](images/Picture1.png) 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. ![Shopping](images/Picture2.png) 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. ![Bike Shop](images/Picture3.png) 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. ![Bike Insurance](images/Picture4.png) 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](./README-local.md). 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: * [Fundamentals of IBM Blockchain](https://www.ibm.com/blockchain/what-is-blockchain) * [Hyperledger Fabric Documentation](https://hyperledger-fabric.readthedocs.io/) * [Hyperledger Fabric code on GitHub](https://github.com/hyperledger/fabric) ## Troubleshooting * Run `clean.sh` to remove the docker images and containers for the insurance network. ```bash ./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)](https://developercertificate.org/) and the [Apache Software License, Version 2](https://www.apache.org/licenses/LICENSE-2.0.txt). [Apache Software License (ASL) FAQ](https://www.apache.org/foundation/license-faq.html#WhatDoesItMEAN)

Developer Tools Crypto & Blockchain
766 Github Stars