I'm using Hyperledger Fabric Gateway SDK for Java to connect my local HLF network, available by default with IBM blockchain platform extension for VSCode. I have deployed a smart contract from Create-BlockchainNetwork-IBPV20 example (https://github.com/IBM/Create-BlockchainNetwork-IBPV20/blob/master/README.md). It works well with Node.js client, being able to submit and query the data.
The issue comes when I do the same in Java. I'm able to connect and even query the data, but when trying to submit a transaction I receive the following error:
Exception in thread "main" org.hyperledger.fabric.gateway.ContractException: Failed to send transaction to the orderer
at org.hyperledger.fabric.gateway.impl.TransactionImpl.commitTransaction(TransactionImpl.java:145)
at org.hyperledger.fabric.gateway.impl.TransactionImpl.submit(TransactionImpl.java:96)
at org.hyperledger.fabric.gateway.impl.ContractImpl.submitTransaction(ContractImpl.java:50)
at com.dai.mastexport.mavenproject1.NewClass.main(NewClass.java:80)
Caused by: java.util.concurrent.ExecutionException: java.lang.Exception: Channel mychannel failed to place transaction 8eb41fb6477ee8162bfcedf28be255bb508043c1811794c761e42a359b31c682 on Orderer. Cause: UNSUCCESSFUL.
at java.util.concurrent.CompletableFuture.reportGet(CompletableFuture.java:357)
at java.util.concurrent.CompletableFuture.get(CompletableFuture.java:1915)
at org.hyperledger.fabric.gateway.impl.TransactionImpl.commitTransaction(TransactionImpl.java:139)
... 3 more
Caused by: java.lang.Exception: Channel mychannel failed to place transaction 8eb41fb6477ee8162bfcedf28be255bb508043c1811794c761e42a359b31c682 on Orderer. Cause: UNSUCCESSFUL.
at org.hyperledger.fabric.sdk.Channel.doSendTransaction(Channel.java:5722)
at org.hyperledger.fabric.sdk.Channel.sendTransaction(Channel.java:5533)
at org.hyperledger.fabric.gateway.impl.TransactionImpl.commitTransaction(TransactionImpl.java:138)
... 3 more
Caused by: java.lang.Exception: Channel mychannel unsuccessful sendTransaction to orderer localhost:17076 (grpc://localhost:17076)
at org.hyperledger.fabric.sdk.Channel.doSendTransaction(Channel.java:5704)
... 5 more
Caused by: org.hyperledger.fabric.sdk.exception.TransactionException: Channel mychannel, send transactions failed on orderer OrdererClient{id: 6, channel: mychannel, name: localhost:17076, url: grpc://localhost:17076}. Reason: timeout after 10000 ms.
at org.hyperledger.fabric.sdk.OrdererClient.sendTransaction(OrdererClient.java:223)
at org.hyperledger.fabric.sdk.Orderer.sendTransaction(Orderer.java:164)
at org.hyperledger.fabric.sdk.Channel.doSendTransaction(Channel.java:5686)
... 5 more
Same Java code works well if I'm connecting to IBM Blockchain on the Cloud. Here is my code for the reference:
public class NewClass {
static {
System.setProperty("org.hyperledger.fabric.sdk.service_discovery.as_localhost", "true");
}
public static void main(String[] args) throws Exception {
String userName = "admin";
String pass = "adminpw";
String msp = "Org1MSP";
String orgName = "Org1MSP";
String channelName = "mychannel";
String connFile = "connection_test.json";
java.nio.file.Path walletDirectory = java.nio.file.Paths.get("../wallets");
Wallet wallet = Wallets.newFileSystemWallet(walletDirectory);
java.nio.file.Path netConfPath = java.nio.file.Paths.get("../conf", connFile);
// Create a CA client for interacting with the CA.
NetworkConfig netConf = NetworkConfig.fromJsonFile(netConfPath.toFile());
HFCAClient caClient = HFCAClient.createNewInstance(netConf.getOrganizationInfo(orgName).getCertificateAuthorities().get(0));
CryptoSuite cryptoSuite = CryptoSuiteFactory.getDefault().getCryptoSuite();
caClient.setCryptoSuite(cryptoSuite);
// Check to see if we've already enrolled the admin user.
Identity user = wallet.get(userName);
if (user == null) {
// Enroll the admin user, and import the new identity into the wallet.
Enrollment enrollment = caClient.enroll(userName, pass);
user = Identities.newX509Identity(msp, enrollment);
wallet.put(userName, user);
}
Gateway.Builder builder = Gateway.createBuilder();
builder.identity(wallet, userName).networkConfig(netConfPath).discovery(true);
// create a gateway connection
try (Gateway gateway = builder.connect()) {
Network net = gateway.getNetwork(channelName);
Contract contract = net.getContract("blockchain-network");
byte[] result = contract.submitTransaction("AddTrader", "traderA", "Mike", "Smith");
System.out.println(new String(result));
}
}
}
I've tried different versions of SDK with no luck. What I've noticed so far is that my connection profile from the local network has no pem information, compared to the one from cloud. Here is local profile:
{
"certificateAuthorities": {
"Org1CA": {
"caName": "ca",
"url": "http://localhost:17050"
}
},
"client": {
"connection": {
"timeout": {
"orderer": "3000",
"peer": {
"endorser": "3000"
}
}
},
"organization": "Org1MSP"
},
"name": "Org1",
"organizations": {
"Org1MSP": {
"certificateAuthorities": [
"Org1CA"
],
"mspid": "Org1MSP",
"peers": [
"Org1Peer1"
]
}
},
"peers": {
"Org1Peer1": {
"url": "grpc://localhost:17051"
}
},
"version": "1.0.0"
}