gpt4 book ai didi

javascript - 如何在开发模式下运行 hyperledger-fabric Node js 链代码?

转载 作者:太空宇宙 更新时间:2023-11-03 22:23:52 25 4
gpt4 key购买 nike

我正在尝试按照此处的教程进行操作:hyperledger-chaincode-for-developers但是当我尝试像这样构建我的链代码时:

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

我收到以下错误消息:

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)

这是我的链代码:

    '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();

hyperledger shim 文档说只需要 peer.address 参数:shim.start

任何帮助将不胜感激

最佳答案

我通过观看这个视频找到了答案:node chaincode
你应该像这样构建它:

 CORE_CHAINCODE_ID_NAME="mycc:v0" node main-chaincode.js --peer.address peer:7052

关于javascript - 如何在开发模式下运行 hyperledger-fabric Node js 链代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49720046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com