Use the Hyperledger Fabric SDKs to Develop Applications

Applications use a software development kit (SDK) to access the APIs that permit queries and updates to the ledger. You can install and use the Hyperledger Fabric SDKs to develop applications for Oracle Blockchain Platform.

The REST APIs provided by Oracle Blockchain Platform have been created with maximum flexibility in mind; you can invoke a transaction, invoke a query, or view the status of a transaction. See REST API for Oracle Blockchain Platform.

However this means that you'll likely want to wrap the existing API endpoints in an application to provide object-level control. Applications can contain much more fine-grained operations.

SDK Versions
  • If your Oracle Blockchain Platform founder instances were created using 19.2.3 or later, they support V1.4 of the Hyperledger Fabric SDKs.

Installing the Hyperledger Fabric SDK for Node.js

Information about how to use the Fabric SDK for Node.js can be found here: Hyperledger Fabric SDK for Node.js documentation

On the Developer Tools tab, open the Application Development pane.

Installing the Hyperledger Fabric SDK for Java

Information about how to use the Fabric SDK for Java can be found here: Hyperledger Fabric SDK for Java documentation

On the Developer Tools tab, open the Application Development pane.

Install a build tool such as Apache Maven.

Structuring your Application

Your Java application should be structured similar to the following:

/Application
  /artifacts
    /cypto
      /orderer
        Contains the certificates required for the application to act on the orderer node
        In participant instances only contains TLS certificates
      /peer
        Contains the certificates required for the application to act on the peer node
    /src
      chaincode.go if installing and deploying chaincode to the blockchain
  /java
    pom.xml or other build configuration files
    /resources
      Any resources used by the Java code, including artifacts such as the endorsement policy yaml file and blockchain configuration properties
    /src
      Java source files

Your Node.js application should be structured similar to the following:

/Application
  /artifacts
    /cypto
      /orderer
        Contains the certificates required for the application to act on the orderer node
        In participant instances only contains TLS certificates
      /peer
        Contains the certificates required for the application to act on the peer node
    /src
      chaincode.go if installing and deploying chaincode to the blockchain
  /node
    package.json file
    application.js
    /app
      Any javascript files called by the application
      /tools

Running the application

You’re now ready to run and test the application. In addition to any status messages returned by your application, you can check the ledger in the Oracle Blockchain Platform console to see your changes:

  1. Go to the Channels tab in the console and locate and click the name of the channel running the blockchain.
  2. In the channel’s Ledger pane, view the chaincode’s ledger summary.

Update the Hyperledger Fabric SDKs to Work with Oracle Blockchain Platform

There's an incompatibility between an OCI infrastructure component and the Node.js and Java SDKs provided with Fabric. Follow the steps in this topic to correct this problem.

Methods of updating the Fabric SDKs

There are two ways of updating the SDK:

  • Using Oracle scripts to download and install the Node.js SDK or Java SDK which will patch the code as it installs.

  • Manually as described in this topic.

To use the scripts, on the console’s Developer Tools tab, select the Application Development pane. The links to download both the Node.js SDK and Java SDK have updates built in which will patch the code as it installs.

  • Fabric Java SDK: We’ve created an updated grpc-netty-1.15.0.jar file, which is the module referenced by the Java SDK which requires modifications.

  • Fabric Node.js SDK: We have created the npm_bcs_client.sh script to replace the standard Fabric npm install operations that users would perform to download and install the Node.js Fabric client package. The script runs the same npm command, but it also patched the needed component and rebuilds it.

Manually updating the Fabric Node.js SDK

Do the following to rebuild the grpc-node module to connect the peers and orderers with grpcs client (via tls).
  1. Install fabric-client without executing the grpc module's build script:
    npm install --ignore-scripts fabric-client
  2. Change the code to avoid an alpn error from server side.

    • Change the target code of node_modules/grpc/deps/grpc/src/core/lib/security/security_connector/security_connector.cc
    • Change function ssl_check_peer to something similar to:
      static grpc_error* ssl_check_peer(grpc_security_connector* sc,
                                        const char* peer_name, const tsi_peer* peer,
                                        grpc_auth_context** auth_context) {
        /* Check the ALPN. */
        const tsi_peer_property* p =
            tsi_peer_get_property_by_name(peer, TSI_SSL_ALPN_SELECTED_PROTOCOL);
         if (false) {
          return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
              "Cannot check peer: missing selected ALPN property.");
        }
         if (p != nullptr && !grpc_chttp2_is_alpn_version_supported(p->value.data, p->value.length)) {
          return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
              "Cannot check peer: invalid ALPN value.");
        }
      
        ...
      }
      
    • Change the target code of node_modules/grpc/binding.gyp.
    • Change the variable grpc_alpn to false:
      'grpc_alpn%': 'false'
  3. Rebuild grpc

    npm rebuild --unsafe-perm --build-from-source
You can now install any other modules you need and run the project.

Manually updating the Fabric Java SDK

For fabric-sdk-java, do the following steps to rebuild the grpc-netty package to connect the peers and orderers with grpcs client (via tls). grpc-netty is a sub-project of grpc-java.

  1. Install project dependencies:
    mvn install
  2. Download grpc-java source code:

    git clone https://github.com/grpc/grpc-java.git
  3. Change the code to avoid an alpn error from the server side.
    • Change the target code of grpc-java_root/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java

    • Change function userEventTriggered to something similar to:
      private static class BufferUntilTlsNegotiatedHandler extends AbstractBufferingHandler
            implements ProtocolNegotiator.Handler {
      
          ...
      
          @Override
          public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
            ...
                if (handler.applicationProtocol() == null 
                    || NEXT_PROTOCOL_VERSIONS.contains(handler.applicationProtocol())) {
                  // Successfully negotiated the protocol.
                  logSslEngineDetails(Level.FINER, ctx, "TLS negotiation succeeded.", null);
            ...
        }
      
  4. Build the project to generate the target patched package. Use gradle to build the grpc-java project. Or you can just rebuild the grpc-netty sub-project in the grpc netty directory gradle build.

    After the build is done, you can get the target patched jar package in the directory grpc-java\netty\build\libs\grpc-netty-1.15.0.jar.

  5. Add the patched package into your Maven local repository.

    Replace official grpc-netty jar package with the patched package in either of the following two ways:
    • Use Maven to install the package by local file:
      mvn install:install-file -Dfile=local_patched_grpc_netty_package_root/grpc-netty-1.15.0.jar -DgroupId=io.grpc -DartifactId=grpc-netty -Dversion=1.15.0 -Dpackaging=jar
      You must keep the target groupid, artifactid, and version the same as the package you want to replace.
    • Manually replace your package. Go to the local Maven repository, find the directory where the target package is located, and replace the package with patched package.

  6. Run the project.