阿里云Fabric 1个order1个peer部署步骤

1.Fabric官方提供了专门编译cryptogen的入口,只需要运行以下命令即可:
cd ~/go/src/github.com/hyperledger/fabric
make cryptogen
运行后系统返回结果:
build/bin/cryptogen
CGO_CFLAGS=" " GOBIN=/home/studyzy/go/src/github.com/hyperledger/fabric/build/bin go install -tags “” -ldflags “-X github.com/hyperledger/fabric/common/tools/cryptogen/metadata.Version=1.1.0github.com/hyperledger/fabric/common/tools/cryptogen
Binary available as build/bin/cryptogen

也就是说在build/bin文件夹下可以看到编译出来的cryptogen程序。
然后复制bin 文件。

2.在 github.com/hyperledger/ 创建新的文件夹,粘贴bin文件到该目录下并在这个文件夹下创建三个文件夹chaincode(存放智能合约),config(配置文件)crypto-config(order和peer证书配置文件)。

3.复制下面四个文件,根据需求修改里面的信息
configtx.yaml
crypto-config.yaml,
docker-compose-order.yaml,
docker-compose-peer.yaml

4.然后进行下面的操作

4.1生成证书
./bin/cryptogen generate --config=./crypto-config.yaml

4.2生成创世区块
./bin/configtxgen -profile TwoOrgOrdererGenesis -outputBlock ./config/genesis.block

4.3查看创世块
./bin/configtxgen -inspectBlock ./config/genesis.block

4.4生成通道凭证
./bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./config/mychannel.tx -channelID mychannel

4.5启动order节点和peer节点
docker-compose -f docker-compose-order.yaml up -d
docker-compose -f docker-compose-peer.yaml up -d

4.6查看启动的镜像命令如下
docker ps -a

5.进入cli容器命令
docker exec -it cli bash

6.创建一个channel
peer channel create -o orderer.example.com:7050 -c mychannel -t 50 -f ./channel-artifacts/mychannel.tx

7.创建完channel后,需要通过mychannel.block文件来加入该channel,以便后续可以安装实例化并测试智能合约。
具体命令如下
peer channel join -b mychannel.block

8.安装智能合约
peer chaincode install -n mychannel -p github.com/hyperledger/fabric/chaincode/go/chaincode_example02 -v 1.0

9.实例化智能合约
peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n mychannel -c ‘{“Args”:[“init”,“A”,“100”,“B”,“150”]}’ -P “OR (‘Org1MSP.member’,‘Org2MSP.member’)” -v 1.0

10.查询合约命令
peer chaincode query -C mychannel -n mychannel -c ‘{“Args”:[“query”,“A”]}’

11.根据合约内容,让A给B转5快钱,执行如下命令
peer chaincode invoke -C mychannel -n mychannel -c ‘{“Args”:[“invoke”, “A”, “B”, “20”]}’

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章