1. 打包链码:

peer lifecycle chaincode package asset-transfer-basic.tar.gz --path /etc/hyperledger/fabric/chaincodes/asset-transfer-basic/javascript/ --lang node --label asset-transfer-basic_1


2. 安装链码:

peer lifecycle chaincode install asset-transfer-basic.tar.gz


export CC_PACKAGE_ID=asset-transfer-basic_1:fbfd2042fb4bbdd9abb076d30afbb63eafd56a1ccb40b8699ff19725fd2f716c


3. 批准链码定义:

peer lifecycle chaincode approveformyorg \

-o orderer0.spicefactory.com:7050 \

--ordererTLSHostnameOverride orderer0.spicefactory.com \

--channelID spicefactorychannel \

--name asset-transfer-basic \

--version 1.0 \

--package-id $CC_PACKAGE_ID \

--sequence 1 \

--tls \

--cafile ${ORDERER_CA}

 

4. 查看通道成员是否已经批准相同链码定义:


peer lifecycle chaincode checkcommitreadiness \

--channelID spicefactorychannel \

--name asset-transfer-basic \

--version 1.0 \

--sequence 1 \

--tls \

--cafile ${ORDERER_CA} \

--output json


5. 将链码提交到通道:


peer lifecycle chaincode commit \

-o orderer0.spicefactory.com:7050 \

--ordererTLSHostnameOverride orderer0.spicefactory.com \

--channelID spicefactorychannel \

--name asset-transfer-basic \

--version 1.0 \

--sequence 1 \

--tls \

--cafile ${ORDERER_CA} \

--peerAddresses ${CORE_PEER_ADDRESS} \

--tlsRootCertFiles ${CORE_PEER_TLS_ROOTCERT_FILE}


6. 查看链码定义是否已提交给通道:


peer lifecycle chaincode querycommitted \

--channelID spicefactorychannel \

--name asset-transfer-basic \

--cafile ${ORDERER_CA}  


7. 调用和查询链码:

a. 调用链码:

peer chaincode invoke \

-o orderer0.spicefactory.com:7050 \

--ordererTLSHostnameOverride orderer0.spicefactory.com \

--tls \

--cafile ${ORDERER_CA} \

-C spicefactorychannel \

-n asset-transfer-basic \

--peerAddresses ${CORE_PEER_ADDRESS} \

--tlsRootCertFiles ${CORE_PEER_TLS_ROOTCERT_FILE} \

-c '{"function":"InitSpicefactoryLedger","Args":[]}'


b. 查询链码:

peer chaincode query \

-C spicefactorychannel \

-n asset-transfer-basic \

-c '{"Args":["GetAllAssets"]}'