src/main/java/org/hyperledger/fabric/sdk/Fabrichelper.java
/**
     * Invoke blockchain query
     *
     * @param client The HF Client
     * @throws ProposalException
     * @throws InvalidArgumentException
     */
Invoke blockchain query
@param client The HF Client
@throws ProposalException
@throws InvalidArgumentException
Invoke blockchain query @param client The HF Client @throws ProposalException @throws InvalidArgumentException
public static boolean invokeBlockChain(HFClient client,String ccid,String fcnname,String[] args) throws ProposalException, InvalidArgumentException,Exception {
        Collection<ProposalResponse> responses;
        Collection<ProposalResponse> successful = new LinkedList<>();
        Collection<ProposalResponse> failed = new LinkedList<>();
        boolean fresult=true;
        Channel channel = client.getChannel("mychannel");
        TransactionProposalRequest tpr = client.newTransactionProposalRequest();
        ChaincodeID fabcarCCId = ChaincodeID.newBuilder().setName(ccid).build();
        tpr.setChaincodeID(fabcarCCId);
        tpr.setFcn(fcnname);
        tpr.setArgs(args);
        Map<String, byte[]> tm2 = new HashMap<>();
        tm2.put("HyperLedgerFabric", "TransactionProposalRequest:JavaSDK".getBytes());
        tm2.put("method", "TransactionProposalRequest".getBytes());
        tm2.put("result", ":)".getBytes());
        tpr.setTransientMap(tm2);
        Collection<ProposalResponse> transactionPropResp = channel.sendTransactionProposal(tpr, channel.getPeers());
        for (ProposalResponse response : transactionPropResp) {
            if (response.getStatus() == ProposalResponse.Status.SUCCESS) {
                System.out.println("Successful transaction proposal response Txid: "+response.getTransactionID() + " from peer " +response.getPeer().getName());
                successful.add(response);
            } else {
                failed.add(response);
                fresult=false;
            }
        }
        Collection<Set<ProposalResponse>> proposalConsistencySets = SDKUtils.getProposalConsistencySets(transactionPropResp);
        if (proposalConsistencySets.size() != 1) {
            System.err.println("Expected only one set of consistent proposal responses but got "+proposalConsistencySets.size());
        }
        if (failed.size() > 0) {
            ProposalResponse firstTransactionProposalResponse = failed.iterator().next();
            System.err.println("Not enough endorsers for invoke :" + failed.size() + " endorser error: " +
                    firstTransactionProposalResponse.getMessage() +
                    ". Was verified: " + firstTransactionProposalResponse.isVerified());
        }
        ProposalResponse resp = successful.iterator().next();
        byte[] x = resp.getChaincodeActionResponsePayload(); 
        String resultAsString = null;
        if (x != null) {
            resultAsString = new String(x, "UTF-8");
        }
        System.out.println("Result returned from chaincode: "+resultAsString);
        System.out.println("Chaincode Status: "+resp.getChaincodeActionResponseStatus());
        System.out.println("Chaincode ID: "+resp.getChaincodeID());
        System.out.println("Chaincode PATH: "+resp.getChaincodeID().getPath());
        System.out.println("Chaincode NAME: "+resp.getChaincodeID().getName());
        System.out.println("Chaincode Version: "+resp.getChaincodeID().getVersion());
        /*channel.sendTransaction(successful).thenApply(transactionEvent -> {
            System.out.print("Response <transactionEvent>: "+transactionEvent.isValid());
            System.out.print("Response <transactionEvent TXID >: "+transactionEvent.getTransactionID());
            if(transactionEvent.isValid()==false) {
            	return false;
            }
            return true;
        });*/
        BlockEvent.TransactionEvent transactionEvent=channel.sendTransaction(successful).get(100, TimeUnit.SECONDS);
        System.out.println("isvalid:"+transactionEvent.isValid());
        System.out.println("transaction id:"+transactionEvent.getTransactionID());
        if(transactionEvent.isValid()==false) {
        	return false;
        }else {
        	return true;
        }
    }
