Change Smart Contract Languages after few versions - hyperledger-fabric

I am experimenting with Hyperledger Fabric and am not sure what the best smart contract language to start.
That being said, I did start with JS using the Commercial Paper example.
Can you change smart contract language along the way?
For example, you write the first few version of your contract in JS and then you switch to GO?

Yes you can change chaincode language as you go. Just make sure the same chaincode is installed on all the peers.

A good approach is to write in a supported programming language that is fast for you. This allows rapid prototyping and demonstration. If it works out, rewrite in a compiled language, such as Go, which also has the benefit of stronger typing.

Related

Does the language in which the hyperledger's chaincode is written matter?

I am trying to develop a chaincode in hyperledger. I know that the chaincode cab be developed in either java,go or node js. My question is does it matter which language I am developing the chaincode in?
When considering which language to write chaincode in I've typically seen orgs ask themselves the following questions:
Which language has the most mature SDK/support?
Which language has the most developer interest/ease of hiring?
Which language provides the most safety?
The last one is often overlooked but is, in my opinion, one of the most crucial when considering that bugs in chaincode are often much more important than bugs in typical code! Remember that the output of the chaincode is inscribed for all time within the ledger, and that fixing the outputs of bad chaincode can be a costly process.
Considering those questions, you can evaluate the three languages (go, nodejs, java) chaincode supports as follows:
Golang has by far the most mature SDK/support. Fabric is written in Go and considers Go a first-class citizen in all tangential projects; it is therefore often the first considered and most updated language when it comes to Fabric support.
NodeJS is probably easiest to find talent for and is already a widely popular language, meaning chaincode will typically be most accessible when written in NodeJS. The first developed and most popular Fabric SDK (non-chaincode) is the nodejs one so these go together very well. Of course, Java probably has just as many if not more available developers, but I'm counting it second here as it is much less supported.
Golang and Java are both strongly typed languages and provide the guarantees such languages bring. Java also brings with it many years of production experience and safety. Those both win out when it comes to language safety over a dynamically-typed, JIT-compiled language like nodejs.
TL;DR: Golang has strong safety guarantees and is most widely supported, NodeJS is easier to write and easier to find developers for, Java is a tough sell
I'd suggest using GoLang as it is a highly efficient and powerful language in terms of performance and scalability.

Type of functions for Hyperledger Fabric Smart Contract

I am using Hyperledger Fabric for my Energy Blockchain work. I am using Javascript for developing my Smart Contract. While writing functions for the smart contract, how much processing I am allowed to put there?
For example, if i put a simple optimization problem inside the smart contract will that work? My guess says, no, I should not, but can I have some logical explanation whether that should be done or not?
Yes, you can. Hyperledger Fabric permits to write smart contracts in turing complete languages (Javascript, Go, Java).
The logics that you write in your smart contract must be deterministic because they are executed in different peers and they must return the same output in order to update the ledger.
If you need more information about smart contracts, here the official documentation:
https://hyperledger-fabric.readthedocs.io/en/release-1.4/smartcontract/smartcontract.html#developing
Ideally you can put full turing complete code in your smart contract code. But you also have to be careful in the amount of computational overhead you are asking your as well as peers of other organisations to perform. Ideally in a permissioned environment, if your code is too computationally expensive, your code might be rejected by smart contract auditing team (if there are any) before any actual production deployment.
But there are other mechanisms where you can employ special nodes to do off chain computations and keep stakes high, for others to point out errors if anyone puts malevolent computational results on chain.

Should I use typescript in all the layers of the MEAN stack?

I chose the MEAN stack to develop my web application mainly because I will be using javascript across all the layers.
One language to rule them all, right?
And then I heard about typescript, and I decided to use it.
The thing is typescript is mainly used with angular and not the other layers of the stack. So choosing typescript means losing the best thing about the MEAN stack.
I still want the benefits of typescript along with the:
One language to rule them all!
In other words, I want to use BOTH typescript&MEAN stack, to develop my web-application, would you advise me to do this?
I just found-out about this "new" stack called tsmean https://www.tsmean.com. It seems the perfect answer for my question!
However, I am scared since it is still a new technology and there’snt a large community behind it like the MeanJS stack community. Also the lack of reliable tutorials makes me a bit hesitant to use it.
On the other hand, my web-application is relatively small and simple and in an article on medium (https://medium.com/#TypeMean/building-the-ts-mean-stack-first-impressions-c2bf1db2bef1), the creator of tsmean wrote that in such conditions, using tsmean can be a good decision.
In a nutshell, I will be creating a web-app version of the functionalities provided by a simple excell sheet. So I believe tsmean is the right choice for me!
Yes. If you want to use TypeScript throughout your MEAN stack, you can. TypeScript is literally JavaScript with strong typing abilities. This makes classes and method signatures much stronger than JavaScript by itself. Ultimately, TypeScript is transpiled to JavaScript so any packages available to JavaScript are also available to TypeScript. Both are EcmaScript languages.

How can write a smart contract for my use case in Hyperledger composer?

i want to write a smart contract (logic.js)for my use case using hyperledger composer playground tool, i know it is writen in javascript so i studied it(javascript), also i read examples for smart contracts for other networks but it is not enough to me to write my own one, also i read this link( https://hyperledger.github.io/composer/v0.19/reference/js_scripts.html). but it still not enough, so my question is how can write my own (logig.js )file?
Firstly you need to learn the JavaScript. Then doing something practical like https://github.com/IBM-Blockchain/marbles .This is an open source project. Hope it helpfull.

Suggestions for non-blocking & fast servers, frameworks, languages?

Our new project will get a lot of concurrent requests. I don't have a lot of experience with this. Any suggestions? I've looked at NodeJS, Twisted, EventMachine & Tornado but I don't have any way to measure how suitable they will be.
Any suggestions?
Ask yourself the following questions (at least) and then decide:
What language do I (or/and my colleagues) know? If you know Python you could choose Twisted, if you know Ruby you can choose EventMachine or if you are really good with JavaScript you could choose Node.js. (only Erlang wouldn't have an advantage here)
Do I want to use a language construct (Erlang, Node.js) or a library (Twisted, EventMachine)?
Do I need a lot of resources, community support, books etc? Check out for yourself how big are their channels on IRC, you'll make an idea. (I may be biased, but I see tons of people on the Node.js channels and they are really helpful)
How mature do you want the framework to be? (Node for example has 2 years, Erlang has been officially released in `98, etc)
What companies/products are using what async frameworks? (for example CouchDB has been built with Erlang, Node.js is used by Github, Linkedin and others, EventMachine is used by PostRank, 37 signals etc)
The suitability of specific non-blocking framework may be dependent on certain aspects, such as:
Preferred language/platform - someone can be versed in specific language which might speed up the development. Also finding a skilled people might be a problem.
Availability of non-blocking libraries for your framework - for example most of the node.js modules are by default non-blocking compared to other frameworks where you might run into a problem of finding a non-blocing version of library which offers desired functionality.
Documentation and community support is essential.
As others say - you should go with the one that has the non-blocking libraries (e.g. DB drivers) you need and, if possible, uses the language your team knows. Popularity may also be an advantage.
If you're programming in Python, gevent might also be a good option. There is even a Socket.IO implementation.
Develop a metric to measure suitability, then use that metric. How can anyone here tell you which one is the most suitable if you don't provide any basis for evaluation?
Wait, scratch that. Twisted is the most suitable for everything, always, no matter what.

Resources