进入 test-network的目录下
cd test-network
相对目录
./network.sh up
创建通道 名字随意起名(mychannel为默认名称)
./network.sh createChannel -c mychannel1
将链码放在chain-code目录下
返回test-network所在目录
cd ../
将Bin目录中的二进制文件添加到CLI路径
export PATH=${PWD}/../bin:$PATH
设置IFABRIC_CFG_PATH为指向fabric - samples中的core.yaml文件
export FABRIC_CFG_PATH=$PWD/../config/
创建链码包
peer lifecycle chaincode package 文件名.tar.gz --path 链码所在路径 --lang java --label 文件名
Org1节点安装链码
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:7051
在peer节点上安装链码
peer lifecycle chaincode install 文件名.tar.gz
Org2节点安装链码
export CORE_PEER_TLS_ENABLED=true
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:9051
在peer节点上安装链码
peer lifecycle chaincode install 文件名.tar.gz
查询包ID
peer lifecycle chaincode queryinstalled
通过链码时,需要使用包ID。因此我们将包ID设为环境变量。将返回的ID放到下面命令上。
export CC_PACKAGE_ID=项目文件名(label):id值
Org2 通过链码定义
peer lifecycle chaincode approveformorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID 通道名 --name 项目文件名 --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
Org1通过链码定义
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export CORE_PEER_ADDRESS=localhost:7051
peer lifecycle chaincode approveformorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID 通道名 --name 项目文件名 --version 1.0 --package-id $CC_PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
检查通过成员是否已批准相同的链码定义
peer lifecycle chaincode checkcommitreadiness --channelId 通道名 --name 项目文件名 --version --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --output json
将链码定义提交到通道
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID 通道名 --name 项目文件名 --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
确认链码定义已经提交到通道
peer lifecycle chaincode querycommitted --channelID 通道名 --name 项目文件名 --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
调用:
peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride
orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/
msp/tlscacerts/tlsca.example.com-cert.pem -C 通道名-n 项目文件名 --peerAddresses
localhost:7051 --tlsRootCertFiles
${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.c
om/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles
${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.c
om/tls/ca.crt -c '{"function":"initLedger","Args":[]}'
peer chaincode query -C 通道名 -n 项目文件名 -c '{"Args":["方法名","参数"]}'