public static boolean invokeBlockChain ( HFClient client , String ccid , String fcnname , String [ ] args ) throws ProposalException , InvalidArgumentException , Exception { Collection < ProposalResponse > responses ; Collection < ProposalResponse > successful = new LinkedList < > ( ) ; Collection < ProposalResponse > failed = new LinkedList < > ( ) ; boolean fresult = true ; Channel channel = client . getChannel ( "mychannel" ) ; TransactionProposalRequest tpr = client . newTransactionProposalRequest ( ) ; ChaincodeID fabcarCCId = ChaincodeID . newBuilder ( ) . setName ( ccid ) . build ( ) ; tpr . setChaincodeID ( fabcarCCId ) ; tpr . setFcn ( fcnname ) ; tpr . setArgs ( args ) ; Map < String , byte [ ] > tm2 = new HashMap < > ( ) ; tm2 . put ( "HyperLedgerFabric" , "TransactionProposalRequest:JavaSDK" . getBytes ( ) ) ; tm2 . put ( "method" , "TransactionProposalRequest" . getBytes ( ) ) ; tm2 . put ( "result" , ":)" . getBytes ( ) ) ; tpr . setTransientMap ( tm2 ) ; Collection < ProposalResponse > transactionPropResp = channel . sendTransactionProposal ( tpr , channel . getPeers ( ) ) ; for ( ProposalResponse response : transactionPropResp ) { if ( response . getStatus ( ) == ProposalResponse . Status . SUCCESS ) { System . out . println ( "Successful transaction proposal response Txid: " + response . getTransactionID ( ) + " from peer " + response . getPeer ( ) . getName ( ) ) ; successful . add ( response ) ; } else { failed . add ( response ) ; fresult = false ; } } Collection < Set < ProposalResponse > > proposalConsistencySets = SDKUtils . getProposalConsistencySets ( transactionPropResp ) ; if ( proposalConsistencySets . size ( ) != 1 ) { System . err . println ( "Expected only one set of consistent proposal responses but got " + proposalConsistencySets . size ( ) ) ; } if ( failed . size ( ) > 0 ) { ProposalResponse firstTransactionProposalResponse = failed . iterator ( ) . next ( ) ; System . err . println ( "Not enough endorsers for invoke :" + failed . size ( ) + " endorser error: " + firstTransactionProposalResponse . getMessage ( ) + ". Was verified: " + firstTransactionProposalResponse . isVerified ( ) ) ; } ProposalResponse resp = successful . iterator ( ) . next ( ) ; byte [ ] x = resp . getChaincodeActionResponsePayload ( ) ; String resultAsString = null ; if ( x != null ) { resultAsString = new String ( x , "UTF-8" ) ; } System . out . println ( "Result returned from chaincode: " + resultAsString ) ; System . out . println ( "Chaincode Status: " + resp . getChaincodeActionResponseStatus ( ) ) ; System . out . println ( "Chaincode ID: " + resp . getChaincodeID ( ) ) ; System . out . println ( "Chaincode PATH: " + resp . getChaincodeID ( ) . getPath ( ) ) ; System . out . println ( "Chaincode NAME: " + resp . getChaincodeID ( ) . getName ( ) ) ; System . out . println ( "Chaincode Version: " + resp . getChaincodeID ( ) . getVersion ( ) ) ; /*channel.sendTransaction(successful).thenApply(transactionEvent -> {
            System.out.print("Response <transactionEvent>: "+transactionEvent.isValid());
            System.out.print("Response <transactionEvent TXID >: "+transactionEvent.getTransactionID());
            if(transactionEvent.isValid()==false) {
            	return false;
            }
            return true;
        });*/ BlockEvent . TransactionEvent transactionEvent = channel . sendTransaction ( successful ) . get ( 100 , TimeUnit . SECONDS ) ; System . out . println ( "isvalid:" + transactionEvent . isValid ( ) ) ; System . out . println ( "transaction id:" + transactionEvent . getTransactionID ( ) ) ; if ( transactionEvent . isValid ( ) == false ) { return false ; } else { return true ; } }
Invoke blockchain query
 @param client The HF Client
 @throws ProposalException
 @throws InvalidArgumentException
Invoke blockchain query @param client The HF Client @throws ProposalException @throws InvalidArgumentException
// get channel instance from client // create chaincode request // build cc id providing the chaincode name. Version is omitted here. // CC function to be called //String[] strs = new String[]{"CAR10","JANG","JANG","JANG","JANG"}; // This is the data returned by the chaincode.