- 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ù)理統(tǒng)計(jì)
- 數(shù)學(xué)女孩2:費(fèi)馬大定理
- 圖解博弈論
- 一個(gè)定理的誕生:我與菲爾茨獎(jiǎng)的一千個(gè)日夜
- ANSYS 18.0有限元分析基礎(chǔ)與實(shí)例教程
- Ethereum Smart Contract Development
- 數(shù)獨(dú)游戲全集
- 高等數(shù)學(xué)同步練習(xí)指導(dǎo)
- Hands-On IoT Solutions with Blockchain
- 神機(jī)妙算:一本關(guān)于算法的閑書
- 燒腦的邏輯題
- 高等數(shù)學(xué)習(xí)題全解與學(xué)習(xí)指導(dǎo)(下冊(cè))
- 模糊數(shù)學(xué)基礎(chǔ)及應(yīng)用
- 數(shù)學(xué)要素(全彩圖解 + 微課 + Python編程)
- 計(jì)算進(jìn)化史:改變數(shù)學(xué)的命運(yùn)