区块链笔记(3)-fabric常用命令总结

115 阅读3分钟

区块链笔记(3)-fabric常用命令总结

总结一下在上篇博客中用到的一些命令

configtxgen常用命令

该命令用来为用户创建与检查配置相关的工作

生成一个创世块

configtxgen -profile OneOrgsOrdererGenesis -outputBlock ./channel-artifacts/genesis.block

检查一个创世块|

configtxgen -inspectBlock genesis.block

生成通道配置区块

configtxgen -profile OneOrgsChannel -outputCreateChannelTx ./channel-artifacts/mychannel.tx -channelID mychannel

检查频道创建tx

configtxgen -inspectChannelCreateTx mychannel.tx

打印一个组织定义

configtxgen -printOrg Org1

输出anchor peer tx

configtxgen -outputAnchorPeersUpdate 锚节点id -profile SampleSingleMSPChannelV1_1 -asOrg Org1

peer 常用命令

peer命令包含五个不同的自命令:

peer channel [command]

peer channel create

创建一个通道,并将创世块写入文件

peer channel create -c mychannel -f ./createchannel.txn --orderer orderer.example.com:7050

-c:channelID
-f:事务文件的配置信息
-o/–orderer:orderer节点

peer channel getinfo

获取指定频道的区块链信息,需要’-c’指定channelID

peer channel getinfo -c mychannel

peer channel join

将peer节点加入通道中

peer channel join -b ./mychannel.block

peer channel list

查看加入通道的节点列表

peer channel list

peer channel update

签署并将提供的配置文件更新发送到通道中,需要’-f’,’-o’,’-c’

peer channel update -c mychannel -f ./updatechannel.txn -o orderer.example.com:7050

peer chaincode [option] [flags]

peer chaincode install [flags]

将指定的链代码打包到部署规范中,并将其保存到peer路径中,例如在第二篇博客helloworld中

peer chaincode install -n mycc -p github.com/hyperledger/fabric/helloworld/chaincode/go/helloworld/cmd -v 1.0

-l:编写chaincode的语言,默认”golang”
-n:chaincode名(自定义)
-p:chaincode路径
-v:chaincode版本

peer chaincode instantiate [flags]

实例化链代码

export ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
peer chaincode instantiate -o orderer.example.com:7050 --tls --cafile $ORDERER_CA -C mychannel -n mycc -v 1.0 -c '{"Args":["init","a","100","b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"

-C:channel ID
-c:JSON字串的链代码构造函数消息(默认”{}”)
-h:帮助
-l:编写chaincode的语言,默认”golang”
-n:chaincode名 (和打包时的要一致)
-P:与此代码相关的认可政策(背书策略)
-o:orderer节点

peer chaincode invoke

调用指定的链代码,它将尝试提交指定的事务到网络中

peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n mycc --peerAddresses peer0.org1.example.com:7051 --peerAddresses peer0.org2.example.com:7051 -c '{"Args":["invoke","a","b","10"]}'

-C:channel ID
-c:JSON字串的链代码构造函数消息(默认”{}”)
-n:chaincode名字
-o:orderer节点

peer chaincode list

如果指定通道,则在通道中获取实例化的链代码,或在peer节点上获取已安装的链代码

peer chaincode query

peer节点查询

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

-C:channelID string
-c:JSON字串的链代码构造函数消息(默认”{}”)
-n:chaincode名字
-r:如果为true,则将查询值输出为原始字节,否则格式化为可打印字符串

peer logging [option] [flags]

允许用户动态观察和配置peer的日志级别