How to use Rest API support in local development environment

0 votes

I have a HyperLedger Fabric V1.0 network. It has 4 organizations and each organization has 1 peer.

1. - with peer: and msp: Org1MSP
2. - with peer: and msp: Org2MSP
3. - with peer: and msp: Org3MSP
4. - with peer: and msp: Org4MSP

To invoke and query, i am using the following code:

peer chaincode invoke -o --tls $CORE_PEER_TLS_ENABLED --cafile /opt/gopath/src/ -C $CHANNEL_NAME -n mycc -c '{"Args":["invoke","a","b","10"]}'

peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}'

Now i want to use REST API in local network using docker image. Then i want to interact with chaincode using java
How can i achieve this?

Jul 11, 2018 in Blockchain by digger
• 26,720 points

retagged Nov 22, 2018 by Omkar 338 views

1 answer to this question.

0 votes

Rest API is not available for Hyperledger Fabric v.1.0.0. But you can use Java SDK to interact with peers. 
setup your java project with following maven dependencies:


Next, you have to get instance of HF client like this: 
final HFClient client = HFClient.createNewInstance();

Next you have to setup crypto materials for client like this:

// Set default crypto suite for HF client

    client.setUserContext(new User() {

        public String getName() {
            return "testUser";

        public Set<String> getRoles() {
            return null;

        public String getAccount() {
            return null;

        public String getAffiliation() {
            return null;

        public Enrollment getEnrollment() {
            return new Enrollment() {
                public PrivateKey getKey() {
                    // Load your private key
               public String getCert() {
                    // Read client certificate

        public String getMspId() {
            return "Org1MSP";

Channel Configuration:
  final Channel channel = client.newChannel("mychannel");

    channel.addOrderer(client.newOrderer("orderer0", "grpc://localhost:7050"));
    channel.addPeer(client.newPeer("peer0", "grpc://localhost:7051"));


Now, create a transaction proposal:

 final TransactionProposalRequest proposalRequest = client.newTransactionProposalRequest();

    final ChaincodeID chaincodeID = ChaincodeID.newBuilder()

    proposalRequest.setArgs(new String[]{"arg1", "arg2"});

Lastly, send the proposal:

    final Collection<ProposalResponse> responses = channel.sendTransactionProposal(proposalRequest);

    CompletableFuture<BlockEvent.TransactionEvent> txFuture = channel.sendTransaction(responses, client.getUserContext());

    BlockEvent.TransactionEvent event = txFuture.get();


answered Jul 11, 2018 by slayer
• 29,310 points

Related Questions In Blockchain

+1 vote
1 answer

How to setup testnet environment in Ethereum??

You can connect to a node using ...READ MORE

answered Apr 18, 2018 in Blockchain by Shashank
• 10,400 points
0 votes
1 answer
0 votes
1 answer

How i can use nodejs to watch transactions in bitcoin network?

you can use  const Socket = require(''); const mySocket ...READ MORE

answered Jul 9, 2018 in Blockchain by digger
• 26,720 points
0 votes
1 answer

Network issue while testing Chaincode.

You can do the following things: You can ...READ MORE

answered Jul 3, 2018 in Blockchain by Omkar
• 69,150 points
0 votes
1 answer
0 votes
1 answer

Hyperledger Composer rest server NPM versions

The Hyperledger Composer pre-requisites can be installed ...READ MORE

answered Jul 13, 2018 in Blockchain by Christine
• 15,830 points
0 votes
1 answer

How to Track Payment API in Coinbase

Use the callback_url option as described in the API. ...READ MORE

answered Sep 5, 2018 in Blockchain by slayer
• 29,310 points
0 votes
1 answer

How to use Coinbase send_money API?

<?php require_once(dirname(__FILE__) . '/../lib/Coinbase.php'); // Create an application at ...READ MORE

answered Sep 12, 2018 in Blockchain by slayer
• 29,310 points