Help Center/ Blockchain Service/ Getting Started/ Installing and Instantiating a Chaincode
Updated on 2023-09-19 GMT+08:00

Installing and Instantiating a Chaincode

To obtain the chaincode file used in the example, go to the BCS console and click Use Cases. Download the example Go chaincode in the Getting Started area.

Installing a Chaincode

  1. Click Manage Blockchain on the card of the BCS instance you just created.
  2. On the login page, enter the username and password, and click Log In.

    The username is admin, and the password is the Blockchain Mgmt. Initial Password set when you created the BCS instance. If you have not set this password, use the resource access initial password. For details, see Purchasing a BCS Instance. For security purposes, change the password periodically.

  3. Click Install Chaincode in the upper left corner of the page.

  4. Enter the chaincode name and version number, select the peers where the chaincode is to be installed, specify the programming language of the chaincode, and add the chaincode file.

    Table 1 Chaincode installation configurations

    Parameter

    Description

    Chaincode Name

    Enter chaincodedemo

    Chaincode Version

    Enter 1.0

    Ledger Storage

    Default option: File database (goleveldb).

    Peer

    Manually select organizations and peers.

    Language

    Select Golang.

    Chaincode File

    Add a chaincode file. To obtain the chaincode file used in the example, go to the BCS console and click Use Cases. Download the example Go chaincode in the Getting Started area.

    Chaincode Description

    Enter a description of the chaincode.

    Code Security Check

    This option is displayed only when the chaincode language is Golang. Enable this option to check code security.

    Figure 1 Installing a Chaincode

  5. Click Install.
  6. Click next to a chaincode name to view the details.
  7. Click Download in the Operation column to view the check result. (The following example is for reference only.)

    If Code Security Check is not enabled, no check report will be generated, and the Download button will not be displayed.

    Figure 2 Downloading the check report
    1. Decompress the package and open the HTML file to view the check result details. There are three types of issues: error, warning, and info. Error-level issues must be resolved. Otherwise, the chaincode functions will be affected. Warning-level issues can be handled by reconstructing the code. Info-level issues can be handled selectively as required.
      Figure 3 Scanned files
    2. For example, there is an info-level issue in the proceeding figure. You can click the issue to view its details, including a brief description, wrong example, scanning details, modification advice, and revision example.

      Modify the code based on the chaincode check result and update the chaincode or install it again.

Instantiating a Chaincode

  1. After installing the chaincode, click Instantiate in the Operation column that contains a target chaincode.

  2. Specify the channel, chaincode version, initialization function, endorsement policy, endorsing organizations, and other parameters.

  3. Click Instantiate. Wait 2 to 3 minutes for the instantiation on the specified channel to complete.