Updated on 2023-09-19 GMT+08:00

Invoking Chaincodes

Prerequisites

  • JDK has been installed and the Java development environment has been configured. The JDK version must be 1.8 (64-bit). If you have installed JDK, run the java -version command to check the JDK version.
  • Log in to the BCS console and click Use Cases. Download the example Java chaincode in the Getting Started area. In Windows, download and decompress the package to C:/javasdkdemo. In Linux, download and decompress the package to /root/javasdkdemo.

Configuring the Application

  1. On the Instance Management page, click Download Client Configuration on an instance card.
  2. Select SDK Configuration File, and enter the chaincode name and certificate path. Retain the default values for other parameters.

    • The chaincode name must be the same as the name specified during chaincode installation and instantiation, for example, chaincodedemo.
    • The certificate path is the final path for storing the certificate for application compilation. If the certificate path changes, you must manually change all certificate paths in the SDK configuration file.

      Windows: C:/javasdkdemo/config

      Linux: /root/javasdkdemo/config

  3. Select Orderer Certificate.
  4. Select Peer Certificates, select organization for Peer Organization, and select Administrator certificate.
  5. Click Download to download the SDK configuration file and the administrator certificates for the demo-orderer and organization organizations.

    • The BCS instance name is demo, so the name of the .yaml file in the downloaded SDK configuration file is demo-channel-sdk-config.yaml.
    • If you use another name, for example, bcs123, the name of the .yaml file in the downloaded SDK configuration file will be bcs123-channel-sdk-config.yaml. You must manually change the file name to demo-channel-sdk-config.yaml.

  6. Decompress demo-config.zip and copy the orderer and peer folders and the sdk-config.json and sdk-config.yaml files to the config directory where the demo is stored (C:/javasdkdemo/config in Windows and /root/javasdkdemo/config in Linux).

    The demo-channel-sdk-config.yaml file must exist in the config directory of the javasdkdemo project.

Deploying the Application

  1. Go to the directory where the demo is stored (C:/javasdkdemo in Windows and /root/javasdkdemo in Linux) and run the following command:

    java -jar javasdkdemo.jar

    Each time the command is successfully executed, the key-value pair <testuser,100> is saved to the blockchain. If you query key testuser, the value is 100.

    The command output is as follows:

    Figure 1 Execution result

  2. View the results in the Block Browser.

    Figure 2 Viewing the results