# fabric-gateway-java **Repository Path**: Ace.com/fabric-gateway-java ## Basic Information - **Project Name**: fabric-gateway-java - **Description**: Hyperledger Fabric Gateway SDK for Java https://wiki.hyperledger.org/display/fabric - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2022-09-02 - **Last Updated**: 2024-07-11 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 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](https://hyperledger-fabric.readthedocs.io/en/latest/developapps/developing_applications.html) chapter of the Fabric documentation. > **Note:** When developing applications for Hyperledger Fabric v2.4 and later, you are strongly encouraged to use the new [Fabric Gateway client API](https://hyperledger.github.io/fabric-gateway/). ## 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). ```java 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: - [2.2](https://hyperledger.github.io/fabric-gateway-java/release-2.2/) - [1.4](https://hyperledger.github.io/fabric-gateway-java/release-1.4/) ### Maven Add the following dependency to your project's `pom.xml` file: ```xml