All Products
Search
Document Center

Blockchain as a Service:Deploy chaincodes

Last Updated:Jul 13, 2022

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.

Note

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:

    1. Install govendor tool.

      go get -u -v github.com/kardianos/govendor
    2. In chaincode project directory, initialize vendor directory.

      govendor init
    3. Move dependent files in GOPATH to vendor directory.

      govendor add +external
  • You can find more information about chaincode package from: peer chaincode commands.

Tips:

  1. 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.

  2. Omit -l if chaincode language is golang. Use -l node if chaincode language is nodejs, while -l java if chaincode language is Java.

  3. Omit -c if there is no need for input.

  4. 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:

  1. Upload the chaincode

  2. Install the chaincode

  3. Instantiate the chaincode

Upload the chaincode

  1. Log on to the Alibaba Cloud BaaS console.

  2. On the Overview page, locate My Organizations, locate the target organization, and click the name of the organization.

  3. Click the Chaincodes tab.

  4. Click Upload Chaincode.

  5. In the dialog box that appears, upload a chaincode that has been packaged locally.

  6. 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.

  7. Enter the endorsement policy.

    Example: OR ('Org1MSP.peer','Org2MSP.peer')means that endorsement from either of the two organizations in the channel is required, and AND ('Org1MSP.peer','Org2MSP.peer')indicates that endorsements from two organizations in this channel are required.

  8. 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

  1. Log on to the Alibaba Cloud BaaS console.

  2. On the Overview page, locate My Organizations, locate the target organization, and click the name of the organization.

  3. Click the Chaincodes tab.

  4. Locate the chaincode that you want to install, click Install in the Actions column to install the chaincode in the organization.

Install

After the installation is complete, the Status in Organization changes from Uninstalled to Installed, and the Install in the Actions column changed to Instantiate.

  1. 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

  1. Log on to the Alibaba Cloud BaaS console.

  2. On the Overview page, locate My Organizations, locate the target organization, and click the name of the organization.

  3. Click the Chaincodes tab.

  4. Locate the chain code that you want to install. In the Actions column, click Instantiate.

  5. 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; and AND ('Org1MSP.member','Org2MSP.member') means that endorsements from two organizations in this channel are required .

  6. 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 named collectionName, and only the peer in organization Org1 can access data in this collection.

    Attention, once name and blockToLive set, you can’t change it anymore in later upgrade. You can visit Using Private Data in Fabric for more information.

  7. Click Instantiate.

Instantiate the chaincode

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.

Next

Manage users and Access blockchain networks