How to check if chaincode is instantiated - hyperledger-fabric

I have application that uses fabric-sdk-java to join new peers to the existing fabric network. When joining peer I want to install chaincode on the peer and instantiate it (in case it had not been instantiated on the channel).
Is there any way to check using sdk if a specific chaincode is instantiated on the channel?

Related

What is the life cycle of a Hyperledger Fabric chaincode?

I'm trying to understand the life cycle of a Hyperledger Fabric chaincode and how it's different from the life cycle of a traditional application. Can someone explain the different stages that a chaincode goes through, and what happens at each stage?
Firstly, might be good to understand that 'peer chaincode lifecycle' commands were introduced only with Hyperledger Fabric version above 2. With version 1.x we only use commands of 'peer chaincode' family.
With 2.x version, we now have both 'chaincode' and 'chaincode lifecycle' commands. Chaincode lifecycle are commands solely for deploying the smart contract.
An example deploy flow would be something like:
peer lifecycle chaincode package
peer lifecycle chaincode install
peer lifecycle chaincode queryinstalled
peer lifecycle chaincode approveformyorg
peer lifecycle chaincode checkcommitreadiness
peer lifecycle chaincode commit
peer lifecycle chaincode querycommitted
Operations on the chaincode (after the successful deployment) are using the ("old") 'peer chaincode' commands. For example when you query or invoke chaincode.
peer chaincode invoke
peer chaincode query
Stages of deploying the chaincode are as follows:
1. Package and install chaincode
The first step in the installation process is to package (.tar.gz) the chaincode, which requires installing the chaincode dependencies (please note that the steps are different if you want to install a smart contract written in Go, JavaScript, or Typescript). Then we install this package:
e.g. peer lifecycle chaincode install sacc.tar.gz
(The peer builds the chaincode when it is installed. The install command will return any build errors if there is a problem(s) with the code.)
2. Approve chaincode
After installing a chaincode package, you need to approve a chaincode definition for your organization. The definition includes important parameters such as the name, version, and the chaincode endorsement policy.
The number of organizations that need to approve a chaincode before it can be activated is governed by the lifecycle endorsement policy. This policy, by default, requires that a majority of channel members need to approve a chaincode before it can be used on that channel.
3. Commit chaincode
Once a majority of channel members (organizations) have approved the chaincode definition, one organization can commit the definition to the channel.
The Fabric documentation on chaincode lifecycle should help:
https://hyperledger-fabric.readthedocs.io/en/latest/chaincode_lifecycle.html
The smart contract is software so you might want to consider this chaincode lifecycle as a stage within a broader application lifecycle (or DevOps) flow.

List all channel in Hyperledger Fabric network

How can I list all the channels within a fabric network? Is it possible to do it with using peer cli?
It's possible to know the "List of channels peer has joined", with peer cli, but not possible for the whole network.
The command is:
peer channel list [flags]
Link:
https://hyperledger-fabric.readthedocs.io/en/release-2.2/commands/peerchannel.html#

container in Hyperledger fabric network

what are the containers which are associated with each peer in Hyperledger Fabric (HLF)?
For example: Endorsing peers most have one chaincode container to execute chaincode.
I'm not sure if I understand your question very well, but I still would like to give it a try.
The docker containers associated with a peer are:
Peer container, which manages you peer node. It's the peer container to which you send the transaction proposal either using CLI or through SDK. Every peer container embodies a copy of the ledger. The ledger is segregated using a channel.
Couchdb container, which persists the world state. It saves every key-value pair which you query or invoke using chaincode. The name of the container is usually in the form couchdb.
Chaincode container, where the chaincode is actually deployed. All the modules/packages that your chaincode requires are first installed when you instantiate your chaincode. The chaincode container usually have its name in the form dev-peer0.org1.example.com-fabcar-1.0.1, where dev refers to the environment in which the chaincode is instantiated. peer0.org1.example.com refers to the peer which instantiated it. fabcar here is the name of your chaincode and 1.0.1 is its version, which is changed every time you upgrade your chaincode.
A peer might not have a chaincode container if it's only acting as a validating or committing peer.
CLI container, this container is required for managing peers. At a time, CLI container can only manage a single peer. You can change the peer it's managing by adding/changing the environment variable CORE_PEER_ADDRESS, e.g. CORE_PEER_ADDRESS=peer0.org1.example.com:7051.

Custumizing the test-network in HyperLedger Fabric

I'm new at HyperLedger Fabric and trying to customize the test-network provided in the demo https://github.com/hyperledger/fabric-samples/tree/master/test-network.
I can't find a way to 1. add new users and peers to the docker network and 2. create private channels using the CLI or Java SDK.
Could someone please help me ? A good tutorial to start would also be great. Thanks.
To extend Test Network with new orderer and peer, we need to extend fabric key with cryptogen, update system-channel definition, compose orderer nodes, compose peer nodes, join application channel and deploy the chaincode.
I created an article about how to extend test-network (in more details) with new peers and orderers https://dev.to/bukhorimuhammad/extending-fabric-2-test-network-50ll hope that helps

How to configure two P2P nodes on same channel using Hyperledger composer?

Current solution:
1. I have a single node running on Hyperledger.
2. I have deployed my car-auction application on it.
Solution looking for:
I want my car-auction application to deploy on the second node and both nodes should be synced on the same channel.
Any suggestion.
Thanks
This basically boils down to the network configuration that you define in Hyperledger Fabric.
This configuration is defined in two files:
crypto-config.yaml: Contains network topology
configtx.yaml: Defines genesis info and channel consortium
Considering your case, I assume your setup to be:
Single Organization
2 peer nodes within this organization
1 Orderer node
A single channel
So, you need to define network topology with an orderer and a single organization containing two peer nodes. You can find references for this complete setup at build your first network docs on fabric documentation.
Once you have that fabric setup ready, you take references from the Composer Docs. Over here, pay close attention to "connection-profile" file that you create. Since you want both these nodes to execute the car-auction chaincode, you'll need to define both of your peers as "endorsing peers" by setting "endorsingPeers" section to be "true" in the connection profile json file.
Follow the same compose reference to generate the PeerAdmin card. Now, when you install the car-auction bna file, it'll be installed on both the peers. Next, when you start the network, both the peer nodes will have their own chaincode container started up.
This way, you'll have two peer nodes connected on the same channel. And since they're on the same channel, they'll be in sync (regardless a peer is endorsing peer or not).
The same kind of setup goes for the multi-org setup.

Resources