1

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"
}
AlexSV
  • 111
  • 1
  • Not having any pem information is expected when trying to connect to a fabric created by the IBM blockchain extension. The logs you provide say that there is some issue submitting the transaction to the orderer. I assume you have tried tearing down the local fabric and re-starting it ? – david_k Apr 23 '20 at 07:14
  • Yes, I was trying to tear down and restart and create new environment from template. Same error every time. In debug I can see that response is received from the peers, but next step sending to the orderer fails. As I've mentioned before using Node.js client with the same connection profile, runs with no issues. – AlexSV Apr 23 '20 at 07:50
  • So it potentially is an issue with the java sdk then, you might want to raise an issue on jira about it https://jira.hyperledger.org and maybe you could try raising an issue with the vscode extension team at https://github.com/IBM-Blockchain/blockchain-vscode-extension although they could come back and say this is an issue with the sdk, but maybe they can see if they get the same problem ? – david_k Apr 23 '20 at 12:11
  • Have you solved the issue? I'm having a similar problem – Eduardo Pascual Aseff May 28 '20 at 22:39
  • Since I was doing some kind of PoC, I couldn't wait for fixing this issue. So, I simply switched to Node SDK and was able to implement all functions of my app. – AlexSV May 29 '20 at 14:16
  • Hi All, I was also facing issue. I have used fabric-gateway-java 2.2.0 version. I had network file in yaml format. But due to incorrect way of adding orderer block in yaml file, my orderer was not getting adding to network hence transaction were not going to channel. So if anyone facing same issue. Please do check yaml also. Thanks – Shobhit Srivastava Dec 23 '21 at 04:51

0 Answers0