Querying the Chaincode  from UI

Now, it is time to query the Chaincode status using the authorized user, who can read the data from the ledger, which is returned in JSON format.

By clicking Query Chaincode, the node server triggers the query Chaincode API to get the current ledger state information. We can see that orderId, orderPrice, shippingPrice, and rawFoodProcessDate are returned from the ledger and shown on the page:

Similarly to what we did before, the queryChaincode  uses the fabric_client API to connect to a channel with peer and query data as follows:

app.get('/queryChaincode',function(req,res){
// setup the fabric network
var fabric_client = new Fabric_Client();
var channel = fabric_client.newChannel('mychannel');
var peer = fabric_client.newPeer('grpc://localhost:7051');
channel.addPeer(peer);
var member_user = null;
var store_path = path.join(__dirname, 'hfc-key-store');
var tx_id = null;
Fabric_Client.newDefaultKeyValueStore({ path: store_path
}).then((state_store) => {
...
return fabric_client.getUserContext('user1', true);
}).then((user_from_store) => {
....
const request = {
chaincodeId: 'fsccc',
fcn: 'query',
args: ['order_001']
};
// send the query proposal to the peer
return channel.queryByChaincode(request);

Congratulations! We just used our application and queried it via Hyperledger Fabric. At this level, you should get a good sense for how web applications can be integrated with the Fabric blockchain.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset