What is the recommended way to invoke and query data/transactions that were modeled using Fabric Composer? - hyperledger-composer

I am building an PoC using Fabric v0.6 and composer-ui. The question I have is regarding how to interact with the Fabric peers once I have deployed my .bna file in the Fabric network. In the past I have made invoke and query calls to my chaincode using gRPC and passing the function name and arguments through the call. In the case of chaincode deployed through composer, there is a whole abstraction happening so I am not sure if the name of my transactions created in composer translate exactly to names I can call via my gRPC calls on the client side (my node application). I also don't know if the arguments that I pass to the chaincode are the same or if any special argument is expected.
So I guess my question is, from the client side, how do I make calls to transactions in my chaincode that have been creating using Composer? Are there client examples out there for Fabric v0.6? Thanks!

The first example that comes to mind is the sample-applications repository at https://github.com/fabric-composer/sample-applications
if you look in the sample-applications/packages/getting-started there is an example of a client application. The landRegistry.js file in the lib directory contains the bulk of the code used to interact with the business network.
There is also an application generator which is described in more detail at
https://fabric-composer.github.io/applications/genapp.html
You can also find reference documentation for both client side and businessnetwork implementations at
https://fabric-composer.github.io/jsdoc/

You should also consider using the REST API that Composer can generate for your business network.
npm install -g composer-rest-server
composer-rest-server
Then fill in the details required to connect to your business network and the composer-rest-server will expose a Swagger defined REST API that you can exercise using Swagger UI. The REST API is expressed in terms of the assets, participants and transactions that are modeled in your business network.
More docs here:
https://fabric-composer.github.io/integrating/getting-started-rest-api.html
The advantage of using the REST API is that it keeps the coupling between the client application and the blockchain loose; the client doesn't need any Composer libraries and doesn't even need to know that the data source is a blockchain.

Related

Using encryption algorithm in smart contract

I am new to Block chain development.I am now trying to write a smart contract in Hyperledger Composer. My smart contract should do this function.
It should access a file on the cloud and run an encryption algorithm on that file and should send to the user on request file transaction invocation.I have a few questions on this:
Is it possible to access a file on the cloud through smart contract code?
I have an encryption algorithm in Java.How can I include it in smart contract so that it can encrypt the file?
Hyperledger Composer Transactions allow you to 'call out' using the Node Request module, so if your cloud file system can make documents available on a REST service then you will be able to access them from Composer. The details of calling out to a REST service are covered here in the Composer documentation.
For the encryption as with the Cloud File, if you can expose your java algorithm as a REST service then you can call it. Otherwise you would need to re-write your encryption in javascript whilst remembering that Composer does not allow 'Import' or 'Require' in the transaction functions.

Hyperledger composer for enterprise

I saw that Hyperledger composer is really easy to work with, also we can deploy the composer code on hyperledger fabric. But I found that they create only one channel, and we will have the flexibility to talk to the specific peers like what we can do in GoLang\fabric, can we call external web services from composer java script code as we can do in Golang on fabric?
I'm wondering, can we use hyperledger composer for enterprise blockchain applications? or just we use it to create blockchain POCs.
Regards.
Bassel Kh
Hyperledger Composer is intended to be used for enterprise blockchain applications, although Composer Playground is not intended for Production use.
Composer connects with Fabric using Business Network Cards, and these contain credentials and a Connection Profile. The connection profile contains definitions of the 'services' on the Fabric, and so it is possible to define specific Peers within the card.
Regarding channels - it is again the Connection Profile that determines the Channel used, and at the moment only one channel is supported per Card. Multiple cards can be used but disconnect/switch/re-connect might not be practical or desirable in some cases.
There is a way to connect to a different Business Network on a different Channel covered in this tutorial, but again it might not be suitable for all cases.
There is an outstanding issue on GitHub for using Composer for multi-channel, so you can leave a comment or +1 on it - particularly if you have a good use case for multi-channel.
Many people are thinking of and using channels as a security feature, but Composer ACLs might solve that issue in some cases. Similarly the upcoming sidedb feature in Fabric might offer security instead of separate channels.
yes, you can call external web services and get the results back into your smart contract code or client see -> https://hyperledger.github.io/composer/latest/integrating/call-out
yes Hyperledger Composer is intended for Enterprise blockchain applications. Your applications will use Composer client to write application data to the ledger, and its production runtime is where the 'chaincode' smart contract/business network is deployed/installed on the peers (just like Go chaincode is similarly deployed). One such provider using Composer is here -> https://ibm-blockchain.github.io/platform-deployment/
Finally also see here -> https://github.com/hyperledger/composer-knowledge-wiki/blob/latest/knowledge.md#production for more info.

Regarding Events of APIs generated by hyperledger composer rest server

I am working on a POC and do not want to write any specific transaction processing functions. Created assets, participants etc. and all, so the model is ready. Generated rest api using hyperledger composer-rest-server. The frontend is developed in simple html/javascript.
the problem is that i need events also available whenver i CRUD using composer generated APIs, but not able to figure out how.
IS it that to capture events, we need to create assets using transaction processing functions only and not via composer rest server apis - a little novice kinda question but i am stuck in this thought.
regards,
Sophia
I think you have figured it by now, but here's the answer for the rest of us: you can only generate events from your chaincode, and every event has to be described in your model.

Overhead to using composer-rest-server over JavaScript / Node SDK?

We are trying to figure out best design practice while using hyper-ledger composer. We have following questions :
1) if We are using composer-rest-server, then will have to manage two server side components.
i) running composer-rest-server ii) running application which will send request to composer-rest-server to communicate to network.
Isn't it overhead? what additional advantages we are getting by using composer-rest-server? in fact, probably client will have to authenticate two times i guess.
2) If we are using JavaScript SDK, then will have to manage only one server side application, kindly correct me in case of misunderstanding.
3) When i generated angularjs application using yo generator, its also asking me information of composer-rest-server, but I am not planning to use composer-rest-server and want to use 'composer-client' and 'composer-admin' only.
Yes, there will be some overhead of running the composer-rest-server in its own process, however it will allow you to secure and scale your rest servers independent of your application. Depending on your scenario that may be an overhead worth paying.
Another option would be to generate a LoopBack application (using the lb tools) that uses the loopback-connector-composer LoopBack connector directly. This may give you access to the underlying Express server and would allow you to merge your application and the REST server.
You are correct, however you would have to build the REST API for your business network yourself, and manage authentication and certificates.
The generated Angular application uses the REST API exposed by the composer-rest-server to interact with HLF.
Here is a DRAFT topology diagram that I am working on for contribution to the documentation.

How can other libraries be invoked from chaincode?

In https://hyperledger.github.io/composer/reference/MeetTheModules.html it says:
composer-client and composer-admin are the two modules that provide APIs for applications. node.js applications should only use APIs that come from these modules. If there are other APIs that are need please contact us.
If I had chaincode which needed to call out to an AWS service using the AWS Node SDK for instance, is this one of the scenarios where we should contact the dev team? I'm new to node.js btw, so apologies if this is an obvious question.
chaincode (or transaction processor functions in Composer terms) are executed in a JavaScript virtual machine written in Go, not Node.js. It is currently not possible to import Node.js modules from a transaction processor function or call out to an external service.
We are very interested in adding Node.js chaincode support to Fabric, this is work we are planning on starting.

Resources