1.智能合约
2.网络搭建配置的实现
- crypto-config.yaml:用于配置节点的个数,参考firstnetwork编写
- 编写好后,传到linux对应目录
- 进入deploy目录,设置工作目录为当前目录
export FABRIC_CFG_PATH=$GOPATH/src/fabric_asset/deploy
- 指定按照yaml文件生成配置
cryptogen generate --config=./crypto-config.yaml
-
configtx.yaml:用于区块联盟中的组织信息,配置名字和证书等的位置,参考firstnetwork编写
-
编写好后,传到linux对应目录
-
创建用于存放配置的目录
mkdir config
-
生成系统链的创世区块
-profile:指定联盟配置
-outputBlock:指定存放的位置
configtxgen -profile OneOrgsOrdererGenesis -outputBlock ./config/genesis.block
-
生成通道的创世交易
-profile:指定业务联盟
-outputCreateChannelTx:指定存放路径
-channelID:指定创建名字
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./config/mychannel.tx -channelID mychannel
-
生成两个组织锚节点的交易信息
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./config/Org0MSPanchors.tx -channelID mychannel -asOrg Org0MSP
configtxgen -profile TwoOrgsChannel -outputAnchorPeersUpdate ./config/Org1MSPanchors.tx -channelID mychannel -asOrg Org1MSP
- 新建docker-compose.yaml文件并移动到deploy目录下
3.启动网络
-
启动docker,后台运行(要以管理员身份运行)
docker-compose up -d
-
查看orderer节点的运行日志
docker logs orderer.example.com
-
与客户端交互操作
docker exec -it cli bash
-
创建通道
-o:指定与哪个orderer节点通信
-c:指定创建的通道名称
-f:指定使用的文件
peer channel create -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/config/mychannel.tx
-
加入通道
peer channel join -b mychannel.block
-
查看peer加入的通道列表
peer channel list
-
指定主节点
peer channel update -o orderer.example.com:7050 -c mychannel -f /etc/hyperledger/config/Org1MSPanchors.tx
- 安装链码
-n:安装的名字
-v: version
-l:使用语言
-p:path
peer chaincode install -n badexample -v 1.0.0 -l golang -p github.com/chaincode/badexample
- 克隆一个会话,交互执行peer0,查看安装的链码
docker exec -it peer0.org1.example.com bash
cd /var/hyperledger/production/chaincodes/
- 链码实例化
peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n badexample -l golang -v 1.0.0 -c '{"Args":["init"]}'
- 链码交互执行
peer chaincode query -C mychannel -n badexample -c '{"Args":[]}'
- 多次执行查询,得到的结果不同,因为invoke()中使用了随机数,不要这么做
4.网络关闭
- 退出客户端
exit
- 在deploy目录下关闭docker
docker-compose down
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)