This video provides a step-by-step walkthrough of the process for deploying chaincode (smart contracts) on a Hyperledger Fabric network using the platform's management interface. You'll learn how to package, install, approve, and commit chaincode, as well as how to verify a successful deployment.
Overview
Hyperledger Fabric uses a multi-step chaincode lifecycle that ensures all network participants agree on the chaincode before it becomes active on a channel. The lifecycle consists of:
- Package -- Bundle chaincode source code into a deployable package (
.tar.gz). - Install -- Install the chaincode package on each peer that needs to execute it.
- Approve -- Each organization approves the chaincode definition for their org.
- Commit -- Once enough organizations have approved (satisfying the lifecycle endorsement policy), the chaincode definition is committed to the channel and becomes available for invocations.
ChainLaunch provides both a manual step-by-step API for each phase and an automated deploy endpoint that handles the entire lifecycle in one call.
CLI Commands
| Command | Purpose |
|---|---|
chainlaunch fabric chaincode create |
Register a chaincode on a channel |
chainlaunch fabric chaincode definition create |
Create a new definition (version, sequence, policy, image) |
chainlaunch fabric chaincode install |
Install the package on one or more peers |
chainlaunch fabric chaincode approve |
Approve the definition for an organization |
chainlaunch fabric chaincode commit |
Commit the definition to the channel |
chainlaunch fabric chaincode deploy |
Deploy (or redeploy) the chaincode container |
chainlaunch fabric chaincode invoke |
Submit a transaction (write) |
chainlaunch fabric chaincode query |
Evaluate a read-only function |
See Chaincode CI/CD with the CLI for the full lifecycle, image-bump flow, and pipeline integration.
Quickstart with the CLI
For a CCaaS chaincode deployed by docker image (the standard ChainLaunch pattern), the full lifecycle is documented in Chaincode CI/CD with the CLI. The TL;DR is:
# 1. Register the chaincode on the channel
chainlaunch fabric chaincode create \
--channel mychannel --chaincode mycc
# 2. Create the initial definition (sequence auto-bumps; version defaults to 1.0)
chainlaunch fabric chaincode definition create \
--channel mychannel --chaincode mycc \
--image kfsoftware/external-chaincode:v1.0 \
--policy "AND('Org1MSP.peer','Org2MSP.peer')"
# 3. Install on each peer (slug or numeric ID)
chainlaunch fabric chaincode install \
--channel mychannel --chaincode mycc \
--peer org1-peer0,org2-peer0
# 4. Approve from each org
chainlaunch fabric chaincode approve \
--channel mychannel --chaincode mycc --org Org1MSP
chainlaunch fabric chaincode approve \
--channel mychannel --chaincode mycc --org Org2MSP
# 5. Commit once
chainlaunch fabric chaincode commit \
--channel mychannel --chaincode mycc --org Org1MSP
# 6. Start the container
chainlaunch fabric chaincode deploy \
--channel mychannel --chaincode myccListing Chaincodes
chainlaunch fabric chaincode definition list \
--channel mychannel --chaincode myccInvoking Chaincode
Submit a transaction that writes to the ledger:
KEY_ID=$(chainlaunch keys list --org Org1MSP --type client --first --output id)
chainlaunch fabric chaincode invoke \
--channel mychannel --chaincode mycc \
--fcn CreateAsset --key-id "$KEY_ID" \
-a asset1 -a blue -a 10 -a Alice -a 1000Querying Chaincode
Read data from the ledger without submitting a transaction:
chainlaunch fabric chaincode query \
--channel mychannel --chaincode mycc \
--fcn ReadAsset --key-id "$KEY_ID" \
-a asset1Upgrading Chaincode
To upgrade an existing chaincode, repeat the lifecycle with an incremented chaincodeSequence value and (optionally) a new chaincodeVersion. For example, to upgrade from sequence 1 to 2:
- Install the new chaincode package on all peers.
- Approve with
chaincodeSequence: 2. - Commit with
chaincodeSequence: 2.
Or use the automated deploy endpoint with the updated sequence number.
Troubleshooting
| Issue | Possible Cause | Solution |
|---|---|---|
| Install fails | Peer not running or unreachable | Verify peer status in the nodes list |
| Approve fails | Chaincode not installed on the peer | Install chaincode before approving |
| Commit fails | Not enough organizations have approved | Ensure all required orgs have approved |
| Invoke returns error | Chaincode not committed on channel | Verify chaincode is committed and peers have joined the channel |
| Query returns empty | Data not yet written | Invoke a write transaction first |