本文Step by Step 搭建一个由IBM提供的基于Fabric的钻石交易展示平台。
本文环境是
ubuntu 16.04 4.4.0-104-generic Docker version 17.03.0-ce, build 60ccb22 docker-compose version 1.14.0, build c7bdf9e |
0.设置本地环境
0.1 安装git
省略
0.2 安装Go
下载Go for linux
https://studygolang.com/dl/golang/go1.10.linux-amd64.tar.gz
$ sudo tar -C /usr/local -xzf /your-download-path/go1.10.linux-amd64.tar.gz |
修改.bashrc 添加
export PATH=$PATH:/usr/local/go/bin
执行~/.bashrc
$ source ~/.bashrc |
验证安装结果
$ go version |
0.3 安装Node.js
Download and install Node.js v6.2.0
https://nodejs.org/dist/v6.9.5/node-v6.9.5-linux-x64.tar.gz
安装
$ sudo tar -C /usr/local -xzf /your-download-pathnode-v6.9.5-linux-x64.tar.gz |
修改.bashrc 添加
export PATH=$PATH:/usr/local/node-v6.9.5-linux-x64/bin
执行~/.bashrc
$ source ~/.bashrc |
验证安装结果
$ node -v $ npm -v |
1、下载钻石交易应用
$ git clone https://github.com/IBM-Blockchain/marbles.git --depth 1 $ cd marbles/ $ git checkout master |
2、创建区块链网络
2.1 下载Fabric Sample
$ git clone https://github.com/hyperledger/fabric-samples.git $ cd fabric-samples $ git checkout v1.1.0 $ curl -sSL https://raw.githubusercontent.com/hyperledger/fabric/master/scripts/bootstrap.sh -o setup_script.sh |
2.2 修改setup_script.sh
export VERSION=${1:-1.1.0} export THIRDPARTY_IMAGE_VERSION=1.0.6 |
2.3 运行setup_script.sh下载平台相关的二进制文件和images
sudo bash setup_script.sh |
2.4 为下载的image建立latest tag
docker tag hyperledger/fabric-tools:x86_64-1.1.0 hyperledger/fabric-tools:latest docker tag hyperledger/fabric-orderer:x86_64-1.1.0 hyperledger/fabric-orderer:latest docker tag hyperledger/fabric-peer:x86_64-1.1.0 hyperledger/fabric-peer:latest docker tag hyperledger/fabric-javaenv:x86_64-1.1.0 hyperledger/fabric-javaenv:latest docker tag hyperledger/fabric-ccenv:x86_64-1.1.0 hyperledger/fabric-ccenv:latest docker tag hyperledger/fabric-couchdb:x86_64-1.0.6 hyperledger/fabric-couchdb:latest docker tag hyperledger/fabric-kafka:x86_64-1.0.6 hyperledger/fabric-kafka:latest docker tag hyperledger/fabric-zookeeper:x86_64-1.0.6 hyperledger/fabric-zookeeper:latest |
2.5 编辑.bashrc把下载的二进制文件加入PATH环境变量
export PATH=$PWD/bin:$PATH
2.6 执行.bashrc
$ source ~/.bashrc |
2.7 启动网络
$ cd ./fabcar $ ./startFabric.sh |
2.8 检查网络,执行docker ps 应该有红框内的5个containers.
2.9 安装测试所需的软件
$ npm install |
2.10 用Fabcar测试网络
node enrollAdmin.js node registerUser.js node query.js |
3.安装并实例化链代码
3.1 安装
$ cd /YOUR_PATH/marbles/ $ npm install |
3.2 再次执行下面脚本去创建证书
$ cd /YOUR_FABRIC_SAMPLE_PATH/fabcar $ node enrollAdmin.js $ node registerUser.js$ node query.js |
3.3 修改marbles/config/connection_profile_local.json
"credentialStore": { "path": "/YOUR_FABRIC_SAMPLE_PATH/fabcar/hfc-key-store" } "x-adminCert": { "path": "/YOUR_FABRIC_SAMPLE_PATH/basic-network/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/admincerts/[email protected]" }, "x-adminKeyStore": { "path": "/YOUR_FABRIC_SAMPLE_PATH/basic-network/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/" } |
3.4 安装链码
$ ./scripts $ node install_chaincode.js |
3.5 实例化链码
$ node instantiate_chaincode.js |
4. 托管 Marbles
$ cd .. $ sudo npm install gulp -g |
BTW: 解决“sudo: npm:找不到命令”问题
$ sudo ln -s /usr/local/node-v6.9.5-linux-x64/bin/node /usr/bin/node
$ sudo ln -s /usr/local/node-v6.9.5-linux-x64/lib/node /usr/lib/node
$ sudo ln -s /usr/local/node-v6.9.5-linux-x64/lib/npm /usr/lib/npm
$ npm install |
4.5 运行钻石交易应用
$ gulp marbles_local |
BTW:if you run into the issue like
error: [Client.js]: Failed to load user "admin" from local key value store. Error: TypeError: privateKey.isPublic is not a function
at _cryptoSuite.importKey.then.then (/home/yan/workspace/marbles/node_modules/fabric-client/lib/User.js:255:45)
error: [Client.js]: Failed to load an instance of requested user "admin" from the state store on this Client instance. Error: TypeError: privateKey.isPublic is not a function
at _cryptoSuite.importKey.then.then (/home/yan/workspace/marbles/node_modules/fabric-client/lib/User.js:255:45)
error: [fcw] Failed to get enrollment marblesDockerComposeNetworkmychannelOrg1MSPfabricpeerorg1 TypeError: privateKey.isPublic is not a function
at _cryptoSuite.importKey.then.then (/home/yan/workspace/marbles/node_modules/fabric-client/lib/User.js:255:45)
error: [fcw] could not format error
error: Exhausted all CAs. There are no more CAs to try.
error: could not enroll...
warn: Error enrolling admin
you may need copy hfc-key-store directory to your home directory $HOME/.hfc-key-store, and re-config the client.credentialStore.path of connection_profile_local.json
5 使用 Marbles
5.1 访问http://localhost:3001/login
5.2 点击Login 设置应用
点击Guided
点击next step
点击next step
点击next step
点击 create
点击next step
点击Enter
5.3 创建钻石
点击Create,查看控制台
5.4 交易钻石,拖拽Amy的蓝钻给Alice
5.5 删除钻石
5.5 故事模式
点击Settings
点击Enable然后交易钻石
未完待续......