In Hyperledger Fabric framework, the chaincodes are the ‘smart contracts’ that run on the peers and create transactions. BaaS currently supports Go, Node.js and Java. This document describes how to deploy new chaincodes for a channel.
If you want to upgrade a chaincode that exists in the channel, see Upgrade chaincodes.
This chapter is applicable to users who purchase an instances of Fabric V1.4. If you purchase an instances of Fabric V2.2, please refer to the Manage chaincode (V2.2) deploy chaincodes.
To learn more about how to develop Fabric chaincode, please refer: Chaincode for Developers.
Please use
peer chaincode package
command to build chaincode package, including all code dependencies. Take golang chaincode for example, put dependent files in vendor directory under golang project:Install govendor tool.
go get -u -v github.com/kardianos/govendor
In chaincode project directory, initialize vendor directory.
govendor init
Move dependent files in GOPATH to vendor directory.
govendor add +external
You can find more information about chaincode package from: peer chaincode commands.
Tips:
In golang,
-p
should be the main package’s relative path from base directory ($GOPATH/src). In Java,-p
should be the root directory of the chaincode project. In nodejs,-p
should be the root directory of the chaincode project that contians package.json.-p
should not be in ‘./xxx’ format.Omit
-l
if chaincode language is golang. Use-l node
if chaincode language is nodejs, while-l java
if chaincode language is Java.Omit
-c
if there is no need forinput
.Do not use
-i
,-S
For example, to create a golang chaincode package named ccpack.out
which name is mycc
and version 1.0
from directory: $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/example02
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.0
You can download peer
binary from here:
The deployment of new chaincodes takes the following three steps:
Upload the chaincode
Install the chaincode
Instantiate the chaincode
Upload the chaincode
Log on to the Alibaba Cloud BaaS console.
On the Overview page, locate My Organizations, locate the target organization, and click the name of the organization.
Click the Chaincodes tab.
Click Upload Chaincode.
In the dialog box that appears, upload a chaincode that has been packaged locally.
Select the channel for the chaincode to be deployed. If it’s a new deployment, please make sure there’s no same chaincode name existing in any channel.
Enter the endorsement policy.
Example:
OR ('Org1MSP.peer','Org2MSP.peer')
means that endorsement from either of the two organizations in the channel is required, andAND ('Org1MSP.peer','Org2MSP.peer')
indicates that endorsements from two organizations in this channel are required.Click OK.
After the chaincode has been uploaded, the chaincode will appear in the chaincode list on the Chaincodes tab. The name of the chaincode displayed in the Chaincode column and the version number displayed in the Version column are specified when you package the chaincode locally.
Install the chaincode
Prerequisites
You have uploaded the chaincode.
Procedures
Log on to the Alibaba Cloud BaaS console.
On the Overview page, locate My Organizations, locate the target organization, and click the name of the organization.
Click the Chaincodes tab.
Locate the chaincode that you want to install, click Install in the Actions column to install the chaincode in the organization.
After the installation is complete, the Status in Organization changes from Uninstalled to Installed, and the Install in the Actions column changed to Instantiate.
If the endorsement policy you set when uploading the chaincode requires multiple organizations to run this chaincode, you need to install the chaincode in other organizations.
Instantiate the chaincode
Prerequisites
You have uploaded and installed the chaincode.
Procedures
Log on to the Alibaba Cloud BaaS console.
On the Overview page, locate My Organizations, locate the target organization, and click the name of the organization.
Click the Chaincodes tab.
Locate the chain code that you want to install. In the Actions column, click Instantiate.
In the dialog box that appears, the system automatically displays the endorsement policy you entered when uploading the chaincode. You can either retain the policy or modify the new policy.
Example:
OR ('Org1MSP.member','Org2MSP.member')
means that endorsement from either of the two organizations in the channel is required; andAND ('Org1MSP.member','Org2MSP.member')
means that endorsements from two organizations in this channel are required .Click Superior in the dialog box, you can enter a collection definition JSON data in Privacy Set Configuration input box(Optional, if chaincode doesn’t use private data feature).
Example:
[{"name": "collectionName", "policy": "OR('Org1MSP.peer')", "memberOnlyRead": false, "requiredPeerCount": 0, "maxPeerCount": 3, "blockToLive": 0}]
means that chaincode needs a private collection namespace namedcollectionName
, and only the peer in organizationOrg1
can access data in this collection.Attention, once
name
andblockToLive
set, you can’t change it anymore in later upgrade. You can visit Using Private Data in Fabric for more information.Click Instantiate.
This operation takes several seconds to several minutes, depending on the complexity of the chaincode dependency. When the operation has been succeeded, the Status in Channel changes from Instantiable to Running, and the value of the Actions column changes to empty.