Fabcar Case deployment
This tutorial is based Fabric-1.4.1
deployment
Official documentation: Click here
Ready for a good environment to initialize the virtual machine ( tutorial address )
principle
The use of fabric-node-sdk program to interact with the network Fabric
Ready to work
Chain code image and remove all the containers of the conventional run-off:
# 查看镜像
docker images
# 查看容器
docker ps -a
# 停止并移除所有容器
docker stop $(docker ps -aq) && docker rm $(docker ps -aq)
# 移除指定的镜像
docker rmi 镜像ID
Installation node and npm
# 创建目录并进入目录
mkdir -p /home/scripts && cd /home/scripts
# 下载node
wget https://nodejs.org/download/release/v8.9.4/node-v8.9.4-linux-x64.tar.gz
# 解压node
tar -zxvf node-v8.9.4-linux-x64.tar.gz
# 复制到/opt目录
mv node-v8.9.4-linux-x64 /opt
# 建立软连接
ln -s /opt/node-v8.9.4-linux-x64/bin/node /usr/local/bin/node
ln -s /opt/node-v8.9.4-linux-x64/bin/npm /usr/local/bin/npm
# 查看版本
node -v
npm -v
Set Taobao mirror
npm install -g cnpm --registry=https://registry.npm.taobao.org
npm config set registry http://registry.npm.taobao.org/
Upgrade node and npm
Note: Optional
# npm升级到最新版本,-g全局安装
cnpm install npm -g
# 已经升级了
npm -v
# 安装nodejs的版本管理模块n
cnpm install -g n
# 查看版本
n -V
# nodejs版本升级到最新,参数可换:latest/stable/lts/vx.x.x
n latest
# 安装稳定版
n stable
# 安装指定版本
n v7.10.0
# 查看已安装版本
n
# 删除指定版本
n rm 6.4.0
Cloning Fabric-sample library
# 创建工作目录并进入该目录
mkdir -p /home/scripts && cd /home/scripts
# 下载脚本
curl -sS https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh -o ./bootstrap.sh
# 赋予脚本执行权限
chmod +x ./bootstrap.sh
# 执行脚本来克隆fabric-samples库
# 镜像我们在前面的课程拉取过,这里跳过特定平台二进制文件的下载(很慢,自行通过浏览器下载,再上传到虚拟机)
./bootstrap.sh 1.4.1 1.4.1 0.4.15 -d -b
# 如果没有拉取fabric镜像的执行下面这条命令
./bootstrap.sh 1.4.1 1.4.1 0.4.15 -b
Start Network
# 进入fabcar目录
cd /home/scripts/fabric-samples/fabcar
# 启动网络、创建通道、部署合约
./startFabric.sh javascript
Installation depends
# 进入javascript目录
cd /home/scripts/fabric-samples/fabcar/javascript
# 安装依赖
npm install
Note: If the following error
npm WARN deprecated [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
npm WARN deprecated [email protected]: Legacy versions of mkdirp are no longer supported. Please update to mkdirp 1.x. (Note that the API surface has changed to use Promises in 1.x.)
> [email protected] install /home/scripts/fabric-samples/fabcar/javascript/node_modules/pkcs11js
> node-gyp rebuild
make: 进入目录“/home/scripts/fabric-samples/fabcar/javascript/node_modules/pkcs11js/build”
CXX(target) Release/obj.target/pkcs11/src/main.o
make: g++:命令未找到
make: *** [Release/obj.target/pkcs11/src/main.o] 错误 127
make: 离开目录“/home/scripts/fabric-samples/fabcar/javascript/node_modules/pkcs11js/build”
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:311:20)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Linux 3.10.0-862.el7.x86_64
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/scripts/fabric-samples/fabcar/javascript/node_modules/pkcs11js
gyp ERR! node -v v12.16.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
> [email protected] install /home/scripts/fabric-samples/fabcar/javascript/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library
node-pre-gyp WARN Using request for node-pre-gyp https download
[grpc] Success: "/home/scripts/fabric-samples/fabcar/javascript/node_modules/grpc/src/node/extension_binary/node-v72-linux-x64-glibc/grpc_node.node" is installed via remote
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/pkcs11js):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
added 507 packages from 1082 contributors in 25.868s
1 package is looking for funding
run `npm fund` for details
Install gcc
# 说明没有安装gcc的环境
yum install -y gcc-c++
Operating fabcar
# 登记管理员
node enrollAdmin.js
# 注册用户
node registerUser.js
# 执行查询
node query.js
# 执行交易
node invoke.js
# 再次执行查询
node query.js