Help Center > > Developer Guide> Demos> Java SDKs

Java SDKs

Updated at: Apr 21, 2020 GMT+08:00

This section provides a demo application that uses a Java SDK and supports the Chinese cryptographic algorithms.

This demo is used only for scenario experience and is not used in actual applications.




Install an integrated development environment (IDE).

Install Java Development Kit (JDK), Maven, and Eclipse. You can replace Eclipse with another IDE you prefer.

The JDK version must be 1.8 (64-bit). If you have installed JDK, run the java -version command in the command line to check the JDK version.

Buying a BCS Service

  1. Log in to the BCS console.
  2. Click Buy BCS Service in the upper right corner of the page and set the parameters.

    Table 1 Parameters



    Billing Mode

    Select Pay-per-use.


    Retain the default value.

    Enterprise Project

    Select an existing enterprise project, for example, default.

    If you have not enabled the enterprise management service, this parameter is unavailable.

    Service Name

    Enter java-sdk-demo.


    Select Basic. If Chinese cryptographic algorithms must be used, select Enterprise.

    Blockchain Type

    Select Private.

    Consensus Mechanism

    Select Solo.

    Resource Access Initial Password

    Enter a password.

    Confirm Password

    Enter the password again.

    Advanced Settings

    Select Configure.


    Select Create a new CCE cluster.


    Select an AZ.

    ECS Specifications

    Select the flavor of 4 vCPUs | 8 GB.

    ECS Quantity

    Enter 1.

    High Availability

    Select No.


    Select Automatically create VPC.


    Select Automatically create subnet.

    ECS Login Method

    Select Password.

    Password of Root User

    If you do not enter a password here, the previously specified resource access initial password will be used.

    Confirm Password


    Blockchain Mgmt. Initial Password

    If you do not enter a password here, the previously specified resource access initial password will be used.

    Confirm Password



    Retain the default value.

    Volume Type

    Select SFS Turbo.

    Peer Organization

    A peer organization named organization has been automatically created. Change the peer quantity to 1.

    Orderer Quantity

    Retain the default value 1.

    Enable Data Aging on Orderers

    Select No.

    Security Mechanism

    Select ECDSA.


    The Chinese cryptographic algorithms option is available. If you select this option, other modifications are required for the demo deployment. Pay attention to the descriptions of modifications.

    Storage Capacity of Peer Organization

    Retain the default value.

    Ledger Storage

    Select File database (goleveldb).

    Channel Configuration

    The organization organization has been added to the channel automatically. Retain this default setting.

    Enable Support for RESTful APIs

    Select No.

    Use EIP

    Select Yes.

    EIP Billed By

    Select Bandwidth.

    EIP Bandwidth

    Retain the default value.

    Configure Block Generation

    Select No.

  3. Click Next, confirm the configurations, and click Submit. If the status of the service and organization is Normal, the service has been successfully created.

Installing and Instantiating a Chaincode

  1. Click Manage Blockchain in the Operation column of the BCS service you just created.

  2. On the login page, enter the username, password, and verification code, and click Log In.

    The username is admin, and the password is the Blockchain Mgmt. Initial Password set when you bought the BCS service. If you have not set this password, use the resource access initial password.

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

    The parameters for chaincode installation are as follows.



    Chaincode Name

    Enter chaincode.

    Chaincode Version

    Enter 2.0.

    Ledger Storage

    File database (goleveldb)

    Select All Peers

    Select the checkbox.

    Organization & Peer

    Select peer-0.


    Select Golang.

    Chaincode File

    Add the downloaded chaincode file

    Chaincode Description

    Enter a description of the chaincode.

  4. Click Install to install the chaincode.
  5. After installing the chaincode, click Instantiate in the Operation column of the chaincode list.

    The parameters for chaincode instantiation are as follows.



    Chaincode Name



    Select channel.

    Chaincode Version

    Select 2.0.

    Initialization Function

    Enter init.

    Chaincode Parameters

    Enter a,200,b,250.

    Endorsement Policy

    Select Endorsement from any of the following organizations.

    Endorsing Organizations

    Select organization.

    Privacy Protection

    Select No.

  6. Click Instantiate.

    Wait for 2 to 3 minutes and refresh the page. Click View more in the Instantiation column to check the instantiation status.

Configuring the Application

  1. Import the project.

    Download and decompress the project code. Right-click in Eclipse and choose Import from the shortcut menu to import the javasdkdemo file (Maven project) to Eclipse.

  2. Download the SDK configuration.

    Click More > Download SDK Configuration in the Operation column on the Service Management page.

    Set the SDK file parameters.



    Chaincode Name

    Enter chaincode.


    The chaincode name and version must be the same as those specified for chaincode installation and instantiation.

    Chaincode Version

    Enter 2.0.

    Certificate Root Path

    Enter the path to the config folder of the javasdkdemo project.


    Backslashes (\) in the path must be changed to slashes (/), for example, D:/javasdkdemo/config.




    Retain the default value.

    Click Download and the SDK file will be saved to the config directory of the demo project. The file name is

    The Certificate Root Path specified in the SDK configuration parameters is not the download path of the SDK file. If you do not specify a path for downloading the SDK file, the SDK file will be stored in the default download path of your system.

  3. Download certificates.

    Download the administrator certificates of organizations java-sdk-demo-orderer and organization on the Service Management page, and save them to the config directory of the demo project.

  4. Copy and decompress the packages.

    If no download path is specified, copy,, and from the default download path to the config directory of the demo project and decompress the packages.

Deploying the Application

  1. Find the file in the /javasdkdemo/src/main/java/handler/ directory, and change the file path in the following code of the Main class to the absolute path of the java-sdk-demo-sdk-config.yaml file. Change the backslashes (\) to slashes (/).


    If Chinese cryptographic algorithms is selected for the BCS service, add the dependency upon fabric-sdk-java-1.4.0-jar-with-dependencies.jar in the lib folder of the project to pom.xml because Chinese cryptographic algorithms need to refer to the fabric-sdk dependency package of Huawei. To add the dependency, remove the comments on the dependency as shown in the following figure.

  2. Run the main function.

    Each execution of the main function represents a transaction in which user A transfers money (100) to user B, as shown in the following figure.

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?

Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel