Intro to Private Blockchains

Connecting to the Fabric

Before we move on to interactions with the ledger, it will help to review how the ledger is updated in Query.js. (see fabric-samples/fabcar/query.js)

Connecting to the Peer SDK

In the first four lines of this script, we'll introduce our libraries. Then, we can initialize the Hyperledger client and connect to the network:

Querying the ledger

When a client queries a Hyperledger node, the state object is returned as the consensus at that time. In section 1 we covered the transaction flow in greater detail, but we’ll now see how the query object is generated and passed to the network endpoint / SDK.

Connecting to the Peer SDK

The first 50 lines or so of query.js handle connecting to the network and authenticating the user that we created in the previous step. Finally, we can prepare a test query on line 54:

You can send the query by triggering the script using the following command:


Run the query

[email protected]: ~/fabric-samples/fabcar/ $ node query.js

If your Hyperledger node is running this should return a printout of json data, but right now it will be empty because we haven’t added any cars to the dealership’s registry! In the next section, we’ll explore the chaincode and see how this payload gets processed by other nodes on the network!