生成创世块 (在orderer节点上生成)在configtx.yaml文件目录
configtxgen -profile OrgsOrdererGenesis -outputBlock /tmp/hyperledger/org0/orderer/genesis.block -channelID syschannel (系统名)
创建通道交易 (在orderer节点上生成) 将mycc.tx文件复制到创建通道的peer节点–在configtx.yaml文件目录
configtxgen -profile TwoOrgsChannel -outputCreateChannelTx /etc/hyperledger/organizations/mycc.tx -channelID mycc //指定链码名称
导入证书
root@peer0:/etc/hyperledger/fabric
打包链码
peer lifecycle chaincode package test.tar.gz --path ../chaincode/fabcar/go/ --lang golang --label test_1
创建通道,并且需要将生成的mycc.block复制到其他的组织节点上,然后执行加入通道
peer channel create -o orderer.hnpmct.com:7050 -c mycc --ordererTLSHostnameOverride orderer.hnpmct.com -f /etc/hyperledger/fabric/mycc.tx --outputBlock /etc/hyperledger/fabric/mycc.block --tls --cafile /etc/hyperledger/organizations/ordererOrganizations/hnpmct.com/orderers/orderer.hnpmct.com/msp/tlscacerts/tlsca.hnpmct.com-cert.pem
root@peer0:/etc/hyperledger/fabric
admin channel.tx core.yaml fabcar.tar.gz msp mychannel.block tls
加入通道
root@peer0:/etc/hyperledger/fabric
2020-08-19 16:32:52.129 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
2020-08-19 16:32:52.159 CST [channelCmd] executeJoin -> INFO 002 Successfully submitted proposal to join channel
root@peer0:/etc/hyperledger/fabric
2020-08-19 16:33:01.036 CST [channelCmd] InitCmdFactory -> INFO 001 Endorser and orderer connections initialized
Channels peers has joined:
mychannel
安装链码 (所有节点都需要,orderer节点不需要)
root@peer0:/etc/hyperledger/fabric
查询包ID
root@peer0:/etc/hyperledger/fabric
Installed chaincodes on peer:
Package ID: fabcar_1:762e0fe3dbeee0f7b08fb6200adeb4a3a20f649a00f168c0b3c2257e53b6e506, Label: fabcar_1
配置
root@peer0:/etc/hyperledger/fabric
授权
root@peer0:/etc/hyperledger/fabric
2020-08-19 16:42:35.236 CST [chaincodeCmd] ClientWait -> INFO 001 txid [e4c0b2f6852a95d76c9ab2c080bf059246e26fb18ea6c1f82e69ff8d79af5aae] committed with status (VALID) at
检查
root@peer0:/etc/hyperledger/fabric
{
"approvals": {
"Org1MSP": true,
"Org2MSP": true,
"Org3MSP": true,
"Org4MSP": true
}
}
提交链码到通道上 (某个peer节点上运行就可以,其他节点同步)
peer lifecycle chaincode commit -o orderer.hnpmct.com:7050 --ordererTLSHostnameOverride orderer.hnpmct.com --channelID mychannel --name fabcar --version 1.0 --sequence 1 --tls --cafile /etc/hyperledger/organizations/ordererOrganizations/hnpmct.com/orderers/orderer.hnpmct.com/msp/tlscacerts/tlsca.hnpmct.com-cert.pem --peerAddresses peer0.org1.hnpmct.com:7051 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org1.hnpmct.com/peers/peer0.org1.hnpmct.com/tls/ca.crt --peerAddresses peer0.org2.hnpmct.com:7151 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org2.hnpmct.com/peers/peer0.org2.hnpmct.com/tls/ca.crt --peerAddresses peer0.org3.hnpmct.com:7251 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org3.hnpmct.com/peers/peer0.org3.hnpmct.com/tls/ca.crt --peerAddresses peer0.org4.hnpmct.com:7351 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org4.hnpmct.com/peers/peer0.org4.hnpmct.com/tls/ca.crt
peer lifecycle chaincode commit -o orderer.hnpmct.com:7050 --ordererTLSHostnameOverride orderer.hnpmct.com --channelID mychannel --name fabcar --version 1.0 --sequence 1 --tls --cafile
/etc/hyperledger/organizations/ordererOrganizations/hnpmct.com/orderers/orderer.hnpmct.com/msp/tlscacerts/tlsca.hnpmct.com-cert.pem
--peerAddresses peer0.org1.hnpmct.com:7051 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org1.hnpmct.com/peers/peer0.org1.hnpmct.com/tls/ca.crt --peerAddresses peer0.org2.hnpmct.com:7151 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org2.hnpmct.com/peers/peer0.org2.hnpmct.com/tls/ca.crt --peerAddresses peer0.org3.hnpmct.com:7251 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org3.hnpmct.com/peers/peer0.org3.hnpmct.com/tls/ca.crt --peerAddresses peer0.org4.hnpmct.com:7351 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org4.hnpmct.com/peers/peer0.org4.hnpmct.com/tls/ca.crt
调用链码初始化
peer chaincode invoke -o orderer.hnpmct.com:7050 --ordererTLSHostnameOverride orderer.hnpmct.com --tls --cafile /etc/hyperledger/organizations/ordererOrganizations/hnpmct.com/orderers/orderer.hnpmct.com/msp/tlscacerts/tlsca.hnpmct.com-cert.pem -C mychannel -n fabcar --peerAddresses peer0.org1.hnpmct.com:7051 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org1.hnpmct.com/peers/peer0.org1.hnpmct.com/tls/ca.crt --peerAddresses peer0.org2.hnpmct.com:7151 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org2.hnpmct.com/peers/peer0.org2.hnpmct.com/tls/ca.crt --peerAddresses peer0.org3.hnpmct.com:7251 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org3.hnpmct.com/peers/peer0.org3.hnpmct.com/tls/ca.crt --peerAddresses peer0.org4.hnpmct.com:7351 --tlsRootCertFiles /etc/hyperledger/organizations/peerOrganizations/org4.hnpmct.com/peers/peer0.org4.hnpmct.com/tls/ca.crt -c '{"function":"initLedger","Args":[]}'
查询
peer chaincode query -C mychannel -n fabcar -c '{"Args":["queryAllCars"]}'