0

I am trying to write a chainCode and for the implementation of logic, I need to use an external node package, which is not a part of fabric API. Is it possible to do that?

I've never seen a chainCode example, which requires an external node module. If you know an example please share with me.

Also, if it is possible, I would like to know about the risks of doing that and what is the good design to minimize the risks.

ethertest
  • 317
  • 4
  • 13
  • FYI - probably best to use the Hyperledger mailing list and/or Hyperledger Chat for these types of questions. – Gari Singh Jun 11 '19 at 08:14
  • You can actually use any package which is available via `npm` with your Node.js chaincode. When you add it to your chaincode, just make it's also included in your `package.json`. – Gari Singh Jun 11 '19 at 08:17
  • [Pratik Patil](https://stackoverflow.com/users/13795709) wrote an [Answer](https://stackoverflow.com/a/65066858) saying "Yes it is possible to create a chaincode server using node fabric-shim API: https://hyperledger.github.io/fabric-chaincode-node/master/api/tutorial-using-chaincodeinterface.html" – Scratte Nov 30 '20 at 01:22

1 Answers1

0

'use strict'

const { Shim } = require('fabric-shim')

const path=require("path")

const fs=require('fs')

const examplecc = require('./lib/examplecontract.js')

function main(){

const tlsCertsPath=path.resolve(__dirname,"lib", "tls")

const tlsKey = fs.readFileSync( path.resolve(tlsCertsPath, "server.key"))
const tlsCert = fs.readFileSync(path.resolve(tlsCertsPath, "server.crt"))
const rootCert = fs.readFileSync(path.resolve(tlsCertsPath, "ca.crt"))
const config={
ccid:       
         

"examplecc:1177322ea1cb10e56c4499016dsdb2fbf0be155660e97a38ca48de76326b12362",

address:   "0.0.0.0:9992"}


 const server= Shim.server(new examplecc(),{
  

 ccid:    config.ccid,

    address: config.address,

    tlsProps: {
        disabled:      true,
        key:           tlsKey,
        cert:          tlsCert,
        clientCACerts: rootCert,
    }
} )


server.start().then((res)=>{
    console.log("Server running successfully @" + config.address )
})

}

main()