Chaincode is the implementation of smart contracts in the Hyperledger Fabric framework. It supports popular programming languages such as Go, Node.js, and Java. This topic describes how to deploy a new chaincode to a channel.
This topic applies to users of Fabric 1.4 instances. If you use a Fabric 2.2 instance, see Manage chaincode (V2.2) to deploy chaincode.
First, develop, test, and package your chaincode in a Hyperledger Fabric development environment:
For more information about chaincode development, see Chaincode for Developers.
After the chaincode passes testing, package it using the
peer chaincode packagecommand. When packaging, include the required dependencies. For a Go chaincode, use the following steps to place the dependency files in the vendor directory:Install the govendor tool.
go get -u -v github.com/kardianos/govendorGo to the chaincode project directory and initialize the vendor directory.
govendor initAutomatically move the dependency packages used by the project from GOPATH to the vendor directory.
govendor add +external
For more information about the packaging command, see peer chaincode command. Note the following:
When you package a Go chaincode, the -p parameter must specify the relative path of the directory that contains the main package of the chaincode under $GOPATH/src. When you package a Java chaincode, the -p parameter must specify the Java project directory. When you package a Node.js chaincode, the -p parameter must specify the root directory of the Node.js project that contains the package.json file. Do not use a relative path format such as "./xxx" for the -p parameter.
If the chaincode language is Go, you can omit the -l option. If the chaincode language is Node.js or Java, you must specify the -l node or -l java parameter.
If the chaincode initialization method does not require input parameters, you can omit the -c option.
Do not add the -i or -S options.
The following example packages the Go chaincode source code from the $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/example02 directory into a file named ccpack.out. The chaincode is named mycc and its version is 1.0.
peer chaincode package ccpack.out -n mycc -p github.com/hyperledger/fabric/examples/chaincode/go/example02/cmd -c '{"Args":["init","a","100","b","200"]}' -v 1.0Download
peer:
Deploying a new chaincode involves the following three steps. For information about how to upgrade an existing chaincode in a channel, see Upgrade chaincode:
Upload the chaincode
Install the chaincode
Instantiate the chaincode
Upload the chaincode
Log on to the Alibaba Cloud BaaS console.
On the Overview page, in the My Organizations area, find the target organization and click its name.
Click the Chaincodes tab.
Click Upload Chaincode.
In the dialog box that appears, upload the chaincode that you packaged in the development environment. For more information about how to package the chaincode, see the preceding section.
Select the channel to which you want to deploy the chaincode. If you are deploying a new chaincode, ensure that its name does not conflict with any existing chaincode in the channel.
Enter an endorsement policy.
For example:
OR ('Org1MSP.peer','Org2MSP.peer')indicates that an endorsement from either of the two organizations in the channel is required.AND ('Org1MSP.peer','Org2MSP.peer')indicates that endorsements from both organizations in the channel are required.Click OK.
After the chaincode is uploaded, it appears in the list on the Chaincodes tab. The chaincode name in the Chaincode column and the version number in the Version column are the ones you specified when you packaged the chaincode locally.
Install the chaincode
Prerequisites
You have uploaded the chaincode.
Procedure
Log on to the Alibaba Cloud BaaS console.
On the Overview page, in the My Organizations area, find the target organization and click its name.
Click the Chaincodes tab.
Find the chaincode that you want to install and in the Actions column, click Install to install the chaincode in the current organization.

After the installation is complete, the Installation Status changes from Not Installed to Installed, and Install in the Actions column changes to Instantiate.
If the endorsement policy that you set when uploading the chaincode requires endorsements from multiple organizations, you must also install the chaincode in those organizations.
Instantiate the chaincode
Prerequisites
You have uploaded and installed the chaincode.
Procedure
Log on to the Alibaba Cloud BaaS console.
On the Overview page, in the My Organizations area, find the target organization and click its name.
Click the Chaincodes tab.
Find the chaincode that you want to instantiate and in the Actions column, click Instantiate.
In the dialog box that appears, the system automatically displays the endorsement policy that you entered when you uploaded the chaincode. You can either keep this policy or specify a new one.
For example:
OR ('Org1MSP.peer','Org2MSP.peer')indicates that an endorsement from either of the two organizations in the channel is required.AND ('Org1MSP.peer','Org2MSP.peer')indicates that endorsements from both organizations in the channel are required.In the dialog box, click Advanced. In the Private Data Collection Configurations input box, enter the JSON definition for your chaincode's private data collection. If your chaincode does not use the private data feature, you can skip this step.
The following is an example of a JSON definition for a private data collection:
[{"name": "collectionName", "policy": "OR('Org1MSP.peer')", "memberOnlyRead": false, "requiredPeerCount": 0, "maxPeerCount": 3, "blockToLive": 0}]. This definition indicates that the chaincode uses a private data namespace namedcollectionName, and only nodes of organizationOrg1can access the private data in this namespace.Note that once the
nameandblockToLiveof a private data collection are set, you cannot modify these values during an upgrade. For more information, see Using Private Data in Fabric.Click Instantiate.

This operation takes several seconds to several minutes, depending on the complexity of the chaincode dependencies. After the operation is successful, the Channel Status changes from Not Instantiated to Running, and the value in the Actions column becomes empty.
Next steps
You can now create a user and access the blockchain network through an SDK.