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 flexibility 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

Multiple versions of the Hyperledger Fabric SDKs are available. Use the version of the SDK that matches the version of Hyperledger Fabric that your instance is based on.

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. You can install the Hyperledger Fabric Node.js SDK by using the link on this tab.

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

Structure your Java application similar to the following example:

/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

Structure your Node.js application similar to the following example:

/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 then locate and click the name of the channel running the chaincode.
  2. In the channel’s Ledger pane, view the chaincode’s ledger summary.

Update the Hyperledger Fabric v2.x SDKs to Work with Oracle Blockchain Platform

There's an incompatibility between an OCI infrastructure component and the Java SDK provided with Hyperledger Fabric v2.x. Follow the steps in this topic to correct this problem.

Methods of updating the Hyperledger Fabric SDK

There are two ways of updating the SDK:

  • Download the modified package from the console. We’ve created an updated grpc-netty-shaded-1.38.0.jar file, which is the module referenced by the Java SDK that requires modifications.
  • Build the package manually, as described in this topic.

To download the grpc-netty-shaded-1.38.0.jar file, click the console’s Developer Tools tab, and then select the Application Development pane.

Manually building the package

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

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

    git clone https://github.com/grpc/grpc-java.git
  3. Find the grpc version that your fabric-sdk-java uses, and check out the code.
    In the grpc-java directory, check out the version of grpc that fabric-sdk-java uses:
    cd grpc-java && git checkout v1.38.0
  4. Change the code to avoid an alpn error from the server side. Create a grpc-java-patch patch file with the following contents:
    diff --git a/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java b/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java
    index 19d3e01b7..ebc4786a3 100644
    — a/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java
    +++ b/netty/src/main/java/io/grpc/netty/ProtocolNegotiators.java
    @@ -611,7 +611,8 @@ final class ProtocolNegotiators {
    SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt;
    if (handshakeEvent.isSuccess()) {
    SslHandler handler = ctx.pipeline().get(SslHandler.class);
    
        if (sslContext.applicationProtocolNegotiator().protocols()
        + if (handler.applicationProtocol() == null
        + || sslContext.applicationProtocolNegotiator().protocols()
        .contains(handler.applicationProtocol())) {
        // Successfully negotiated the protocol.
        logSslEngineDetails(Level.FINER, ctx, "TLS negotiation succeeded.", null);
  5. Apply the patch:

    git apply grpc-java.patch
  6. Build the project to generate the target patched package. Use gradle to build the grpc-java-shaded project:

    cd netty/shaded
    gradle build -PskipAndroid=true -PskipCodegen=true

    After the build completes, the target patched .jar package is available at grpc-java/netty/build/libs/grpc-netty-shaded-1.38.0.jar.

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

    Replace the original grpc-netty-shaded .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=grpc-netty-shaded-build/grpc-netty-shaded-1.38.0.jar -DgroupId=io.grpc -DartifactId=grpc-netty-shaded -Dversion=1.38.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.

  8. Run the project.