Chaincode Deployment Guide
This guide walks you through the complete process of deploying chaincode to your FireFly stack, from packaging to registration and testing.
Before proceeding, ensure you have:
- Completed the Chaincode Development Setup
- A running FireFly stack (see FireFly Stack Setup)
- Node.js and npm installed for chaincode dependencies
Overview
The deployment process consists of four main steps:
- Package - Bundle your chaincode into a deployable format
- Deploy - Upload the package to the Fabric network
- Define Interface - Create a contract interface in FireFly
- Register API - Register the chaincode as a callable API
Step 1: Package the Chaincode
Navigate to the Chaincode Directory
First, navigate to the package chaincode directory:
cd chaincodes/package
Create Core Configuration File
Create an empty core.yaml file:
touch core.yaml
FireFly requires this file for the packaging process to work correctly with the Hyperledger Fabric peer CLI. For more details, see the FireFly Documentation.
Install Dependencies and Package
Install the chaincode dependencies and create the package:
# Install npm dependencies
npm install
# Build chaincode
npm run package
# Package the chaincode
peer lifecycle chaincode package \
--lang node \
-p . \
--label pm3package_X.Y \
./pm3package.zip
Replace X.Y with your desired version number (e.g., 1.0, 1.1, 2.0).
Example for version 1.0:
peer lifecycle chaincode package \
--lang node \
-p . \
--label pm3package_1.0 \
./pm3package.zip
Use semantic versioning (MAJOR.MINOR) for your chaincode:
- MAJOR: Incompatible API changes
- MINOR: Backward-compatible functionality additions
Example: 1.0, 1.1, 2.0, 2.1
Verify Package Creation
Check that the package was created successfully:
ls -lh pm3package.zip
You should see the pm3package.zip file in your current directory.
Step 2: Deploy to FireFly Network
Deploy the packaged chaincode to your FireFly stack using the FireFly CLI:
ff deploy fabric dev ./pm3package.zip firefly pm3package X.Y
Parameters explained:
dev- Your stack namepm3package.zip- The package file you createdfirefly- The channel namepm3package- The chaincode nameX.Y- The version number (must match the version used in packaging)
Example for version 1.0:
ff deploy fabric dev pm3package.zip firefly pm3package 1.0
Ensure the version number (X.Y) matches exactly what you used when packaging the chaincode in Step 1.
Verify Deployment
The deployment process will:
- Install the chaincode on all peer nodes
- Approve the chaincode for all organizations
- Commit the chaincode definition to the channel
Watch the output for any errors. A successful deployment will show approval and commitment messages for all organizations.
Step 3: Define Contract Interface
Now you need to define the contract interface in FireFly so it knows how to interact with your chaincode.
Get the Interface Definition
- Navigate to the interface definition file:
- Copy the entire JSON content
Upload to FireFly
Option 1: Using the Sandbox UI
-
Open the FireFly Sandbox for any node:
- Organization 1: http://127.0.0.1:5108/home?action=contracts.interface
- Organization 2: http://127.0.0.1:5208/home?action=contracts.interface
-
Navigate to Contracts → Define a Contract Interface
-
Paste the interface JSON content into the editor
-
Update the version in the interface to match your deployed version (e.g.,
1.0) -
Click Run to create the interface
Ensure the version in the interface definition matches the version you deployed in Step 2. Mismatched versions will cause invocation errors.
Step 4: Register Contract API
The final step is to register your chaincode as a callable API in FireFly.
Access the Registration Form
-
Open the FireFly Sandbox:
- Organization 1: http://127.0.0.1:5108
- Organization 2: http://127.0.0.1:5208
-
Navigate to Contracts → Register Contract API
Or use direct link: http://127.0.0.1:5108/home?action=contracts.api
Fill in the Registration Form
Provide the following information:
| Field | Value | Example |
|---|---|---|
| Contract Interface | Select from dropdown | The interface you defined in Step 3 |
| Name | packagename_X.Y | pm3package_1.0 |
| Chaincode | Same as Name | pm3package_1.0 |
| Channel | Channel name | firefly |
Use the format packagename_X.Y where:
packagenameis your chaincode name (e.g.,pm3package)X.Yis your version number (e.g.,1.0)
This keeps your registrations organized and version-aware.
Complete Registration
Click Register to complete the process.
Upon successful registration, your chaincode API will be available for invocation through FireFly's API endpoints and UI.
Verify Your Deployment
Check Contract APIs
- In the FireFly Sandbox, navigate to Contracts → Contract APIs
- You should see your newly registered API listed
- Click on it to view available methods
Test Invocation
Try invoking a method to verify everything is working:
- Go to Contracts → Invoke Method
- Select your contract API
- Choose a method to test
- Provide required parameters
- Click Run
The Sandbox provides an excellent environment for testing your chaincode methods before integrating them into your application.
Deployment Checklist
Use this checklist to ensure you've completed all steps correctly:
- Navigated to
chaincodes/packagedirectory - Created empty
core.yamlfile - Installed npm dependencies with
npm install - Packaged chaincode with consistent version number
- Deployed package to FireFly network
- Retrieved interface definition from GitHub
- Defined contract interface in FireFly
- Verified interface version matches deployment
- Registered contract API with correct parameters
- Verified API appears in Contract APIs list
- Tested at least one method invocation
Updating Chaincode
When you need to update your chaincode:
Update Process
- Increment the version number (e.g., from
1.0to1.1or2.0) - Repeat the packaging process with the new version
- Deploy the new version to the network
- Update the interface with the new version
- Register the new API with the updated version number
Version Strategy
# Bug fixes and minor changes
pm3package_1.0 → pm3package_1.1
# Breaking changes or major features
pm3package_1.0 → pm3package_2.0
FireFly allows multiple versions of the same chaincode to coexist on the network, enabling gradual migration strategies.
Troubleshooting
Package Creation Fails
Problem: Error during peer lifecycle chaincode package
Solutions:
# Ensure peer binary is accessible
which peer
# Verify you're in the correct directory
pwd # Should show .../chaincodes/package
# Check core.yaml exists
ls -la core.yaml
# Verify npm dependencies are installed
ls -la node_modules
Deployment Fails
Problem: ff deploy command fails or hangs
Solutions:
# Stop the running firefly stack
ff stop dev
# Remove the stopped firefly stack
ff rm dev
Then recreate the stack and follow the same steps again according to the documentation. You can find the initalization step here.
Next Steps
🎉 Congratulations! Your chaincode is now deployed and ready to use.
What's Next?
- Integrate with Applications: Use the FireFly API to call your chaincode from applications
- Explore APIs: Review the FireFly API Documentation
- Monitor Transactions: Use the FireFly UI to monitor blockchain transactions
- Develop More Chaincodes: Apply this process to deploy additional smart contracts