手动部署Faribc网络
1、加密生成器
生成Peers、Orderers用于网络配置的相关证书
cryptogen generate --config=./crypto-config.yaml
2、配置交易生成器
创建4个配置工作: order的genesis block, channel的channel configuration transaction, 以及两个anchor peer transactions一个对应一个Peer组织
configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID mychannel
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID mychannel -asOrg Org2MSP
3、启动网络
docker-compose -f docker-compose-cli.yaml up -d
4、停止网络
docker-compose -f docker-compose-cli.yaml down
4、手动创建、加入channel
1、配置环境变量
进入cli容器,设置以下环境变量
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
CORE_PEER_ADDRESS=peer0.org1.example.com:7051
CORE_PEER_LOCALMSPID="Org1MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
2、创建channel
peer channel create -o orderer.example.com:7050 -c yourchannel -f ./channel-artifacts/channel.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
3、加入channel
peer channel join -b yourchannel.block
4、更新org的peer
peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
5、加入channel
peer channel join -b mychannel.block
5、安装和实例化chaincode
1、安装chaincode
peer chaincode install -n andriycc -v 1.0 -l golang -p github.com/chaincode/chaincode_example02/go/
2、在channel上实例化chaincode
peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n andriycc -l golang -v 1.0 -c '{"Args":["init","c", "250", "d","500"]}' -P "AND ('Org1MSP.member','Org2MSP.member')"
6、交易操作
如下操作全部在cli容器中操作
1、查询账户余额
peer chaincode query -C mychannel -n andriycc -c '{"Args":["query","c"]}'
2、转账操作
# c 账户转50到d 账户
peer chaincode invoke -o orderer.example.com:7050 --tls true --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n andriycc --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","c","d","50"]}'