├── .gitignore
├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE
├── MAINTAINERS.md
├── README-ja.md
├── README.md
├── contract
├── .eslintrc.js
├── index.js
├── lib
│ └── fabcar.js
├── package-lock.json
└── package.json
├── package-lock.json
├── run-local.md
└── web-app
├── client
├── .editorconfig
├── .gitignore
├── README.md
├── angular.json
├── e2e
│ ├── protractor.conf.js
│ ├── src
│ │ ├── app.e2e-spec.ts
│ │ ├── app.po.ts
│ │ └── components
│ │ │ ├── changeCarOwnerForm.ts
│ │ │ ├── createCarForm.ts
│ │ │ └── submit.ts
│ └── tsconfig.e2e.json
├── package-lock.json
├── package.json
├── src
│ ├── app
│ │ ├── api.service.ts
│ │ ├── app.component.html
│ │ ├── app.component.scss
│ │ ├── app.component.spec.ts
│ │ ├── app.component.ts
│ │ ├── app.module.ts
│ │ ├── car.ts
│ │ ├── query-all-cars
│ │ │ ├── query-all-cars.component.html
│ │ │ ├── query-all-cars.component.scss
│ │ │ ├── query-all-cars.component.spec.ts
│ │ │ └── query-all-cars.component.ts
│ │ └── submit-component
│ │ │ ├── change-car-owner-form
│ │ │ ├── change-car-owner-form.component.html
│ │ │ ├── change-car-owner-form.component.scss
│ │ │ └── change-car-owner-form.component.ts
│ │ │ ├── create-car-form
│ │ │ ├── create-car-form.component.html
│ │ │ ├── create-car-form.component.scss
│ │ │ ├── create-car-form.component.spec.ts
│ │ │ └── create-car-form.component.ts
│ │ │ ├── submit.component.html
│ │ │ ├── submit.component.scss
│ │ │ ├── submit.component.spec.ts
│ │ │ └── submit.component.ts
│ ├── assets
│ │ └── .gitkeep
│ ├── browserslist
│ ├── colors.scss
│ ├── environments
│ │ ├── environment.prod.ts
│ │ └── environment.ts
│ ├── favicon.ico
│ ├── ibmDuocolors.scss
│ ├── index.html
│ ├── karma.conf.js
│ ├── main.ts
│ ├── polyfills.ts
│ ├── styles.css
│ ├── test.ts
│ ├── tsconfig.app.json
│ ├── tsconfig.spec.json
│ └── tslint.json
├── tsconfig.json
└── tslint.json
└── server
├── .eslintrc.js
├── config.json
├── deregisterUser.js
├── enrollAdmin.js
├── mychannel_fabcar_profile.json
├── package-lock.json
├── package.json
├── registerUser.js
└── src
├── app.js
└── fabric
└── network.js
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | **/.DS_Store
3 | node_modules/
4 | /dist
5 | wallet/
6 |
7 | # local env files
8 | .env.local
9 | .env.*.local
10 |
11 | # Log files
12 | npm-debug.log*
13 | yarn-debug.log*
14 | yarn-error.log*
15 |
16 | # Editor directories and files
17 | .idea
18 | .vscode
19 | .vscode/
20 | *.suo
21 | *.ntvs*
22 | *.njsproj
23 | *.sln
24 | *.sw*
25 |
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: node_js
2 | node_js:
3 | - "10.16.3"
4 |
5 | script:
6 | - cd contract && npm install && npm run lint && cd ../web-app/server && npm install && npm run lint && cd ../client && npm install && npm run lint
7 |
8 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | This is an open source project, and we appreciate your help!
4 |
5 | We use the GitHub issue tracker to discuss new features and non-trivial bugs.
6 |
7 | In addition to the issue tracker, [#ibmcode on
8 | Slack](https://dwopen.slack.com) is the best way to get into contact with the
9 | project's maintainers.
10 |
11 | To contribute code, documentation, or tests, please submit a pull request to
12 | the GitHub repository. Generally, we expect two maintainers to review your pull
13 | request before it is approved for merging. For more details, see the
14 | [MAINTAINERS](MAINTAINERS.md) page.
15 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/MAINTAINERS.md:
--------------------------------------------------------------------------------
1 | ## Maintainers Guide
2 |
3 | This guide is intended for maintainers — anybody with commit access to one or
4 | more Developer Journey repositories.
5 |
6 | ## Methodology:
7 |
8 | A master branch. This branch MUST be releasable at all times. Commits and
9 | merges against this branch MUST contain only bugfixes and/or security fixes.
10 | Maintenance releases are tagged against master.
11 |
12 | A develop branch. This branch contains your proposed changes.
13 |
14 | The remainder of this document details how to merge pull requests to the
15 | repositories.
16 |
17 | ## Merge approval
18 |
19 | The project maintainers use LGTM (Looks Good To Me) in comments on the code
20 | review to indicate acceptance. A change requires LGTMs from two of the members
21 | of the [eti-journey-admins](https://github.com/orgs/IBM/teams/eti-journey-admins/members)
22 | team. If the code is written by a member, the change only requires one more
23 | LGTM.
24 |
25 | ## Reviewing Pull Requests
26 |
27 | We recommend reviewing pull requests directly within GitHub. This allows a
28 | public commentary on changes, providing transparency for all users. When
29 | providing feedback be civil, courteous, and kind. Disagreement is fine, so
30 | long as the discourse is carried out politely. If we see a record of uncivil
31 | or abusive comments, we will revoke your commit privileges and invite you to
32 | leave the project.
33 |
34 | During your review, consider the following points:
35 |
36 | ### Does the change have impact?
37 |
38 | While fixing typos is nice as it adds to the overall quality of the project,
39 | merging a typo fix at a time can be a waste of effort.
40 | (Merging many typo fixes because somebody reviewed the entire component,
41 | however, is useful!) Other examples to be wary of:
42 |
43 | Changes in variable names. Ask whether or not the change will make
44 | understanding the code easier, or if it could simply a personal preference
45 | on the part of the author.
46 |
47 | Essentially: feel free to close issues that do not have impact.
48 |
49 | ### Do the changes make sense?
50 |
51 | If you do not understand what the changes are or what they accomplish,
52 | ask the author for clarification. Ask the author to add comments and/or
53 | clarify test case names to make the intentions clear.
54 |
55 | At times, such clarification will reveal that the author may not be using
56 | the code correctly, or is unaware of features that accommodate their needs.
57 | If you feel this is the case, work up a code sample that would address the
58 | issue for them, and feel free to close the issue once they confirm.
59 |
60 | ### Is this a new feature? If so:
61 |
62 | Does the issue contain narrative indicating the need for the feature? If not,
63 | ask them to provide that information. Since the issue will be linked in the
64 | changelog, this will often be a user's first introduction to it.
65 |
66 | Are new unit tests in place that test all new behaviors introduced? If not, do
67 | not merge the feature until they are!
68 | Is documentation in place for the new feature? (See the documentation
69 | guidelines). If not do not merge the feature until it is!
70 | Is the feature necessary for general use cases? Try and keep the scope of any
71 | given component narrow. If a proposed feature does not fit that scope,
72 | recommend to the user that they maintain the feature on their own, and close
73 | the request. You may also recommend that they see if the feature gains traction
74 | amongst other users, and suggest they re-submit when they can show such support.
75 |
--------------------------------------------------------------------------------
/README-ja.md:
--------------------------------------------------------------------------------
1 | [See this lab in English](./README.md)
2 |
3 |
4 | # FabCar Blockchain Sample
5 |
6 | >Hyperledger Fabric sample Fabcar on IBM Blockchain Platform
7 |
8 | このコードパターンは、IBM Blockchain Platformでネットワークを設定し、Fabcarスマートコントラクトをネットワークに展開する方法を示しています。 次に、IDを含むネットワークとやり取りしてスマートコントラクトでトランザクションを送信するようにアプリケーションをセットアップします。 アプリケーションは、Fabric Node SDKを使用してネットワークへのリクエストを処理するNode.jsサーバーと、Webインターフェースを起動するAngularクライアントでセットアップされます。
9 |
10 | このコードパターンを完了すると、次のことができるようになります:
11 |
12 | * IBM Blockchain PlatformでHyperledger Fabricネットワークをセットアップする
13 | * IBM Blockchain Platformを介してスマートコントラクトをインストールおよびインスタンス化する
14 | * Hyperledger Fabric SDKを使用してNode.jsサーバーを開発し、展開されたネットワークと対話する
15 | * WebアプリのAngularフロントエンドを作成して、ネットワークとインターフェイスする
16 |
17 | ## アプリケーション構成図
18 |
19 |
465 |
466 |
467 |
468 | ## トラブルシューティング
469 |
470 | * If you encounter an error ``discover error: access denied``, you need to set the `gatewayDiscovery` properly in your `config.json` file. This is REQUIRED You must set it as follows to connect to IBP:
471 |
472 | `"gatewayDiscovery": {"enabled": true, "asLocalhost": false }`
473 |
474 |
475 | ## リンク
476 | * [Hyperledger Fabric Docs](http://hyperledger-fabric.readthedocs.io/en/latest/)
477 | * [IBM Code Patterns for Blockchain](https://developer.ibm.com/patterns/category/blockchain/)
478 |
479 |
480 | ## ライセンス(英語)
481 |
482 | 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).
483 |
484 | [Apache Software License (ASL) FAQ](https://www.apache.org/foundation/license-faq.html#WhatDoesItMEAN)
485 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [日本語はこちら - Japanese version](./README-ja.md)
2 |
3 |
4 | [](https://travis-ci.org/IBM/fabcar-blockchain-sample)
5 |
6 |
7 | # FabCar Blockchain Sample
8 |
9 | >Hyperledger Fabric sample Fabcar on IBM Blockchain Platform
10 |
11 | > **NOTE**: This developer pattern creates a blockchain network on *IBM Blockchain Platform version **2.5*** using the *Hyperledger Fabric version **1.4***.
12 |
13 | This code pattern demonstrates setting up a network on the IBM Blockchain Platform and deploying the Fabcar smart contract on the network. Next, we setup our application to interact with the network including identities to submit transactions on the smart contract. The application is setup with a Node.js server using the Fabric Node SDK to process requests to the network, and an Angular client to bring up a web interface.
14 |
15 | When the reader has completed this code pattern, they will understand how to:
16 |
17 | * Setup a Hyperledger Fabric network on IBM Blockchain Platform
18 | * Install and instantiate smart contract through the IBM Blockchain Platform
19 | * Develop a Node.js server with the Hyperledger Fabric SDK to interact with the deployed network
20 | * Create an Angular frontend for the web app to interface with the network
21 |
22 |
23 | ## Architecture flow
24 |
25 |
26 |
27 |
28 |
29 | 1. The Blockchain Operator sets up the IBM Blockchain Platform service.
30 | 2. The IBM Blockchain Platform enables to create a Hyperledger Fabric network onto a IBM Cloud Kubernetes Service, allowing to install and instantiate the Fabcar smart contract on the network.
31 | 3. The Node.js application server uses the Fabric SDK to interact with the deployed network on IBM Blockchain Platform and creates APIs for a web client.
32 | 4. The Angular client uses the Node.js application API to interact with the network.
33 | 5. The User interacts with the Fabcar Angular web interface to update and query the blockchain ledger and state.
34 |
35 |
36 | ## Included components
37 |
38 | * [IBM Blockchain Platform](https://www.ibm.com/cloud/blockchain-platform) 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.
39 | * [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.
40 | * [IBM Blockchain Platform Extension for VS Code](https://marketplace.visualstudio.com/items?itemName=IBMBlockchain.ibm-blockchain-platform) is designed to assist users in developing, testing, and deploying smart contracts -- including connecting to Hyperledger Fabric environments.
41 |
42 |
43 | ## Featured technologies
44 |
45 | + [Hyperledger Fabric v1.4](https://hyperledger-fabric.readthedocs.io/en/release-1.4/) is a platform for distributed ledger solutions, underpinned by a modular architecture that delivers high degrees of confidentiality, resiliency, flexibility, and scalability.
46 | + [Node.js](https://nodejs.org/en/) is an open source, cross-platform JavaScript run-time environment that executes server-side JavaScript code.
47 | + [Express.js](https://expressjs.com/) is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications.
48 | + [Angular.io](https://angular.io/) is a front-end framework for building web applications.
49 |
50 |
51 | ## Prerequisites
52 |
53 | - [IBM Cloud account](https://cloud.ibm.com/registration/?target=%2Fdashboard%2Fapps)
54 | - [Node v10.x and npm v6.x or greater](https://nodejs.org/en/download/)
55 | - [VSCode version 1.38.0 or greater](https://code.visualstudio.com)
56 | - [IBM Blockchain Platform Extension for VSCode](https://marketplace.visualstudio.com/items?itemName=IBMBlockchain.ibm-blockchain-platform)
57 |
58 |
59 | ## Running the application
60 |
61 | Follow these steps to set up and run this code pattern. The steps are described in detail below.
62 |
63 |
64 | ## Steps
65 |
66 | > To run a local network, you can find steps [here](./run-local.md)
67 |
68 | 1. [Clone the repo](#1-clone-the-repo)
69 | 2. [Package the smart contract](#2-package-the-smart-contract)
70 | 3. [Create IBM Cloud services](#3-create-ibm-cloud-services)
71 | 4. [Build a network](#4-build-a-network)
72 | 5. [Deploy FabCar Smart Contract on the network](#5-deploy-fabcar-smart-contract-on-the-network)
73 | 6. [Connect application to the network](#6-connect-application-to-the-network)
74 | 7. [Run the application](#7-run-the-application)
75 |
76 |
77 | ### 1. Clone the repo
78 |
79 | Clone this repository in a folder your choice:
80 |
81 | ```bash
82 | git clone https://github.com/IBM/fabcar-blockchain-sample.git
83 | cd fabcar-blockchain-sample
84 | ```
85 |
86 | ### 2. Package the smart contract
87 |
88 | We will use the IBM Blockchain Platform extension on VS Code to package the Fabcar smart contract.
89 |
90 | * Open Visual Studio code and open the `contract` folder from `fabcar-blockchain-sample` repository that was cloned earlier.
91 | **It is important that you are opening the `contract` folder and not the entire `fabcar-blockchain-sample` directory; otherwise you will see an error that states that it doesn't understand what programming language you are using.**
92 |
93 | * Press the `F1` key to see the different VS code options. Choose `IBM Blockchain Platform: Package Open Project`.
94 |
95 |
96 |
97 |
98 |
99 | * Click the `IBM Blockchain Platform` extension button on the left. This will show the packaged contracts on top and the blockchain connections on the bottom.
100 |
101 |
102 |
103 |
104 |
105 | * Next, right click on the packaged contract (in this case, select fabcar@1.0.0) to export it and choose `Export Package`.
106 |
107 | * Choose a location on your machine and save the `.cds` file. We will use this packaged smart contract later to deploy on the IBM Blockchain Platform service.
108 |
109 | Now, we will start setting up the different services required for configuring our Hyperledger Fabric network on the IBM Cloud and for running our application using this network.
110 |
111 |
112 | ### 3. Create IBM Cloud services
113 |
114 | * Create the [IBM Cloud Kubernetes Service](https://cloud.ibm.com/kubernetes/catalog/cluster). You can find the service in the `Catalog`. For this code pattern, we can use the `Free` cluster, and give it a name. Note, that the IBM Cloud allows one instance of a free cluster which expires after 30 days. **Note: it could take 20 minutes for the IBM Cloud Kubernetes Service setup to complete**.
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 | * Create the [IBM Blockchain Platform](https://cloud.ibm.com/catalog/services/blockchain-platform) service on the IBM Cloud. You can find the service in the `Catalog`, and give it a name.
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 | * After your kubernetes cluster is up and running, you can deploy your IBM Blockchain Platform on the cluster. Again - wait for the IBM Cloud Kubernetes service to indicate it was deployed. The IBM Blockchain Platform service walks through few steps and finds your cluster on the IBM Cloud to deploy the service on.
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 | * Once the Blockchain Platform is deployed on the Kubernetes cluster, you can launch the console to start configuring your blockchain network.
139 |
140 |
141 | ### 4. Build a network
142 |
143 | We will build a network as provided by the IBM Blockchain Platform [documentation](https://cloud.ibm.com/docs/services/blockchain/howto?topic=blockchain-ibp-console-build-network#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.
144 |
145 |
146 | #### Create your peer organization CA
147 | - Navigate to the Nodes tab in the left navigation and click Add Certificate Authority +.
148 | - Click Create a Certificate Authority + and click Next.
149 | - Give it a CA display name of `Org1 CA`, a CA administrator enroll ID of `admin` and a CA administrator enroll secret of `adminpw`, then click Next.
150 | - Review the summary and click Add Certificate Authority.
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 | #### Associate the peer organization CA admin identity
160 | - In the Nodes tab, select the Org1 CA once it is running (indicated by the green box in the tile).
161 | - Click Associate identity on the CA overview panel.
162 | - On the side panel, select the Enroll ID tab.
163 | - Provide an Enroll ID of `admin` and an Enroll secret of `adminpw`. Use the default value of `Org1 CA Admin` for the Identity display name.
164 | - Click Associate identity to associate the `admin` identity with the Org1 CA.
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 | #### Use peer organization CA to register the peer and org1 admin identities
174 | - Select the Org1 CA Certificate Authority and ensure the `admin` identity that was created for the CA is visible in the table.
175 | - The next step is to register an admin for the organization "Org1". Click on the Register User + button. Give an Enroll ID of `org1admin` and an Enroll secret of `org1adminpw`. Set the Type for this identity as `admin`. Specify to Use root affiliation. Leave the Maximum enrollments field blank. Click Next.
176 | - Skip the section to add attributes to this user and click Register user.
177 | - Repeat the process to create an identity of the peer. Click on the Register User + button. Give an Enroll ID of `peer1` and an Enroll secret of `peer1pw`. Set the Type for this identity as `peer`. Specify to Use root affiliation. Leave the Maximum enrollments field blank. Click Next.
178 | - Skip the section to add attributes to this user and click Register user.
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 | #### Create the peer organization MSP definition
188 | - Navigate to the Organizations tab in the left navigation and click Create MSP definition +.
189 | - Enter the MSP display name as `Org1MSP` and the MSP ID as `Org1MSP`. Click Next.
190 | - Specify `Org1 CA` as the Root Certificate Authority. Click Next.
191 | - Select the New identity tab. Give the Enroll ID and Enroll secret for your organization admin, i.e. `org1admin` and `org1adminpw` respectively. Then, give the Identity name as `Org1 Admin`.
192 | - Click the Generate button to enroll this identity as the admin of your organization and add the identity to the wallet. Click Export to export the admin certificates to your file system. Click Next.
193 | - Review all the information and click Create MSP definition.
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 | #### Create a peer
203 | - Navigate to the Nodes tab in the left navigation and click Add peer +.
204 | - Click Create a peer + and then click Next.
205 | - Give the Peer display name as `Peer Org1` and click Next.
206 | - On the next screen, select `Org1 CA` as the Certificate Authority. Then, give the Peer enroll ID and Peer enroll secret as `peer1` and `peer1pw` respectively. Select the Organization MSP as `Org1MSP`. Leave the TLS CSR hostname blank and select the highest value available in the drop-down for Fabric version, i.e. `2.1.1-0`. Click Next.
207 | - Provide `Org1 Admin` as the Peer administrator identity and click Next.
208 | - Review the summary and click Add peer.
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 | #### Create your orderer organization CA
218 | - Navigate to the Nodes tab in the left navigation and click Add Certificate Authority +.
219 | - Click Create a Certificate Authority + and click Next.
220 | - Give it a CA display name of `Orderer CA`, a CA administrator enroll ID of `admin` and a CA administrator enroll secret of `adminpw`, then click Next.
221 | - Review the summary and click Add Certificate Authority.
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 | #### Associate the orderer organization CA admin identity
231 | - In the Nodes tab, select the Orderer CA once it is running (indicated by the green box in the tile).
232 | - Click Associate identity on the CA overview panel.
233 | - On the side panel, select the Enroll ID tab.
234 | - Provide an Enroll ID of `admin` and an Enroll secret of `adminpw`. Use the default value of `Orderer CA Admin` for the Identity display name.
235 | - Click Associate identity to associate the `admin` identity with the Orderer CA.
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 | #### Use orderer organization CA to register orderer and orderer admin identities
245 | - Select the Orderer CA Certificate Authority and ensure the `admin` identity that was created for the CA is visible in the table.
246 | - The next step is to register an admin for the organization "Orderer". Click on the Register User + button. Give an Enroll ID of `ordereradmin` and an Enroll secret of `ordereradminpw`. Set the Type for this identity as `admin`. Specify to Use root affiliation. Leave the Maximum enrollments field blank. Click Next.
247 | - Skip the section to add attributes to this user and click Register user.
248 | - Repeat the process to create an identity of the orderer. Click on the Register User + button. Give an Enroll ID of `orderer` and an Enroll secret of `ordererpw`. Set the Type for this identity as `orderer`. Specify to Use root affiliation. Leave the Maximum enrollments field blank. Click Next.
249 | - Skip the section to add attributes to this user and click Register user.
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 | #### Create the orderer organization MSP definition
259 | - Navigate to the Organizations tab in the left navigation and click Create MSP definition +.
260 | - Enter the MSP display name as `OrdererMSP` and the MSP ID as `OrdererMSP`. Click Next.
261 | - Specify `Orderer CA` as the Root Certificate Authority. Click Next.
262 | - Select the New identity tab. Give the Enroll ID and Enroll secret for your organization admin, i.e. `ordereradmin` and `ordereradminpw` respectively. Then, give the Identity name as `Orderer Admin`.
263 | - Click the Generate button to enroll this identity as the admin of your organization and add the identity to the wallet. Click Export to export the admin certificates to your file system. Click Next.
264 | - Review all the information and click Create MSP definition.
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 | #### Create an orderer
275 | - Navigate to the Nodes tab in the left navigation and click Add ordering service +.
276 | - Click Create an ordering service + and then click Next.
277 | - Give the Ordering service display name as `Orderer` and click Next.
278 | - On the next screen, select `Orderer CA` as the Certificate Authority. Then, give the Ordering service enroll ID and Ordering service enroll secret as `orderer` and `ordererpw` respectively. Select the Organization MSP as `OrdererMSP`. Leave the TLS CSR hostname blank and select the highest value available in the drop-down for Fabric version, i.e. `2.1.1-0`. Click Next.
279 | - Provide `Orderer Admin` as the Orderer administrator identity and click Next.
280 | - Review the summary and click Add ordering service.
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 | #### Add organization as Consortium Member on the orderer to transact
291 | - Navigate to the Nodes tab, and click on the Orderer that was created.
292 | - Under Consortium Members, click Add organization +.
293 | - Select the Existing MSP ID tab. From the drop-down list, select `Org1MSP (Org1MSP)`, as this is the MSP that represents the peer's organization "Org1".
294 | - Click Add organization.
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 | #### Create the channel
304 | - Navigate to the Channels tab in the left navigation and click Create channel +.
305 | - Click Next.
306 | - Give the Channel name as `mychannel`. Select `Orderer` from the Ordering service drop-down list. Click Next.
307 | - Under Organizations, select `Org1MSP (Org1MSP)` from the drop-down list to add the organization "Org1" as a member of this channel. Click the Add button. Set the permissions for this member as Operator. Click Next.
308 | - Leave the Policy as the default value i.e. `1 out of 1`. Click Next.
309 | - Select the Channel creator MSP as `Org1MSP (Org1MSP)` and the Identity as `Org1 Admin`. Click Next.
310 | - Review the summary and click Create channel.
311 |
312 |
313 |
314 |
315 |
316 |
317 |
318 |
319 | #### Join your peer to the channel
320 | - Click on the newly created channel mychannel.
321 | - In the side panel that opens, under Choose from available peers, select `Peer Org1`. Once the peer is selected, a check mark will be displayed next to it. Ensure that Make anchor peer(s) is marked as `Yes`. Click Join channel.
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 | ### 5. Deploy FabCar Smart Contract on the network
331 |
332 | #### Install a smart contract
333 | - Navigate to the Smart contracts tab in the left navigation and click Install smart contract +.
334 | - Click on Add file.
335 | - Browse to the location of the Fabcar smart contract package file (it is probably named `fabcar@1.0.0.cds`), which we packaged earlier using the IBM Blockchain Platform extension for Visual Studio code.
336 | - Once the contract is uploaded, click Install smart contract.
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 | #### Instantiate smart contract
346 | - Under Installed smart contracts, find the smart contract from the list (**Note: ours is called fabcar**) installed on our peer and click Instantiate from the overflow menu on the right side of the row.
347 | - On the side panel that opens, select the channel, `mychannel` on which to instantiate the smart contract. Click Next.
348 | - Select `Org1MSP` as the organization member to be included in the endorsement policy. Click Next.
349 | - Skip the Setup private data collection step and simply click Next.
350 | - Provide the Function name as `initLedger` and leave the Arguments blank.
351 | - Click Instantiate smart contract.
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 | ### 6. Connect application to the network
361 |
362 | #### Connect with sdk through connection profile
363 | - Navigate to the Organizations tab in the left navigation, and click on Org1MSP.
364 | - Click on Download Connection Profile.
365 | - In the side panel that opens up, select `Yes` as the response for Include Org1 CA for user registration and enrollment?. Under Select peers to include, select `Peer Org1`. Then click Download connection profile. This will download the connection json which we will use to establish a connection between the Node.js web application and the Blockchain Network.
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 | #### Create an application admin
375 | - Navigate to the Nodes tab in the left navigation, and under Certificate Authorities, choose Org1 CA.
376 | - Click on the Register User + button. Give an Enroll ID of `app-admin` and an Enroll secret of `app-adminpw`. Set the Type for this identity as `client`. Specify to Use root affiliation. Leave the Maximum enrollments field blank. Click Next.
377 | - Click on Add attribute +. Enter the attribute name as `hf.Registrar.Roles` and the attribute value as `*`. **NOTE: If you wish to use the deregisterUser.js script to remove/revoke/delete existing users, then you need to add another attribute `hf.Revoker` with the attribute value of `true` to your application admin.**
378 | - Click Register user.
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 | #### Update application connection profile
388 |
389 | - Copy the connection profile you downloaded into the [server folder](web-app/server).
390 | - Update the [config.json](web-app/server/config.json) file with:
391 | - The connection json file name you downloaded.
392 | - The enroll id and enroll secret for your app admin, which we earlier provided as `app-admin` and `app-adminpw` respectively.
393 | - The orgMSP ID, which we provided as `Org1MSP`.
394 | - The caName, which can be found in your connection json file under "organizations" -> "Org1MSP" -> certificateAuthorities". This would be like an IP address and a port.
395 | - The username you would like to register.
396 | - Update gateway discovery to `{ enabled: true, asLocalhost: false }` to connect to IBM Blockchain Platform.
397 |
398 | > the current default contents of the config.json are to connect to a local fabric instance from VS Code.
399 |
400 | After the updates, the contents of the config.json should look similar to the file shown below:
401 | ```
402 | {
403 | "connection_file": "Org1MSP_profile.json",
404 | "appAdmin": "app-admin",
405 | "appAdminSecret": "app-adminpw",
406 | "orgMSPID": "Org1MSP",
407 | "caName": "169.46.208.151:30404",
408 | "userName": "user1",
409 | "gatewayDiscovery": { "enabled": true, "asLocalhost": false }
410 | }
411 | ```
412 |
413 |
414 | ### 7. Run the application
415 |
416 | #### Enroll admin
417 |
418 | - First, navigate to the `web-app/server` directory, and install the node dependencies:
419 |
420 | ```bash
421 | cd web-app/server
422 | npm install
423 | ```
424 |
425 | - Run the `enrollAdmin.js` script:
426 |
427 | ```bash
428 | node enrollAdmin.js
429 | ```
430 |
431 | - You should see the following in the terminal:
432 |
433 | ```bash
434 | msg: Successfully enrolled admin user app-admin and imported it into the wallet
435 | ```
436 |
437 |
438 | #### Register User
439 |
440 | - From the `server` directory, run the `registerUser.js` script:
441 |
442 | ```bash
443 | node registerUser.js
444 | ```
445 |
446 | - You should see the following in the terminal:
447 |
448 | ```bash
449 | Successfully registered and enrolled admin user user1 and imported it into the wallet
450 | ```
451 |
452 | #### Deregister User
453 |
454 | **NOTE: The following steps need to be performed only if you wish to revoke an existing user.**
455 |
456 | By default, removal of identities is disabled in IBM Blockchain Platform. If you wish to remove identities, you need to manually override this default setting in the IBM Blockchain Platform console.
457 |
458 | - On the console, go to the `Nodes` tab using the left hand navigation pane and click on your organization's CA.
459 | - Click on the settings icon in the left side.
460 | - In the pane that opens up on the right side, click on `Edit configuration JSON (Advanced)`.
461 | - Paste the following into the input block for `Configuration updates`, then click `Update Certificate Authority`.
462 | **NOTE: The value of 10 for passwordattempts is the default value. If your certificate authority was set up with a different number for passwordattempts then you need to use that number. You can find this value from the `Current configuration` section which is just above the `Configuration updates` section.**
463 |
464 | ```json
465 | {
466 | "ca": {
467 | "cfg": {
468 | "identities": {
469 | "passwordattempts": 10,
470 | "allowremove": true
471 | }
472 | }
473 | }
474 | }
475 | ```
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 | The removal of identities will now be enabled. As long as your application admin has been created with the `hf.Revoker` attribute set to the value of `true` (as specified in the [Create an application admin](#-create-an-application-admin) step above, you can use the `deregisterUser.js` script to remove the user identity.
485 |
486 | - From the `server` directory, run the `deregisterUser.js` script. This script removes/revokes the user identified by `userName` specified in the [config.json](web-app/server/config.json) file.
487 |
488 | ```bash
489 | node deregisterUser.js
490 | ```
491 |
492 | - You should see the following in the terminal:
493 |
494 | ```bash
495 | Successfully deregistered the user user1 and deleted it from the wallet.
496 | ```
497 |
498 |
499 | #### Start the application server
500 |
501 | - From the `server` directory, start the server:
502 |
503 | ```bash
504 | npm start
505 | ```
506 |
507 |
508 | #### Start the web client
509 |
510 | - In a new terminal, open the `web-app/client` directory and install the dependencies:
511 |
512 | ```bash
513 | cd web-app/client
514 | npm install
515 | ```
516 |
517 | - Start the client:
518 |
519 | ```bash
520 | npm start
521 | ```
522 |
523 | You can find the app running at http://localhost:4200/
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 | You can go to the IBM Blockchain Platform console to monitor your users and get information on your channel including the blocks added.
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 | ## Troubleshooting
541 |
542 | * If you encounter an error ``discover error: access denied``, you need to set the `gatewayDiscovery` properly in your `config.json` file. This is REQUIRED You must set it as follows to connect to IBP:
543 |
544 | `"gatewayDiscovery": {"enabled": true, "asLocalhost": false }`
545 |
546 | * When running the *registerUser.js* script, if you get an error that says `Failed to register user user1: TypeError [ERR_INVALID_ARG_TYPE]: The "options.ca" property must be one of type string, Buffer, TypedArray, or DataView. Received type object` , you can get past this error by editing your connection profile that was downloaded from IBM Blockchain Platform. Open the connection profile and look for `tlsCACerts` under your certificateAuthority. If the `pem` value under `tlsCACerts` is of type array, remove the square brackets `[]` and convert it to a string. That is, if your connection profile is like the following image:
547 |
548 |
549 |
550 |
551 |
552 | update it as shown in the image below:
553 |
554 |
555 |
556 |
557 |
558 | * When running the *registerUser.js* script, if you get an error that says `Error: Calling register endpoint failed with error [Error: self signed certificate]`, you can get past this by adding `"httpOptions": {"verify": false}` to the certificateAuthorities section of the connection profile that was downloaded from IBM Blockchain Platform.
559 |
560 |
561 |
47 |
48 | Click the `IBM Blockchain Platform` extension button on the left. This will show the packaged contracts on top and the blockchain connections on the bottom.
49 |
50 |
51 |
52 |
53 |
54 | * Next, if you want to, you can export the package to a location on your machine. However, exporting the packaged smart contract is not required for installing the smart contract on the local network.
55 |
56 | * Right click on the packaged contract (in this case, select fabcar@1.0.0) to export it and choose `Export Package`. Choose a location on your machine and save the `.cds` file.
57 |
58 |
59 | ### Setup fabric locally
60 |
61 | You should see `FABRIC ENVIRONMENTS` on the left side of the editor. Under this section, you should see `1 Org Local Fabric`. Click it to start the Local Fabric.
62 |
63 |
64 |
65 |
66 |
67 | The extension will now provision the Docker containers that will act as nodes in your network. Once the provisioning is finished and the network is up and running, you will see the options to install and instantiate the smart contract, the `Channels` information, the `Nodes` and the organization msps under `Organizations`. You are now ready to install the smart contract.
68 |
69 |
70 |
71 |
72 |
73 |
74 | ### Install and instantiate the smart contract
75 |
76 | #### Install
77 |
78 | * In the `FABRIC ENVIRONMENTS` section near the bottom, click on `Smart Contracts` > `Installed` > `+ Install`. You will see a pop-up similar to the graphic below.
79 |
80 |
81 |
82 |
83 |
84 | * Then select the packaged contract: `fabcar@1.0.0 Packaged` **Note** The 1.0.0 comes from your `package.json` line: `"version": "1.0.0"`
85 |
86 | After the install is complete, you should get a message `Successfully installed on peer peer0.org1.example.com`. You should also see that the contract is listed under `Installed` under `FABRIC ENVIRONMENTS`.
87 |
88 |
89 |
90 |
91 |
92 |
93 | #### Instantiate
94 |
95 | * Under **Smart Contracts** you will see a section that says **Instantiated**. Click on `+ Instantiate` under it.
96 |
97 | * The extension will then ask you which contract and version to instantiate — choose `fabcar@1.0.0 Installed`.
98 |
99 |
100 |
101 |
102 |
103 | * The extension will then ask you which function to call on instantiate — type in `initLedger`
104 |
105 |
106 |
107 |
108 |
109 | * Next, it will ask you for the arguments to the function. There are none, so just hit enter.
110 |
111 |
112 |
113 |
114 |
115 | * Next, the extension will then ask you do you want to use a provide a private data collection configuration file? - Click on `No`.
116 |
117 |
118 |
119 |
120 |
121 | * Lastly, the extension will then ask you do you want to choose a smart contract endorsement policy. Choose `Default (single endorser, any org)`.
122 |
123 |
124 |
125 |
126 |
127 | Once instantiation of the contract completes, you should get the message `Successfully instantiated smart contract` and you should see `fabcar@1.0.0` under `Instantiated` under `FABRIC ENVIRONMENTS`.
128 |
129 |
130 |
131 |
132 |
133 |
134 | ### Add app-admin identity on CA Node
135 |
136 | We will now create the app-admin identity using the CA (Certificate Authority) node. The identity information and key files are needed in order to authenticate and run the application.
137 |
138 | Under `FABRIC ENVIRONMENTS` section in the left hand pane, expand `Nodes` and right click on `Org1 CA`. Choose `Create Identity (register and enroll)`.
139 |
140 |
141 |
142 |
143 |
144 | Type `app-admin` and press the enter key.
145 |
146 |
147 |
148 |
149 |
150 | The extension will then ask if you want to add any attributes to this identity. Click on `Yes`.
151 |
152 |
153 |
154 |
155 |
156 | The extension will then ask you to provide the attributes for this identity. Enter `[{"name":"hf.Registrar.Roles","value":"*","ecert":true}]`.
157 |
158 |
159 |
160 |
161 |
162 | Once the identity is successfully created, you should get the message `Successfully created identity 'app-admin' with the attributes: [{"name":"hf.Registrar.Roles","value":"*","ecert":true}]`. You can now see `app-admin` in the `FABRIC WALLETS` section under `1 Org Local Fabric` > `Org1`.
163 |
164 |
165 |
166 |
167 |
168 |
169 | ### Export Wallet
170 |
171 | Under `FABRIC WALLETS` in the left hand pane, expand `1 Org Local Fabric`, and under it right click on `Org1` and select `Export Wallet`.
172 |
173 |
174 |
175 |
176 |
177 | You can save the exported files anywhere.
178 |
179 | From the exported directory, copy the contents of the `app-admin` folder to the following location in the directory where you have cloned this repo:
180 |
181 | ```
182 | /fabcar-blockchain-sample/web-app/server/wallet/app-admin
183 | ```
184 |
185 |
186 |
187 |
188 |
189 |
190 | ### Save the connection profile and update the config file
191 |
192 | The next step is to obtain the connection profile for `Org1`. Under `FABRIC GATEWAYS` in the left-hand pane, expand `1 Org Local Fabric` and right click on `Org1`. Select `Export Connection Profile`. Save the file to the following location in the directory where you have cloned this repo:
193 |
194 | ```
195 | /fabcar-blockchain-sample/web-app/server
196 | ```
197 |
198 |
199 |
200 |
201 |
202 | Next, open the [config.json](./web-app/server/config.json) file. We need to update this file to indicate that we want to run the application locally.
203 |
204 | - Specify the "connection_file" as the name of the connection profile file which was downloaded earlier. Unless you specified a different name when saving the file, it should probably be named `1 Org Local Fabric - Org1_connection.json`.
205 | - The value for "caName" can be obtained from the connection profile file. Open the connection profile and look for the certificateAuthorities section. Obtain the caName from the line just below it. It should probably be `Org1CA`.
206 | - Update gateway discovery to `{ enabled: true, asLocalhost: true }` to connect to the local fabric network.
207 |
208 | After these updates, the config.json file should look similar to the file shown below:
209 |
210 | ```
211 | {
212 | "connection_file": "1 Org Local Fabric - Org1_connection.json",
213 | "appAdmin": "app-admin",
214 | "appAdminSecret": "app-adminpw",
215 | "orgMSPID": "Org1MSP",
216 | "caName": "Org1CA",
217 | "userName": "user1",
218 | "gatewayDiscovery": { "enabled": true, "asLocalhost": true }
219 | }
220 | ```
221 |
222 | Almost done, you can run the application.
223 |
224 |
225 | ### 3. Run the application
226 |
227 |
228 | #### Register User
229 |
230 | - Run the `registerUser.js` script.
231 |
232 | ```bash
233 | node registerUser.js
234 | ```
235 |
236 | - You should see the following in the terminal:
237 |
238 | ```bash
239 | Successfully registered and enrolled the user user1 and imported it into the wallet
240 | ```
241 |
242 |
243 | #### Run the application server
244 |
245 | - From the `server` directory, start the server.
246 |
247 | ```bash
248 | npm start
249 | ```
250 |
251 |
252 | #### Start the web client
253 |
254 | - In a new terminal, open the web client folder and install the dependencies.
255 |
256 | ```bash
257 | cd web-app/client
258 | npm install
259 | ```
260 |
261 | - Start the client:
262 |
263 | ```bash
264 | npm start
265 | ```
266 |
267 | You can find the app running at http://localhost:4200/
268 |
269 |
270 |