Skip to content
No description, website, or topics provided.
Java JavaScript Gherkin Shell
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
scripts/ci_scripts FGJ-30: Publish to Maven with correct group ID Jul 14, 2019
src FGJ-32: Allow endorsing peers to be specified Aug 6, 2019
.gitignore FGJ-15 Support service discovery Apr 29, 2019
.gitreview Port to Docker Image Aug 7, 2019
CODEOWNERS [FAB-16489] Add CODEOWNERS Aug 31, 2019 FGJ-29 Add licence file etc Jul 3, 2019
Jenkinsfile Port to Docker Image Aug 7, 2019
LICENSE FGJ-29 Add licence file etc Jul 3, 2019 Additional project content Jul 17, 2019 FABCI-314 Add CI jobs for gateway-java Apr 4, 2019

Hyperledger Fabric Gateway SDK for Java

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).

package org.example;

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;

public final 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 = Wallet.createFileSystemWallet(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")

        // 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.submitTransaction("createCar", "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 e) {

API documentation

Full Javadoc documentation of the SDK is published here.


Depend on development snapshots with the following pom.xml entries:




Depend on development snapshots with the following build.gradle entries:

repositories {
    maven {
        url ''

dependencies {
    implementation 'org.hyperledger.fabric-gateway-java:fabric-gateway-java:1.4.0-SNAPSHOT'

Building and testing

git clone
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. For the tests to locate the peer, orderer and certificate authority containers running locally, the following entries are required in the local hosts file:

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.

You can’t perform that action at this time.