Smart contracts are how users interact with the blockchain ledger. Smart contracts are implemented in Hyperledger Fabric in the form of chaincode packages. Organizations that want to validate transactions or query the ledger need to install a chaincode on their peers.
The Fabric chaincode lifecycle is the process through which a chaincode is distributed to a channel. Before a chaincode may be used to create transactions, different organizations can agree on how it will be operated using the Fabric chaincode lifecycle. While an endorsement policy specifies which companies must execute a chaincode to validate a transaction, channel members must agree on the chaincode endorsement policy using the Fabric chaincode lifecycle.
The steps for deploying a chaincode are:
- Install the package on the peer
- Approve the chaincode definition on the channel
- Commit the chaincode definition on the channel
You must have a networkconfig file, if you haven't, please, go to the network config documentation.
For this step you'll need to install the chaincode package on your peer. To do this, run the following command:
- Node JS
The parameters are:
--path: The path to the chaincode package.
--config: The network configuration file.
--language: The language of the chaincode.
--label: The label of the chaincode.
--user: The user to use to install the chaincode, this user must be defined in the network config file.
--peer: The peer to install the chaincode on.
If you don't have any chaincode packages, you can download them from the hlf-operator github repository.
If no user is found in the networkConfig.yaml, the following error will be thrown:
After a couple of minutes, depending on your set up, the chaincode will be installed on the peer and a package id will be returned.
The list of all chaincodes installed in the peer can be obtained with the following command: