Skip to content

Running a javascript chaincode at AMB

0

I created a hyperledger fabric network. Then I successfully installed and exeucted the abstore chaincode implemented in Go. However, when I tried to run a javascript chaincode (actually fabcar), it failed. I checked the chaincode log and got the following messages.

I think that main problem is "sh: fabric-chaincode-node: not found". It means to me that fabric-chaincode-node is not installed at the peer node. Please give me any hints to solve this.

========== log messages: more recent first ============

      1. 오전 4:10:04

npm ERR! /root/.npm/_logs/2025-02-19T04_10_04_032Z-debug.log

      1. 오전 4:10:04 npm ERR! A complete log of this run can be found in:
      1. 오전 4:10:04 npm WARN Local package.json exists, but node_modules missing, did you mean to install?
      1. 오전 4:10:04 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
      1. 오전 4:10:04 npm ERR! Failed at the fabcar@1.0.0 start script.
      1. 오전 4:10:04 npm ERR!
      1. 오전 4:10:04 npm ERR! spawn ENOENT
      1. 오전 4:10:04 npm ERR! fabcar@1.0.0 start: fabric-chaincode-node start "--peer.address" "nd-s7r2nwwd4rfctdjb5hxmmgrjam.m-vejze2zp4rfaph7hauzvdqjmtq.n-tsnwhuqxkbhhpdkkjqnqo2b6gu.managedblockchain.ap-northeast-2.amazonaws.com:7052"
      1. 오전 4:10:04 npm ERR! errno ENOENT
      1. 오전 4:10:04 npm ERR! file sh
      1. 오전 4:10:04 npm ERR! syscall spawn
      1. 오전 4:10:04 npm ERR! code ELIFECYCLE
      1. 오전 4:10:04 sh: fabric-chaincode-node: not found
      1. 오전 4:10:04

fabric-chaincode-node start "--peer.address" "nd-s7r2nwwd4rfctdjb5hxmmgrjam.m-vejze2zp4rfaph7hauzvdqjmtq.n-tsnwhuqxkbhhpdkkjqnqo2b6gu.managedblockchain.ap-northeast-2.amazonaws.com:7052"

      1. 오전 4:10:04

fabcar@1.0.0 start /usr/local/src

asked a year ago110 views
1 Answer
0

The issue you're encountering is related to the way Node.js chaincode is packaged and deployed on Amazon Managed Blockchain (AMB). Due to security requirements, peer nodes in AMB don't have internet access, which means they can't download external dependencies at runtime when building or executing chaincode.

To resolve this, you need to bundle the Node.js chaincode with its dependencies before deploying. Here are some steps to help you solve this issue:

  1. Navigate to the root directory of your chaincode (where the package.json file is located).

  2. Run npm install to install all the required dependencies.

  3. Move the node_modules directory to a new directory called 'lib':

    mv node_modules/ lib
    
  4. Modify the start script in your package.json file to point to the new location of the dependencies:

    "scripts": {
      "start": "NODE_PATH=lib fabric-chaincode-node start"
    }
  5. Package your chaincode manually in a tar.gz format, including the lib directory (which contains node_modules) and any other necessary files.

  6. Use this manually created package to install, approve, and commit your chaincode using the Chaincode Lifecycle commands.

If you're using the fabric-contract-api or TypeScript, you might need to package the chaincode differently. In this case, you should manually create a package that includes the node_modules folder intact, along with your source code and a metadata.json file.

By bundling the dependencies with your chaincode, you ensure that all necessary modules, including fabric-chaincode-node, are available when the chaincode is executed on the peer node.
Sources
How bundle and commit Node.js chaincode on Amazon Managed Blockchain Hyperledger Fabric | AWS re:Post
How to bundle and commit Node.js chaincode on Amazon Managed Blockchain Hyperledger Fabric | AWS re:Post

answered a year ago
  • I tried this. But it shows the same error messages. "sh: fabric-chaincode-node: not found". It seems to me that the file "fabric-chaincode-node" does not exist in the peer node. Did AWS change to omit javascript chaincode? The documentation has only for Java chaincode for special case. There is not document for javascript chaincode.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.