Hyperledger Fabric How to run node js chaincode in dev mode

+2 votes

I am trying to build my chaincode using the following command:

node main-chaincode.js --peer.address peer:7052

I get the following error message:

Error: Illegal value for namevalue element of type string: undefined (not a string) at fail
(/opt/gopath/src/chaincode/lavinias_chaincode/node/node_modules/protobufjs/dist/protobuf.js:1817:23) at
(/opt/gopath/src/chaincode/lavinias_chaincode/node/node_modules/protobufjs/dist/protobuf.js:1879:25) at
(/opt/gopath/src/chaincode/lavinias_chaincode/node/node_modules/protobufjs/dist/protobuf.js:3499:33) at
(/opt/gopath/src/chaincode/lavinias_chaincode/node/node_modules/protobufjs/dist/protobuf.js:2582:77) at
Function.start (/opt/gopath/src/chaincode/lavinias_chaincode/node/node_modules/fabric-shim/lib/chaincode.js:118:15) at start (/opt/gopath/src/chaincode/lavinias_chaincode/node/main-chaincode.js:46:8) at Object. (/opt/gopath/src/chaincode/lavinias_chaincode/node/main-chaincode.js:49:1) at
Module._compile (module.js:643:30) at Object.Module._extensions..js (module.js:654:10) at Module.load
(module.js:556:32):654:10) at Module.load (module.js:556:32)

Here is my chaincode:

    'use strict';
const shim = require('fabric-shim');
const Chaincode = class {
  async Init(stub) {
       let ret = stub.getFunctionAndParameters();
       let args = ret.params;
       if(args.length != 2) {
         return shim.error("Error. Invalid call arguments.")
       await stub.putState(args[0], Buffer.from(args[1]));

       return shim.success('Initialized Successfully!');

   async Invoke(stub) {
       let functionAndParams = stub.getFunctionAndParameters();
       if(functionAndParams.fcn === 'get') {
         return get(stub, functionAndParams.params);
       else if(functionAndParams.fcn === 'set'){
         return set(stub, functionAndParams.params);
       return shim.error("Error. Invalid invocation.");

function get(stub, params) {
  if(params.length != 1) {
    return shim.error("Error. Invalid invocation call.");
  return stub.getState(params[0]);

function set(stub, params) {
  if(params.length != 2) {
    return shim.error("Error. Invalid number of arguments.");
  return stub.putState(params[0], params[1]);

var start = function start(){
  var cc = new Chaincode();


Can someone help me?

Nov 2, 2018 in Blockchain by digger
• 26,740 points

3 answers to this question.

+2 votes
Best answer

Hi, the command you are using to build is not right. Use this to build:

 CORE_CHAINCODE_ID_NAME="mycc:v0" node main-chaincode.js --peer.address peer:7052
answered Nov 2, 2018 by Omkar
• 69,230 points

selected May 6, 2019 by digger
+1 vote

To run the chaincode in dev mode, try this command:

$ peer chaincode install -l node -n mycc -p /opt/gopath/src/github.com/mycc -v v0
answered May 6, 2019 by Kriti
This is just for installing the chaincode. After the successfull install make sure that you instantiate it properly.
0 votes

I used the following command and it worked like a charm:

$ $(npm bin)/fabric-chaincode-node start --peer.address localhost:7052 --chaincode-id-name "mycontract:v0"
answered May 6, 2019 by Nati

Related Questions In Blockchain

0 votes
1 answer
+1 vote
2 answers

How to return value from a chaincode in Hyperledger Fabric?

Hyperledger Fabric supports only 2 types of ...READ MORE

answered Jun 13, 2018 in Blockchain by Perry
• 17,100 points
0 votes
1 answer

How to set chaincode path in Hyperledger Fabric?

For chaincode to properly run on your ...READ MORE

answered Jul 27, 2018 in Blockchain by digger
• 26,740 points
0 votes
0 answers

How to set chaincode path in Hyperledger Fabric in fabric.sh file

i set the path to chaincode in ...READ MORE

Mar 23, 2019 in Blockchain by Malik

retagged Mar 25, 2019 by Omkar 1,211 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
0 votes
1 answer

Docker: How to connect Node.js in container to Hyperledger Fabric?

You need to map ~/.composer/cards of your Docker host ...READ MORE

answered Oct 31, 2018 in Blockchain by Omkar
• 69,230 points
0 votes
1 answer
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP