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
Element.ProtoBuf.Reflect.ElementPrototype.verifyValue
(/opt/gopath/src/chaincode/lavinias_chaincode/node/node_modules/protobufjs/dist/protobuf.js:1879:25) at
Field.ProtoBuf.Reflect.FieldPrototype.verifyValue
(/opt/gopath/src/chaincode/lavinias_chaincode/node/node_modules/protobufjs/dist/protobuf.js:3499:33) at
Message.setter
(/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();
shim.start(cc);
}
start();
Can someone help me?