Hyperledger Fabric V1 0 Application using Java SDK Client for is waiting indefinitely when invoking chaincode

0 votes

I have my Hyperledger Fabric V1.0 network up and running by following the steps Building Your First Network. And now I am able to create channel, install/instatiate/invoke/query chaincode etc. Now I am trying to create some assets and query the same using Java SDK Client. I have created the following methods to invoke and query the chaincode from my java application.

void createChannel() throws InvalidArgumentException, TransactionException, IOException, ProposalException{
    Properties ordererProperties = getOrdererProperties("orderer.example.com");
    ordererProperties.put("grpc.NettyChannelBuilderOption.keepAliveTime", new Object[] {5L, TimeUnit.MINUTES});
    ordererProperties.put("grpc.NettyChannelBuilderOption.keepAliveTimeout", new Object[] {8L, TimeUnit.SECONDS});
    Orderer orderer = client.newOrderer("orderer.example.com", "grpcs://",ordererProperties);

    Properties peerProperties = getPeerProperties("peer0.org1.example.com"); //test properties for peer.. if any.
    if (peerProperties == null) {
        peerProperties = new Properties();
    peerProperties.put("grpc.NettyChannelBuilderOption.maxInboundMessageSize", 9000000);
    Peer peer = client.newPeer("peer0.org1.example.com", "grpcs://",peerProperties);
    channel = client.newChannel("testchannel");

void creteTransactionalProposal(){
    proposalRequest = client.newTransactionProposalRequest();
    final ChaincodeID chaincodeID = ChaincodeID.newBuilder()

    proposalRequest.setArgs(new String[]{"a1", "a1_val"});

void sendProposal() throws ProposalException, InvalidArgumentException, InterruptedException, ExecutionException{
    final Collection<ProposalResponse> responses = channel.sendTransactionProposal(proposalRequest);
    CompletableFuture<BlockEvent.TransactionEvent> txFuture = channel.sendTransaction(responses, client.getUserContext());
    BlockEvent.TransactionEvent event = txFuture.get();//waiting indefinitely

void query() throws InvalidArgumentException, ProposalException{
     final ChaincodeID chaincodeID = ChaincodeID.newBuilder()

    QueryByChaincodeRequest queryByChaincodeRequest = client.newQueryProposalRequest();
    queryByChaincodeRequest.setArgs(new String[] {"a1"});

    Map<String, byte[]> tm2 = new HashMap<>();
    tm2.put("HyperLedgerFabric", "QueryByChaincodeRequest:JavaSDK".getBytes(UTF_8));
    tm2.put("method", "QueryByChaincodeRequest".getBytes(UTF_8));

    Collection<ProposalResponse> queryProposals = channel.queryByChaincode(queryByChaincodeRequest, channel.getPeers());
    for (ProposalResponse proposalResponse : queryProposals) {
        if (!proposalResponse.isVerified()
                || proposalResponse.getStatus() != ProposalResponse.Status.SUCCESS) {
            System.out.println("Failed query proposal from peer " + proposalResponse.getPeer().getName() + " status: "
                    + proposalResponse.getStatus() + ". Messages: " + proposalResponse.getMessage()
                    + ". Was verified : " + proposalResponse.isVerified());
        } else {
            String payload = proposalResponse.getProposalResponse().getResponse().getPayload()
            System.out.printf("\nQuery payload of b from peer %s returned %s", proposalResponse.getPeer().getName(),
            //assertEquals(payload, expect);

I am able to create Asset by calling


But the line BlockEvent.TransactionEvent event = txFuture.get();makes the application in an indefinite waiting state even after the completion of the transaction commit to ledger. Why it is behaving like this?

Once I to force exit and run the query() method it is listing the asset.

Jul 16, 2018 in Blockchain by sabby
• 4,370 points

1 answer to this question.

0 votes

I ran into a similar issue to this, and many of the answers around the net are missing a key part of the code - assigning the EventHub to the channel. I added this before initializing the channel (which in this case would be in the createChannel mehtod), and my transactions were then processed successfully:

channel.addEventHub(client.newEventHub("eventhub0", "grpc://localhost:7053"));
answered Jul 16, 2018 by Perry
• 17,100 points

Related Questions In Blockchain

+1 vote
2 answers
0 votes
0 answers
+1 vote
2 answers

Where is custom chaincode path Hyperledger Fabric 1.0?

You have to have your chaincode at ...READ MORE

answered Jul 10, 2018 in Blockchain by slayer
• 29,310 points
0 votes
1 answer

Invalid Batch or signature in Savtooth

This will solve your problem import org.apache.commons.codec.binary.Hex; Transaction txn ...READ MORE

answered Aug 1, 2018 in Blockchain by digger
• 26,720 points
0 votes
1 answer
+1 vote
2 answers
0 votes
1 answer

Hyperledger Fabric v1.0 setup on multiple machines

You would be able to host hyperledger fabric ...READ MORE

answered Oct 23, 2018 in Blockchain by Perry
• 17,100 points