Chaincode Management
What is Chaincode?
Chaincode is the smart contract of Hyperledger Fabric that handles the business logic of a particular application. It programmatically accesses two distinct pieces of the ledger — a blockchain that immutably records the history of all transactions, and a world state that holds a cache of the current value of these states.
Catalyst Blockchain Manager supports JavaScript, Golang, and Java for smart contract development.
Key Concepts
Endorsement: Any transaction generated by the chaincode must be approved by specific organizations as defined by the endorsement policy.
Valid Transactions: Each peer completes validation in two phases:
Ensuring all parties mentioned in the endorsement policy have signed the transaction
Checking authenticity by matching the world state at signing time against the current state
External Chaincodes: With Hyperledger Fabric v2.0, chaincode can be added externally through a Docker image. Catalyst Blockchain Manager supports this — you simply reference your Docker image in an online repository.
Chaincodes Lifecycle
Catalyst Blockchain Manager supports Hyperledger Fabric v2.0 capabilities with the following chaincode lifecycle:
Add Chaincode Template
Create a Docker image and provide a link to the Docker repository when adding a chaincode template in Catalyst Blockchain Manager.
You need to add the required environment variables (CHAINCODE_ID and CHAINCODE_ADDRESS) to run chaincode in Catalyst Blockchain Manager. See Create Your Application.
Organizations can also upgrade and delete a chaincode.
How to Add a Chaincode in Catalyst Blockchain Manager?
Go to the Chaincode tab and click Add chaincode.

Provide:
Chaincode name
Number of replicas — Chaincode replicas to deploy
Image — Link to your chaincode Docker container at the public Docker repository
For private repositories, specify an imagePullSecret. Create one in your Kubernetes cluster with the label "app.kubernetes.io/name": "image-pull-secret".
Resources: Requested CPU, CPU limit, Requested memory, Memory limit
Version
Indexes (optional, CouchDB only):
Chaincode index
Private index (for private data collections)
Indexes can only be applied to CouchDB. LevelDB does not support indexes.
Click Save to add the chaincode template.
Chaincode statuses
Pending
Ready to be installed on a peer
Running
Chaincode pod is running; can be committed to a channel
Failed
All chaincode pods have failed status
Deleted
The chaincode was deleted
How to Install Chaincode on a Peer?
Go to the Peer tab, click on a specific peer with Running status, go to the Chaincodes tab, and click Install chaincode.

Select the chaincode from the dropdown menu showing all chaincode templates added to the platform.
After installation, the chaincode container(s) will launch. It may take a few minutes to start.
How to Approve Chaincode on a Channel?
Click "Approve chaincode"
Under the Chaincodes section, click the Approve chaincode button.

Fill in:
Peer — A peer where the chaincode was installed
Chaincode — Select from the dropdown
Endorsers — Organizations that need to execute and validate transactions
Policy — ANY, MAJORITY, or ALL
Sequence — Automatically specified (increases every time chaincode is upgraded)
Package ID — Auto-specified when you choose a peer
Init required — If checked, ensures the Init function is invoked before any other function and only once
Private collection (optional) — For private data between specific organizations
Each Endorser organization needs to approve the same chaincode definition to commit it on a channel. Only the peer and Package ID differ per organization.
You cannot approve a chaincode definition twice. If you see an error, check if it was already approved.
After approval, you can see the chaincode commitment status at the Chaincodes tab. When all approvals per the channel policy are received, you can commit.
How to Commit a Chaincode?
Go to the Channels tab, open the specific channel, and click Commit chaincode under the Chaincodes section. Select a peer and the chaincode, then click Save.
Only an organization with endorser rights on the channel who approved this chaincode definition earlier can commit it.
Sometimes you cannot commit a chaincode even after all endorser approvals. This can be caused by no anchor peer specified for some organizations — without an anchor peer, the organization's peers won't be returned in a discovery service request.
After successful commitment, you can test the chaincode using the Query and Invoke buttons.
How to Upgrade a Chaincode?
Add a new chaincode version
Add the same chaincode name with a new version. See How to Add a Chaincode.
To only update the chaincode policies (without changing binaries), skip steps 1 and 2 — just approve and commit the same chaincode with a new policy.
See Upgrading a Chaincode in the Hyperledger Fabric documentation.
How to Remove a Chaincode?
Click the Remove button in the Actions column of the Chaincodes table.
Removing a chaincode will delete all chaincode deployments. Do not remove a chaincode if you want it to remain running, committed to a channel, and used by business applications.
Last updated
Was this helpful?