fabric运行记录

创建第一个fabric网络

  • Generate Network Artifacts
    cd first-network
    先关闭服务
    ./byfn.sh -m down
    然后创建
    ./byfn.sh -m generate

  • 创建创世区块
    ../bin/cryptogen generate --config=./crypto-config.yaml
    该文件是first-network下面的配置文件

  • 生成初始区块
    export FABRIC_CFG_PATH=$PWD
    f
    ../bin/configtxgen -profile TwoOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block

  • 生成应用通道的配置信息
    export CHANNEL_NAME=mychannel
    链的一个标识
    ../bin/configtxgen -profile TwoOrgsChannel -outputCreateChannelTx ./channel-artifacts/channel.tx -channelID $CHANNEL_NAME

  • 生成锚节点配置更新文件

../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
锚节点用于和对等节点进行通信

  • 操作网络

编辑 docker-compose-cli.yaml 注释掉command命令
路径:/goWorkPlace/src/github.com/hyperledger/fabric/peer
CHANNEL_NAME=$CHANNEL_NAME TIMEOUT=600 docker-compose -f docker-compose-cli.yaml up -d

创建和加入通道

  • 进入docker容器
    docker exec -it cli bash

  • 创建通道

export CHANNEL_NAME=mychannel

  • 创建区块链

peer channel create -o orderer.example.com:7050 -c $CHANNEL_NAME -f ./channel-artifacts/channel.tx --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem

  • 加入通道
    peer channel join -b mychannel.block

链上代码

  • 安装链码
    peer chaincode install -n mycc -v 1.4 -p github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02

用以上代码安装,会被认为是本地路径,查看本地挂载位置docker-compser-cli.yaml
故本文使用以下代码
peer chaincode install -n mycc -v 1.4 -p github.com/chaincode/chaincode_example02/go

  • 实例化链码
    peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --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.4 -c '{"Args":["init","a","100","b","200"]}' -P "OR ('Org1MSP.member','Org2MSP.member')"

初始化a,b两个节点,a有一百块,b有两百块

  • 查询

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

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

以上为一次基本流程

你可能感兴趣的:(fabric运行记录)