Smart Contract 一步步走近“智能合约”
配置“智能合约”运行环境
基础配置请参考前两篇文章
Node.js(目前Fabric只支持6.9.X或更早版本)下载安装
https://nodejs.org/dist/v6.9.2/node-v6.9.2-linux-x64.tar.xz
[root@huangzhenhua tmp]# tar -xJf node-v6.9.2-linux-x64.tar.xz -C /usr/local/
设置node环境变量
[root@huangzhenhua Desktop]# vi /etc/profile
export NODE_HOME=/usr/local/node-v6.9.2-linux-x64
export PATH=$NODE_HOME/bin:$PATH
[root@huangzhenhua Desktop]# source /etc/profile
检查node配置是否成功
[root@huangzhenhua Desktop]# node -v
v6.9.2
[root@huangzhenhua Desktop]# npm -v
3.10.9
升级npm
[root@huangzhenhua Desktop]# npm install npm@3.10.10 -g
#安装g++,以便npm install初始化环境编译成功
[root@huangzhenhua Desktop]#yum install gcc-c++ libstdc++-devel
开启“智能合约”之旅
初始化客户端
[root@huangzhenhua Desktop]#cd /opt/gopath/src/github.com/hyperledger/fabric-samples/fabcar
[root@huangzhenhua fabcar]# npm install
[root@huangzhenhua fabcar]# ls
enrollAdmin.js invoke.js node_modules package.json query.js registerUser.js startFabric.sh
#新增node_modules目录
开启Fabric网络
[root@huangzhenhua fabcar]# ./startFabric.sh
# don't rewrite paths for Windows Git Bash users
export MSYS_NO_PATHCONV=1
docker-compose -f docker-compose.yml down
Removing network net_basic
WARNING: Network net_basic not found.
docker-compose -f docker-compose.yml up -d ca.example.com orderer.example.com peer0.org1.example.com couchdb
Creating orderer.example.com ... done
Creating peer0.org1.example.com ... done
Creating ca.example.com ...
Creating couchdb ...
Creating peer0.org1.example.com ...
# wait for Hyperledger Fabric to start
# incase of errors when running later commands, issue export FABRIC_START_TIMEOUT=<larger number>
export FABRIC_START_TIMEOUT=10
#echo ${FABRIC_START_TIMEOUT}
sleep ${FABRIC_START_TIMEOUT}
# Create the channel
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/etc/hyperledger/msp/users/Admin@org1.example.com/msp" peer0.org1.example.com peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/configtx/channel.tx
2018-02-09 01:57:19.575 UTC [msp] GetLocalMSP -> DEBU 001 Returning existing local MSP
2018-02-09 01:57:19.575 UTC [msp] GetDefaultSigningIdentity -> DEBU 002 Obtaining default signing identity
2018-02-09 01:57:19.613 UTC [channelCmd] InitCmdFactory -> INFO 003 Endorser and orderer connections initialized
2018-02-09 01:57:19.772 UTC [msp] GetLocalMSP -> DEBU 004 Returning existing local MSP
2018-02-09 01:57:19.773 UTC [msp] GetDefaultSigningIdentity -> DEBU 005 Obtaining default signing identity
2018-02-09 01:57:19.782 UTC [msp] GetLocalMSP -> DEBU 006 Returning existing local MSP
2018-02-09 01:57:19.782 UTC [msp] GetDefaultSigningIdentity -> DEBU 007 Obtaining default signing identity
2018-02-09 01:57:19.782 UTC [msp/identity] Sign -> DEBU 008 Sign: plaintext: 0A88060A074F7267314D535012FC052D...53616D706C65436F6E736F727469756D
2018-02-09 01:57:19.782 UTC [msp/identity] Sign -> DEBU 009 Sign: digest: 75403FC8DC482C1B3066D9C407AADB725386A3726C62C555B04DB36939776BE6
2018-02-09 01:57:19.784 UTC [msp] GetLocalMSP -> DEBU 00a Returning existing local MSP
2018-02-09 01:57:19.784 UTC [msp] GetDefaultSigningIdentity -> DEBU 00b Obtaining default signing identity
2018-02-09