How to write Multiple chaincodes for multiple channels in hyperledger-composer? - hyperledger-fabric

In Fabric we have multiple channels, if my network has multiple channels then how can i write multiple chaincodes for each channel from the Hyperledger-composer ?

Hyperledger Composer connects to Fabric via Business Network Cards, and the Cards include a connection profile. In that connection profile the channel is specified. By default composerchannel is used.
You can see this in a filename similar to this example: /home/ibm/.composer/cards/admin#my-network/connection.json

Related

How to create a channel which was not in the initial channelconfig during the network creation?

I am using Hyperledger Fabric for permissioned Blockchain Network. I created one channel with 2 organizations. Now the network is up and running. Now I want to create another new channel which was not defined in the initial configuration. Now what is the process of creating such new channel?

Implement the distributed-decentralised ledger for a hyperleder network

Did a small example using the hyperledger composer and then used the composer-rest-server to integrate it with GUI. So in the case of identity, only admin is there. There is also documentation to create and issue other identities to login into the business networks.
But still, the problem is it's only in a single peer, meaning my local machine. To my understanding, for the hyperledger to function as decentralized and distributed ledger system, additional peers have to be added to the channel and then states gets synced in those peers. Hence if one node is down, details can be obtained from other nodes.
I checked some links such as this and this. But all of these point to the things that :
Existing network should be stopped and teared down.
The IP address of the second machine should be manually added to the docker.yml file and then have to be restarted.
My doubts are :
But on doing this, won't the existing ledger stated be cleared? All the data are gone.
So before even creating a dApp using hyperledger, we have to include all the IP address of the machine in the yml and start the network?
How to actually implement the distributed-decentralised ledger system for a hyperleder network?
UPDATE :
I have checked the links mentioned by Paul O'Mahony. The links explains about the peer addition steps. Overall what happens there is :
downloaded the fabric sample as the fabric extension is only possible through the cryptogen version appropriate to the Fabric version.
Currently contains order, org1 & org2 (with 2 peers each).
To add a new peer along with its couchdb, changed the template count in the crypto-config.yaml and created crypto material for the new peer using the extend command.
Then using the docker composer file to spawn a new peer and its couchdb. This will create new containers.
Finally the created peers should be joined to the existing channel for the couch db to get sync. The adding to existing channel is via logging into the docker container and typing some cli commands and adding the peer to channel via channel join command.
Is this recommend way to add peers to the channel ? Suppose i am creating a network and wanted to add peers to the channel based on a condition. Like a user/users can add themselves to the network through a login via composer playground and act as a peer. So i have to follow the same steps to do it ? Is this the recommended way ?
Supporting link : https://chat.hyperledger.org/channel/fabric?msg=KgxFegcZyKEPdo4v2

Channels in hyperledger fabric

Are channels only created in hyperledger fabric only when the business network is deployed ? Or it can be created afterwards. If yes than how it is possible ?
Channels are a hyperledger fabric concept and not a hyperledger composer concept. A business network will be instantiated on a channel. So the channel must already have been created using the standard fabric mechanisms for creating channels.
It is able to create a new channel in an existing orderer, and then ask existing peers to join that channel.
On Fabric Node.js SDK, we can use Channel.createChannel() and Channel.joinChannel() to do it.
related references:
https://fabric-sdk-node.github.io/release-1.3/Client.html#createChannel
https://fabric-sdk-node.github.io/release-1.3/Channel.html#joinChannel
Hope this helps.

How to share data between two chaincodes on Hyperledger Fabric on Single Channel?

I have started to learn Hyperledger Fabric and Composer. I am able to create a simple Business Network using Composer and deploy it on Fabric, but I have a question. Let's say I have 2 BNA (instantiated on single channel) files both having same namespace (org.example) and having same participant name as well, as Customer (identifier will be org.example.Customer). Is there any way that I can access the participants created by first Business Network App in another Business Network App? Logically what I can think of is since both have been instantiated in the same channel with different chaincode and same model file, data should be cross accessible. But it isn't.
Although chaincodes share the same ledger when installed on the same channel (and as business networks are just chaincodes this applies to them also). Fabric still partitions the data that a chaincode can read/write by it's chaincode id. So when you install 2 business networks onto the same channel they will have different chaincode id's and so their data is separately partitioned.
As mentioned in the other answer (although the link is not quite correct), what you can do is make use of a feature of composer to be able to invoke another business network on the same or even different channel from the executing business network.
As the 2 business networks are on the same channel you can not only read information but you are also able to invoke transactions that can change information. (You can only read information if the business networks are on different channels).
The correct link for the tutorial is here
https://hyperledger.github.io/composer/latest/tutorials/invoke-composer-network
Unfortunately this tutorial is rather basic and only offers a glimpse of how to interact with other business networks.
Is available a tutorial about how to interact from a bna to another one.
Here the link to the official Hyperledger Composer documentation.
https://hyperledger.github.io/composer/latest/tutorials/invoke-composer-network

Can some one share fabric multi channel example using hyperledger-composer

There is no clear documentation of hyperledger fabric multichannel, can someone from community share example of configuration.
This Stack Overflow thread on creating multi-channel for a Hyperledger Fabric configuration should help you (mostly in yellow and grey code blocks) -> Configure Multiple Channel in Hyperledger Fabric.
Once you have configured your custom runtime Fabric environment for your multi-Org, multi-channel setup, you can then create the requisite Hyperledger Composer config artifacts (eg. such as business network cards, one for a PeerAdmin for runtime install on the two peers in a specific organisation, and one card for a PeerAdmin to instantiate/start the business network across all the multi-Org peers joined to the specific channel in question) - and thereafter, issue cards for the individual identities that will consume/transact on the business network (on whatever channel the connection profile information is set up to communicate on). See this Multi-Org tutorial (for two Organisations, but similar principles apply) https://hyperledger.github.io/composer/tutorials/deploy-to-fabric-multi-org.html for guidance.

Resources