- Hyperledger Cookbook
- Xun (Brian) Wu Chuanfeng Zhang Andrew Zhang
- 324字
- 2021-06-24 14:59:43
Setting up a client project
Next, it is time for us to write client-side code to trigger our chaincode. As we discussed, when the client sends a request to the Fabric network to query or invoke the chaincode, these requests need to be authorized. In Fabric release 1.4, we can create a wallet by enrolling the user and importing the identity into the wallet. The client application can interact with a smart contract in blockchain by utilizing the fabric-ca-client and fabric-network APIs with the authorized wallet.
Let's create a Node.js app:
- Navigate to the ~/itasset/client/webapp folder, issue the npm init command, and fill up the related project information. This will create a basic node application:
ubuntu@ip-172-31-9-54:~/itasset/client/webapp$ npm init
package name: (webapp) assetmgr
version: (1.0.0)
description: hyperledger cookbook fabric
entry point: (index.js)
- Install the default npm libraries. This includes the express.js, ejs, fabric-ca-client, and fabric-network libraries, shown as follows:
npm install
npm install express -save
~/itasset/client/webapp$ npm i fabric-ca-client@1.4.0
~/itasset/client/webapp$ npm i fabric-network@1.4.0
~/itasset/client/webapp$ npm install ejs
- We need to copy three files (connection.json, enrollAdmin.js, and registerUser.js) from the fabric-samples/fabcar project to our project:
cp ~/fabric-samples/basic-network/connection.json .
cp /home/ubuntu/fabric-samples/fabcar/javascript/enrollAdmin.js .
cp /home/ubuntu/fabric-samples/fabcar/javascript/registerUser.js .
Create empty wallet folder by issue below command:
mkdir wallet
At this step, our files and folders should look as follows:

- Since we copied enrollAdmin.js and registerUser.js from the fabric-samples/fabcar folder, we also need to update the file path defined in the enrollAdmin.js and registerUser.js files. Update path.resolve() in the enrollAdmin.js and registerUser.js files, as follows:
const ccpPath = path.resolve(__dirname, 'connection.json');
The connection.js file we copied from basic-network is in the same folder as enrollAdmin.js and registerUser.js.
- Let's create a wallet to enroll the admin and the user onto our Fabric network. To do this, issue the following command:
~/itasset/client/webapp$ node enrollAdmin.js
~/itasset/client/webapp$ node registerUser.js
This will create a wallet for the admin and the users. The following screenshot shows the wallet structure for admin and user1:

- 實(shí)用運(yùn)籌學(xué):案例、方法及應(yīng)用
- 仿真模型可移植性規(guī)范及其應(yīng)用
- 線性代數(shù)
- Foundations of Blockchain
- 別說(shuō)你不懂?dāng)?shù)學(xué)
- 隨機(jī)數(shù)學(xué)及其應(yīng)用
- 數(shù)學(xué)原來(lái)可以這樣學(xué):初中篇
- 硅谷工程師爸爸的超強(qiáng)數(shù)學(xué)思維課:激發(fā)孩子的數(shù)感天賦
- 無(wú)言的宇宙
- 迷人的數(shù)學(xué)(全2冊(cè))
- 愛(ài)情數(shù)學(xué)(TED 思想的力量系列)
- 數(shù)學(xué)多大點(diǎn)事兒
- 咖啡時(shí)間聊數(shù)學(xué)
- ABAQUS 2018有限元分析從入門(mén)到精通
- 線性代數(shù)