Can I query Hyperledger Fabric directly from a WebApp? - hyperledger-fabric

I'm really new to Hyperledger and blockchain. From what I understand, the whole meaning of the blockchain is to build decentralized applications, not depending on a single server.
So my question is: Is there a way to query and work with a Fabric node directly from a web browser? I believe Ethereum solves this problem with web3.js.
Thank you very much for your help.

Short Answer: No.
Web3.js communicates with Ethereum over JSON RPC and is supported by browsers.
Hyperledger Fabric, on the other hand, uses Protobuf over grpc. Currently, there is no such implementation like web3.js that can communicate directly using a browser with Hyperledger Fabric.
However Hyperledger Burrow, that provides a permissioned version of Ethereum and supports Solidity Smart Contracts does not yet support web3.js, but it is something they have in their roadmap and shall support soon.
Check this for more updates: https://wiki.hyperledger.org/projects/burrow/roadmap_2018_q1

To mimic a network for testing you can use composer-playground.mybluemix.net and to test your assets/transactions once deployed on Fabric, you can use Composer's REST API to make calls to localhost.

Related

Looking for a End-to-End tutorial to develop a NodeJs Blockchain Appliation using Hyperledger Fabric and Composer REST SERVER

Since more than one month, I am working on creating a multi Organization Hyperledger Fabric Application.
I started with Composer, used playground to test my business logic. Then deployed it to the Locally running Fabric Network and used the COMPOSER REST Server to interact with the Blockchain.
The problem started when I wanted to use my Node Application with this network. I can't get my head around participants, network cards, importing these cards, binding these cards, having a wallet for these cards, Activating these cards, enrolling them and doing all this from the NODE Application.
I want One tutorial which will help me connecting a NODE application to a Blockchain network with a Business card and explain everything in layman terms.
Bottom Line: I want to develop a node application, which will use the REST server-generated for the locally running Hyperledger Fabric using Composer. Any suggestion on End-to-End tutorials or step by step method to understand these concepts will be really appreciated.
what you need can be found here:
https://hyperledger-fabric.readthedocs.io/en/latest/write_first_app.html
it covers everything you need to create a fully fledged application using the node SDK. Make sure you follow all the resources including the Setting up your first network tutorial. The link is on that page.
The problem with composer is that it is not developed anymore by IBM:
https://lists.hyperledger.org/g/composer/message/125
as such I would not recommend you spend any more time on it.

Hyperledger -- how to set up REST API for invoking Chaincode

I'm playing around with Hyperledger and am trying to figure to figure how to set up the server with REST api for chaincode defined here https://openblockchain.readthedocs.io/en/latest/API/CoreAPI/#rest-api
Unfortunately many of the links are dead, so I'm not sure how to set it up. I understand the query language, I just don't knopw how to begin the web server.
Does anyone have any ideas?
Hyperledger Fabric v1.0 and later does not provide a native REST API for interacting with peer and/or orderer nodes. If you have not done so, I'd advise taking a look at http://hyperledger-fabric.readthedocs.io/en/release-1.1/ to better understand the current Fabric architecture.
There is a project to provide a REST API server in front of Fabric nodes. It was not updated to support Fabric v1.1 (at least not yet) but does support Fabric v1.0 and should provide at least an example of how to add a REST API in front.
I'd also advice taking a look at the samples which are documented here as well. The fabcar sample provides a nice, simple example of how to connect a Node.js application to Fabric.

Hyperledger Composer vs Hyperledger Nodejs Api

I am new to hyperledger and bit confused about hyperledger composer & nodejs api.
I saw using composer we can create assets, transactions, participants and chaincode and in last we have to archive it this all into .bna file and finally we deploy this chaincode into network using admin card
But at other end using NodeJs API we can also write chaincode by overiding init & invoke methods.
How can we relate these all.
The best way to think about this is the following:
1) Hyperledger Fabric v1.1 supports writing chaincode in two languages: Golang and JavaScript via Node.js
If you want to do all of the heavy lifting yourself, you can write straight chaincode.
2) Hyperledger Composer provides a higher-level model-driven language for developing smart contracts. It currently only allows deployment of these artifacts to Hyperledger Fabric. It also happens to support writing functions in JavaScript as well.
So if you want to start from a higher-level model-driven approach, Hyperledger Composer is the way to go. If you want to write all of the plumbing yourself or use very low-level chaincode features, then using chaincode itself is the way to go.
Moving forward, we are looking at a better way to move between the two and not force a decision / direction up front.
There is another option, we develop a framework called Convector to be in the middle of Composer (high abstraction, low control) and raw code (low abstraction, high control, therefore high risk). We open sourced it a few days ago. At WorldSibu we don't like loosing so much control over our code like with Composer but as Gari Singh was saying, doing all the heavy lifting for each project is crazy. It is like a Mongoose for Hyperledger Fabric. It may help to check it out.
It is also worth noting that, according to IBM, Composer is no longer recommended as a production solution, but only for prototyping. In HLF 1.3, chaincode can now be written in Go, Javascript and Java.

How to get chaincode to read from api's outside of the Hyperledger fabric blockchain

I'm wondering how you can get a hyperledger fabric smart contract to read from external API's ?
A service called oraclize (http://www.oraclize.it/) is used to do this operation in Ethereum blockchains - Is there anything similar for hyperledger fabric smart contracts or any workarounds?
In Hyperledger Fabric - smart contracts (the chaincode), could be implemented at the moment with either golang or Java, both of which are Turing complete and provides you with reach set of libraries and frameworks. Among which you can you any network library to get connected with external services, while you need to be extra cautious doing this to make sure your chaincode is deterministic (e.g. two independent executions of the same chaincode calling same external API will get same result back).
Riccardo from Oraclize here.
We are actually working on a Oraclize integration with Hyperledger.

What does Hyperledger composer do .Does that create chaincode for fabric or something else?

I have been working on hyperledger fabric for some time. But I don’t understand where hyperledger composer comes in place . I do understand that it helps in visualizing the logic and transaction. But what I don’t get is how do you integrate it with fabric network? what does it create? Is it chaincode if not then what?
The Compose runtime is chain code that executes the business network archive artefacts created by the end-user.
Perhaps this will help?
https://blog.selman.org/2017/07/08/getting-started-with-blockchain-development/
The tech answer is that Hyperledger Composer is an abstraction layer over Hyperledger Fabric.
The practical answer is that it is awesome. Think how Angular and hundreds of other frameworks make web programming easier.
It is a framework where you can write your blockchain in Javascript and specify your data objects in an easy to understand text file. Throw in some querying, ACL stuff and pathways to use some nice opensource tools that let you do things like generate a Web API automatically and play around in a web environment without installing anything.
We are using it for the Integra Ledger Legal blockchain. (www.integraledger.com). I just spent the day working in it.

Resources