Search code examples
node.jshyperledger-fabrichyperledgerhyperledger-chaincode

Is it possible to package the Hyperledger Fabric chaincode using the node SDK?


I use hyperledger fabric V1.4.10 I created a deployer app that installs and upgrades my chaincode using the node SDK API and everything works great but I am storing all my project compressed in a zip file as an artifact and I would like to have a smaller artifact to store, off course I'm adding the node modules, the js and the ts files, as I'm not completely sure if they are needed or not during deployment.

I would like to be able to do the same that is done using "peer chaincode package" from my deployer app to be able to package my code in an efficient way.

I have seen in the SDK a BasePackager class that seems to be able to package the code, but I can´t find any examples of how to use it.

Also looking inside the js code I found that the install method can receive a ChaincodeInstallRequest that can be a ChaincodePackageInstallRequest or a ChaincodePathInstallRequest.

Here's the code inside index.d.ts:

export interface ChaincodePackageInstallRequest {
    targets?: Peer[] | string[];
    channelNames?: string[] | string;
    txId?: TransactionId;
    chaincodePackage: Buffer;
}

export interface ChaincodePathInstallRequest {
    targets?: Peer[] | string[];
    channelNames?: string[] | string;
    txId?: TransactionId;
    chaincodeId: string;
    chaincodeVersion: string;
    chaincodePath: string;
    chaincodeType?: ChaincodeType;
    metadataPath?: string;
}

export type ChaincodeInstallRequest = ChaincodePackageInstallRequest | ChaincodePathInstallRequest;

So I was wondering, is it possible to use the SDK to package your code? or should I use the "peer chaincode package" option instead? Also, after packaging my code, can I use the SDK to install it? or do I need to do it using the "peer chaincode install" option better?

Thanks


Solution

  • Node SDK

    The Node SDK does not (currently) include admin capabilities such as lifecycle deployment of chaincode. If you can use the peer CLI commands then that is probably a good option since they are well supported and maintained. Alternatively, there is at least one admin package aiming to provide this capability to Node applications: https://www.npmjs.com/package/khala-fabric-admin There is a lack of documentation.

    JAVA SDK

    The fabric-sdk-java API has some Lifecycle-related functions on HFClient and Channel:

    However, I'm not certain they are really up-to-date with the current Lifecycle deployment implementation so I'm not sure I would recommend relying on them

    The peer chaincode lifecycle CLI commands are better maintained and supported so, if you can make use of them, I would recommend that instead: https://hyperledger-fabric.readthedocs.io/en/release-2.2/commands/peerlifecycle.html