开发Hyperledger Composer业务网络后,如何获取底层Fabric代码?
How to Extract Underlying Fabric Code from Hyperledger Composer Business Network
Great question—even if you don’t have an immediate use case, grabbing the underlying Fabric artifacts is invaluable for client handoffs, deep customizations, or just understanding how Composer maps to the core Fabric layer. Here’s exactly how to get those files from your tutorial-network or any other Composer business network:
1. Extract from a Packaged Business Network Archive (.bna)
This is the most straightforward method if you’ve already packaged your business network into a .bna file (which you likely did during the tutorial).
- Open your terminal and navigate to the directory where your
.bnafile is stored. - Run this Composer CLI command to extract the contents into a new folder (replace
tutorial-network.bnaandfabric-outputwith your actual file name and desired output directory):composer archive extract --archiveFile tutorial-network.bna --outputDir fabric-output - Inside the
fabric-outputfolder, you’ll find achaincodedirectory. This contains the Node.js chaincode that Composer generates to run on Hyperledger Fabric. This is the direct "Fabric code" you’re looking for—it includes all the logic from your business network translated into Fabric-compatible chaincode, plus dependencies and configuration files likepackage.json.
2. Generate Directly from Your Local Business Network Project
If you haven’t packaged your network yet, you can generate the Fabric chaincode artifacts directly from your project files:
- Navigate to your business network project root (the folder with your
model.cto,logic.js, etc.). - Run this command to generate the chaincode and related artifacts (again, replace
fabric-outputwith your preferred directory):composer runtime generate --businessNetworkName tutorial-network --outputDir fabric-output --language javascript - The
fabric-outputfolder will now contain the full chaincode package ready to deploy to Fabric. The chaincode does rely on Composer’s runtime libraries, but these are included in the package so it can be deployed using standard Fabric tooling.
Key Notes for Client Delivery
- When handing this off to a client, pair the chaincode with basic Fabric deployment instructions (like how to install/instantiate the chaincode on a Fabric network) if they aren’t using Composer.
- The extracted chaincode works seamlessly with standard Fabric commands—clients can use
peer chaincode installandpeer chaincode instantiatejust like with any other native Fabric chaincode.
内容的提问来源于stack exchange,提问作者E. Erfan
相关产品推荐
相关产品推荐

