本文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然後交易鑽石
未完待續......