channel列表
peer get channel
chaincode列表
peer chaincode list --installed -C mychannel
peer chaincode list --instantiated -C mychannel
切换用户
使用环境变量切换
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
CORE_PEER_ADDRESS=peer0.org2.example.com:9051
CORE_PEER_LOCALMSPID="Org2MSP"
CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
安装链码
-p
指定的是gopath的相对路径
peer chaincode install -n chcc -v 1.0.0 -l golang -p github.com/chaincode/chcc/chaincode
实例化链码
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 mychannel -n chcc -l golang -v 2.0.0 -c '{"Args":["init","a","100","b","200"]}'
调用链码
peer chaincode query -C mychannel -n mycc -c '{"Args":["query","a"]}'
peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n mycc -c '{"Args":["invoke","a","b","10"]}'
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 --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt -c '{"Args":["invoke","a","b","1"]}'
创建channel
peer channel create -o orderer.example.com:7050 -c mychannel -f ./channel-artifacts/truck.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
让已经运行的Peer模块加入通道
peer channel join -b cars.block
删除chaincode
分别进入链码安装的容器,删除 /var/hyperledger/production/chaincodes/ 路径下对应的链码包,然后docker rm -f 删除对应的容器
不进入容器方法:
docker exec -it peer0.org1.example.com bash -c 'rm -rf /var/hyperledger/production/chaincodes/chcc*'
docker exec -it peer1.org1.example.com bash -c 'rm -rf /var/hyperledger/production/chaincodes/chcc*'
docker exec -it peer0.org2.example.com bash -c 'rm -rf /var/hyperledger/production/chaincodes/chcc*'
docker exec -it peer1.org2.example.com bash -c 'rm -rf /var/hyperledger/production/chaincodes/chcc*'
docker rm -f a5c181936195 e22b9d337597 2b25bf1b77d1 e0b51107f26c
查询系统链码qscc
查询系统链码qscc,提供以下几种方法,但是查询出来的编码有问题,需要修改sdk去解析
GetChainInfo
GetBlockByNumber
GetBlockByHash
GetTransactionByID
GetBlockByTxID
peer chaincode query -C mychannel -n qscc -c '{"Args":["GetBlockByHash", "mychannel", "HE4OHQ0pEvcMEh0E3lyvfW40ftxhmoQBWCclO3aYXWY="]}'
查看区块
并使用configtxlator
解析成json,这样看着还是不方便,使用sdk比较好
#设置环境变量
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 && export CHANNEL_NAME=mychannel
#导出最新配置
peer channel fetch config config_block.pb -o orderer.example.com:7050 -c $CHANNEL_NAME --tls --cafile $ORDERER_CA
#导出最新区块
peer channel fetch newest mychanneltest.block -c mychannel --orderer orderer.example.com:7050 --tls --cafile $ORDERER_CA
#导出指定区块
peer channel fetch 7 7.pb -c mychannel --orderer orderer.example.com:7050 --tls --cafile $ORDERER_CA
#使用`configtxlator`解析
configtxlator proto_decode --input 7.pb --type common.Block | jq .data.data[0].payload.data.config > 7.json
转载请注明来源