The Fabric Gateway client API allows applications to interact with a Hyperledger Fabric blockchain network. It implements the Fabric programming model, providing a simple API to submit transactions to a ledger or query the contents of a ledger with minimal code.
Samples showing how to create client applications that connect to and interact with a Hyperledger Fabric network, are available in the fabric-samples repository:
- asset-transfer-basic for examples of transaction submit and evaluate.
- asset-transfer-events for examples of chaincode eventing.
- off_chain_data for examples of block eventing.
The Gateway client API documentation for Java is available here:
The Fabric Gateway client API package is published to Maven Central.
Add the following dependency to your project's pom.xml
file:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-bom</artifactId>
<version>4.29.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hyperledger.fabric</groupId>
<artifactId>fabric-gateway</artifactId>
<version>1.7.0</version>
</dependency>
</dependencies>
Note the pom import in the dependencyManagement
section, which ensures that v4 of the Java protocol buffers package is resolved by your project.
A suitable gRPC channel service provider must also be specified (as described in the gRPC security documentation), such as:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-bom</artifactId>
<version>1.69.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-api</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
Add the following dependency to your project's build.gradle
file:
implementation 'org.hyperledger.fabric:fabric-gateway:1.7.0'
implementation platform('com.google.protobuf:protobuf-bom:4.29.2')
Note the platform import, which ensures that v4 of the Java protocol buffers package is resolved by your project.
A suitable gRPC channel service provider must also be specified (as described in the gRPC security documentation), such as:
implementation platform('io.grpc:grpc-bom:1.69.0')
compileOnly 'io.grpc:grpc-api'
runtimeOnly 'io.grpc:grpc-netty-shaded'
This API requires Fabric v2.4 (or later) with a Gateway enabled Peer. Additional compatibility information is available in the documentation: