io.github.ecsoya:fabric-gateway-spring-boot-starter

Provided Springboot starter for spring-fabric-gateway based on fabric-gateway-java (https://github.com/hyperledger/fabric-gateway-java)

License

License

Categories

Categories

Spring Boot Container Microservices
GroupId

GroupId

io.github.ecsoya
ArtifactId

ArtifactId

fabric-gateway-spring-boot-starter
Last Version

Last Version

2.0.2
Release Date

Release Date

Type

Type

jar
Description

Description

Provided Springboot starter for spring-fabric-gateway based on fabric-gateway-java (https://github.com/hyperledger/fabric-gateway-java)
Project URL

Project URL

https://github.com/ecsoya/spring-fabric-gateway
Source Code Management

Source Code Management

https://github.com/hyperledger/fabric-gateway-java

Download fabric-gateway-spring-boot-starter

How to add to project

<!-- https://jarcasting.com/artifacts/io.github.ecsoya/fabric-gateway-spring-boot-starter/ -->
<dependency>
    <groupId>io.github.ecsoya</groupId>
    <artifactId>fabric-gateway-spring-boot-starter</artifactId>
    <version>2.0.2</version>
</dependency>
// https://jarcasting.com/artifacts/io.github.ecsoya/fabric-gateway-spring-boot-starter/
implementation 'io.github.ecsoya:fabric-gateway-spring-boot-starter:2.0.2'
// https://jarcasting.com/artifacts/io.github.ecsoya/fabric-gateway-spring-boot-starter/
implementation ("io.github.ecsoya:fabric-gateway-spring-boot-starter:2.0.2")
'io.github.ecsoya:fabric-gateway-spring-boot-starter:jar:2.0.2'
<dependency org="io.github.ecsoya" name="fabric-gateway-spring-boot-starter" rev="2.0.2">
  <artifact name="fabric-gateway-spring-boot-starter" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.github.ecsoya', module='fabric-gateway-spring-boot-starter', version='2.0.2')
)
libraryDependencies += "io.github.ecsoya" % "fabric-gateway-spring-boot-starter" % "2.0.2"
[io.github.ecsoya/fabric-gateway-spring-boot-starter "2.0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
org.springframework.boot : spring-boot-autoconfigure jar
io.github.ecsoya : spring-fabric-gateway jar 2.0.2
org.springframework.boot : spring-boot-configuration-processor Optional jar

Project Modules

There are no modules declared in this project.

Hyperledger Fabric Gateway SDK for Java

Branch Build status
main
release-2.2
release-1.4

The Fabric Gateway SDK allows applications to interact with a Fabric blockchain network. It provides a simple API to submit transactions to a ledger or query the contents of a ledger with minimal code.

The Gateway SDK implements the Fabric programming model as described in the Developing Applications chapter of the Fabric documentation.

How to use

The following shows a complete code sample of how to connect to a fabric network, submit a transaction and query the ledger state using an instantiated smart contract (fabcar sample).

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.TimeoutException;

import org.hyperledger.fabric.gateway.Contract;
import org.hyperledger.fabric.gateway.ContractException;
import org.hyperledger.fabric.gateway.Gateway;
import org.hyperledger.fabric.gateway.Network;
import org.hyperledger.fabric.gateway.Wallet;
import org.hyperledger.fabric.gateway.Wallets;

class Sample {
    public static void main(String[] args) throws IOException {
        // Load an existing wallet holding identities used to access the network.
        Path walletDirectory = Paths.get("wallet");
        Wallet wallet = Wallets.newFileSystemWallet(walletDirectory);

        // Path to a common connection profile describing the network.
        Path networkConfigFile = Paths.get("connection.json");

        // Configure the gateway connection used to access the network.
        Gateway.Builder builder = Gateway.createBuilder()
                .identity(wallet, "user1")
                .networkConfig(networkConfigFile);

        // Create a gateway connection
        try (Gateway gateway = builder.connect()) {

            // Obtain a smart contract deployed on the network.
            Network network = gateway.getNetwork("mychannel");
            Contract contract = network.getContract("fabcar");

            // Submit transactions that store state to the ledger.
            byte[] createCarResult = contract.createTransaction("createCar")
                    .submit("CAR10", "VW", "Polo", "Grey", "Mary");
            System.out.println(new String(createCarResult, StandardCharsets.UTF_8));

            // Evaluate transactions that query state from the ledger.
            byte[] queryAllCarsResult = contract.evaluateTransaction("queryAllCars");
            System.out.println(new String(queryAllCarsResult, StandardCharsets.UTF_8));

        } catch (ContractException | TimeoutException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}

API documentation

Full Javadoc documentation is published for each of the following versions:

Maven

Add the following dependency to your project's pom.xml file:

<dependency>
  <groupId>org.hyperledger.fabric</groupId>
  <artifactId>fabric-gateway-java</artifactId>
  <version>2.2.0</version>
</dependency>

Gradle

Add the following dependency to your project's build.gradle file:

implementation 'org.hyperledger.fabric:fabric-gateway-java:2.2.0'

Compatibility

The following table shows versions of Fabric, Java and other dependencies that are explicitly tested and that are supported for use with version 2.2 of the Fabric Gateway SDK. Refer to the appropriate GitHub branch for compatibility of other release versions.

Tested Supported
Fabric 2.2 2.2
Java 8, 11 8+
Platform Ubuntu 20.04

Client applications running on POWER architecture

To run Java SDK clients on IBM POWER systems (e.g. zLinux), use Java 11 and set the SSL provider to ‘JDK’ by either supplying the -D command line option:

-Dorg.hyperledger.fabric.sdk.connections.ssl.sslProvider=JDK

or with the environment variable set as follows:

ORG_HYPERLEDGER_FABRIC_SDK_CONNECTIONS_SSL_SSLPROVIDER=JDK

Building and testing

git clone https://github.com/hyperledger/fabric-gateway-java.git
cd fabric-gateway-java
mvn install

The mvn install command will download the dependencies and run all the unit tests and scenario tests. It will also generate all the crypto material required by these tests.

Docker is required to run the scenario tests.

Unit tests

All classes and methods have a high coverage (~90%) of unit tests. These are written using the JUnit, AssertJ and Mockito frameworks.

Scenario tests

Scenario tests are written using the Cucumber BDD framework.

io.github.ecsoya

Hyperledger

Versions

Version
2.0.2
2.0.1
2.0.0
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0