I am currently digging into Hyperledger Fabric and I can't get stuff started with the Java SDK (talking about 1.0.0-beta here). Is there a working example starting from connecting to the Fabric node, doing queries, etc? All I found so far through extensive googling are "let's-write-some-chaincode" examples.
You can take a look at the following
- Java SDK for Hyperledger Fabric 2.2. In this, there are two files given in the folder "fabric-sdk-java/src/test/java/org/hyperledger/fabric/sdkintegration/" ==> End2endAndBackAgainIT.java, End2endIT.java. This can help.
Update on 2020-June-07
The link above Java SDK for Hyperledger Fabric 2.2, is a low level SDK for interacting with Hyperledger Fabric.
If your purpose is building Hyperledger Fabric blockchain client applications, then its recommended to use the Hyperledger Fabric Gateway SDK for Java, a high level API. Its very simple to use, just refer to the code snippet from [2.2]. please refer to the link how to use
// code snippet from [2.2]
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 for both 1.4 and 2.2 are available.
As of Hyperledger Fabric v2.4 release, Fabric SDK for JAVA has been deprecated Ref. github link. For developing client applications, please use Fabric Gateway Client API Getting started : Fabric Gateway. Please note that Client SDK does not have Deployment capabilities.