hyperledger fabric 基础环境搭建
基础环境搭建参考
一、下载fabric-samples、二进制文件、镜像文件
1、进入gopath目录下,创建目录src/github.com/hyperledger,进到该目录
2、下载官网上面的bootstrap.sh,修改可执行权限,chmod +x bootstrap.sh
3、执行bootstrap.sh下载fabric-samples、二进制文件、docker镜像,网络不好的同学耐心等待哈。
1、cd first-network
2、先关闭网络,确保服务是关闭状态
./byfn.sh down
3、创建网络
./byfn.sh generate
创建成功后生成两个组织、四个对等节点
genesis.block为创世区块的配置文件
4、启动网络测试
./byfn.sh up
查看docker进程
5、关闭网络
./byfn.sh down
1、生成初始区块
../bin/cryptogen generate --config=./crypto-config.yaml
设置FABRIC配置文件路径
export FABRIC_CFG_PATH=$PWD
生成创世区块
../bin/configtxgen -profile TwoOrgsOrdererGenesis -channelID byfn-sys-channel -outputBlock ./channel-artifacts/genesis.block
2、设置区块链名称,生成应用通道相关信息
export CHANNEL_NAME=mychannel
../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME
3、生成锚节点,更新配置文件
../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org1MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org1MSP
../bin/configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./channel-artifacts/Org2MSPanchors.tx -channelID $CHANNEL_NAME -asOrg Org2MSP
4、启动网络
docker-compose -f docker-compose-cli.yaml up -d
5、进入docker 命令行
docker exec -it cli bash
6、生成一个通道
export CHANNEL_NAME=mychannel
创建通道
peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -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
7、加入通道
peer channel join -b mychannel.block
8、安装链码
peer chaincode install -n mycc -v 1.0 -p github.com/chaincode/chaincode_example02/go/
9、实例化链码,时间较长,耐心等待
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 $CHANNEL_NAME -n mycc -v 1.0 -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"
10、查询
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'
11、转账调用(invoke)
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 mycc -c '{"Args":["invoke","a","b","20"]}'
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!