1

Can we able to use NPM modules other than fabric-shim and fabric-contract-api in chaincode?

If so how the packages will install while instantiating?

2 Answers2

1

Yes you can, just add the dependency to your package.json and require or import the dependency in your code as you would do normally. For your node.js chaincode during instantiation as part of building the chaincode image, npm install --production is done.

david_k
  • 5,843
  • 2
  • 9
  • 16
1

Yes, you can.

As an example you can add the Moment.js package to deal with working with time and dates in a better way:

"dependencies": {
    "fabric-contract-api": "~1.4.0",
    "fabric-shim": "~1.4.0",
    "moment": "2.24.0"
},

When you instantiate the chaincode for a channel, the peers which receive the request will all proceed to download the dependencies. This means they need access to make outbound connections.

The more dependencies you have, the more data needs to be fetched, meaning the instantiation will take longer.

Paul
  • 770
  • 1
  • 7
  • 12