A Step-by-Step guideline for deploying the smart contract.
Installation and approval of Chaincode
Smart Contracts are officially called as chaincode in Fabric. A peer node can install a smart contract, meaning the smart contract is physically installed to the peer node.
After installation, the chaincode should be approved by all organizations in the channel. Once a smart contract is approved and committed, the smart contract is now active.
The functions in the smart contract can be invoked as transactions. However, only those nodes who have installed the same smart contract can invoke functions (transactions).
Create a Fabric smart contract package using Fabric command "peer"
# Install the packaged smart contractpeerlifecyclechaincodeinstall~/${USER}-chaincode.gz# Verify if the smart contract is installedpeerlifecyclechaincodequeryinstalled
# Install the packaged smart contractpeerlifecyclechaincodeinstall~/${USER}-chaincode.gz# Verify if the smart contract is installedpeerlifecyclechaincodequeryinstalled
And also terminal 3,
# Install the packaged smart contractpeerlifecyclechaincodeinstall~/${USER}-chaincode.gz# Verify if the smart contract is installedpeerlifecyclechaincodequeryinstalled
Approve the installed smart contract on each peer
In terminal 1,
#Grep the package id of your smart contractPACKAGEID=$(peerlifecyclechaincodequeryinstalled|grep ${USER}-chaincode|sed-n's/.*Package ID: \(.*\),.*/\1/p')#Approve your smart contractpeerlifecyclechaincodeapproveformyorg-onode-1:7050 \--name ${USER}-chaincode--channelID ${USER}-channel \--package-id ${PACKAGEID} --version0--sequence1
Repeat in terminal 2,
#Grep the package id of your smart contractPACKAGEID=$(peerlifecyclechaincodequeryinstalled|grep ${USER}-chaincode|sed-n's/.*Package ID: \(.*\),.*/\1/p')#Approve your smart contractpeerlifecyclechaincodeapproveformyorg-onode-1:7050 \--name ${USER}-chaincode--channelID ${USER}-channel \--package-id ${PACKAGEID} --version0--sequence1
Also in terminal 3
#Grep the package id of your smart contractPACKAGEID=$(peerlifecyclechaincodequeryinstalled|grep ${USER}-chaincode|sed-n's/.*Package ID: \(.*\),.*/\1/p')#Approve your smart contractpeerlifecyclechaincodeapproveformyorg-onode-1:7050 \--name ${USER}-chaincode--channelID ${USER}-channel \--package-id ${PACKAGEID} --version0--sequence1
To verify if all peers approve your smart contract. Execute the following command in terminal 1.
Chaincode definition for chaincode 'cyliu-chaincode', version '0', sequence '1' on channel 'cyliu-channel' approval status by org:
greatinsurance: true
police: true
smartinsurance: true
If any organization show false, wait a few seconds and execute the command again until all organization show true
Execute the following command to commit the approved smart contract