All Products
Search
Document Center

Initialize the client

Last Updated: Jul 23, 2019

Prerequisites

You have already applied to join the blockchain.

You have built the environment. For how to build the environment, see: MacOS Windows.

The notary blockchain will be offline on October 17, 2019. For a better experience, please use the contract blockchain, which has all the functions of the notary blockchain and better performance.

Configuration file

The client needs to configure basic information. Detailed configuration can be found in the sdk.properties file. The simplest configuration includes the following.

Determine the primary node for the client to connect to, and the alternate node addresses to use when the primary node is inavailable.

In addition, the client connects to the node using TLS mutual authentication, which requires the x509 certificate to be configured. Replace ssl_key_password with the password you set when you created the private key.

  1. # The address of the primary node to which the client is connected. One and only one primary node can be configured
  2. biz.sdk.primary=### IP configuration does not need to be modified ###
  3. # The API address of the backup node. You can configure n backup nodes, where n=3f : f=1,2.
  4. # When the primary node cannot be connected, the system switches to "connect to the backup node". When the primary node recovers, it automatically switches back to "connect to the primary node"
  5. Jolla. SDK. Backups =### IP configuration does not need to be modified ###
  6. # The client connects to the node using TLS mutual authentication, which requires the x509 certificate to be configured
  7. # The absolute path of the SSL private key files in pkcs8 format
  8. biz.sdk.ssl_key=/path/key_pkcs8.pem
  9. # The absolute path of the SSL certificate files in x509 format
  10. biz.sdk.ssl_cert=/path/cert.pem
  11. # The SSL private key password set when the private key is created
  12. biz.sdk.ssl_key_password=******
  13. # The absolute path of the TrustStore file
  14. biz.sdk.trust_store=/path/trust.keystore
  15. # The trust store password, which defaults to mychain, and does not need to be changed
  16. biz.sdk.trust_store_password=mychain

The configuration above contains three files, where ssl_key is the private key certificate, ssl_cert is the signature certificate, and trust_store can be obtained from the download link of the BaaS platform. Whether these files are filled in or not depends on how you initialize the client. You can save the files locally and pass them to the client as configured above, or initialize the client by ClassLoader loading or other input streams, such as the network IO.

Initialize the client

This document will provide you with a utility class DefaultClientPropertyConfig, with which two methods can be used to initialize the client.

The first method is to read the sdk.properties configuration file to initialize the client. DefaultClientPropertyConfig first finds the corresponding file from the path configured by biz.sdk.ssl_key, biz.sdk.ssl_cert and biz.sdk.trust_store. If the file is found, the client is initialized with the file content. If not, DefaultClientPropertyConfig finds the files named “sslkey.pem”, “sslcert.pem” and “trust.keystore” in the class path and loads the resources through the ClassLoader to initialize the client.

  1. // Load the client configuration file
  2. Properties p = new Properties();
  3. p.load(new FileInputStream("/path/sdk.properties"));
  4. ClientConfig config = new DefaultClientPropertyConfig(p);
  5. // Initialize the client using the specified client configuration
  6. Client client = new Client(config);

Next, you can use the client to notarize data writes