HyperLedger(1)启动Fabric及创建channel、部署chaincode

HyperLedger

前提

git clone https://github.com/hyperledger/fabric.git

#编译configtxgen工具
cd $GOPATH/src/github.com/hyperledger/fabric
make configtxgen # 如果出错:'ltdl.h' file not found sudo apt install libtool libltdl-dev

#进入examples/e2e_cli目录,首先从Docker Hub拉取镜像:
# 使脚本可执行
chmod +x download-dockerimages.sh
# 执行脚本
./download-dockerimages.sh

启动fabric

sudo docker-compose -f docker-compose-cli.yaml up -d

本文所进入的cli,其环境依赖于peer0.org1;如果想要在该cli中对其它peer操作需要设置相应的参数:

CORE_PEER_ADDRESS

CORE_PEER_MSPCONFIGPATH

CORE_PEER_TLS_ROOTCERT_FILE

CORE_PEER_LOCALMSPID

Create channel

#进入cli容器
sudo docker exec -it cli bash
#针对orderer的channel create
peer channel create -o orderer.example.com:7050 -c mychannel -f channel-artifacts/channel.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

Join channel

peer channel join -b mychannel.block

Update anchor peer

#update anchor peer info of org1
peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org1MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

#update anchor peer info of org2
peer channel update -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/Org2MSPanchors.tx --tls --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

Chaincode

#install chaincode
peer chaincode install -n mycc -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02

#instantiate chaincode
peer chaincode instantiate -o orderer.example.com:7050 --tls --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 mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"

#invoke chaincode
peer chaincode invoke -o orderer.example.com:7050 --tls --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 mycc -c '{"Args":["invoke","a","b","10"]}'

#query chaincode
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'

猜你喜欢

转载自blog.csdn.net/haiyanggeng/article/details/78551282