For the complete documentation index, see llms.txt. This page is also available as Markdown.

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:

  1. Ensuring all parties mentioned in the endorsement policy have signed the transaction

  2. 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:

1

Add Chaincode Template

Create a Docker image and provide a link to the Docker repository when adding a chaincode template in Catalyst Blockchain Manager.

2

Install the Chaincode on Your Peers

Every organization that will use the chaincode to endorse a transaction or query the ledger needs to complete this step.

3

Approve a Chaincode Definition

Every organization that will use the chaincode needs to complete this step. The chaincode definition needs to be approved by a sufficient number of organizations to satisfy the channel's Lifecycle Endorsement policy.

4

Commit the Chaincode Definition

Once all necessary approvals are received, commit the definition to the channel.

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):

Indexes can only be applied to CouchDB. LevelDB does not support indexes.

Click Save to add the chaincode template.

Chaincode statuses
Status
Description

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?

1

Go to the Channels tab

Open the specific channel where you need to approve the chaincode.

2

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

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?

1

Add a new chaincode version

Add the same chaincode name with a new version. See How to Add a Chaincode.

2

Install the new chaincode on your peers

3

Approve the new chaincode definition

4

Commit the definition to the channel

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.

Last updated

Was this helpful?