调用链码、Node SDK、方法时出错:channel.sendTransactionProposal()
Error Invoking Chaincode, Node SDK, Method: channel.sendTransactionProposal()
当我尝试发送交易建议时,我收到了来自 hyperledger fabric node sdk 的 TypeError。下面是我的调用代码:
const prop_response = await channel.sendTransactionProposal({
targets: peers,
chaincodeId: "ccid1",
fcn: ADD_ASSET,
args: [mockAsset],
txId: client.newTransactionID()
});
可以在此处找到该方法的文档:https://fabric-sdk-node.github.io/Channel.html#sendTransactionProposal__anchor
文档声称该方法需要一个 ChaincodeInvokeRequest 对象,但是代码不需要一个对象。以下是错误:
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type object
at Function.from (buffer.js:225:9)
如有任何帮助,我们将不胜感激。
当 args
属性 包含非 string, Buffer, ArrayBuffer, Array, or Array-like Object.
类型的数据时会发生这种情况
确保数组的每个参数都匹配所需的类型。例如检查是否没有 undefined
个元素。
在您的示例中,我假设 mockAsset
是一个 json 对象。根据我的经验,你应该将你的 json 字符串化,然后在你的链代码中解析它。
const prop_response = await channel.sendTransactionProposal({
targets: peers,
chaincodeId: "ccid1",
fcn: ADD_ASSET,
args: [JSON.stringify(mockAsset)],
txId: client.newTransactionID()
});
在您的链代码中(编程模型 < 1.4):
mockAsset = JSON.parse(args[0])
编程模型 >= 1.4
mockAsset = JSON.parse(myParam)
为了使这个答案完整,您应该告诉我们什么是 mockAsset
。
当我尝试发送交易建议时,我收到了来自 hyperledger fabric node sdk 的 TypeError。下面是我的调用代码:
const prop_response = await channel.sendTransactionProposal({
targets: peers,
chaincodeId: "ccid1",
fcn: ADD_ASSET,
args: [mockAsset],
txId: client.newTransactionID()
});
可以在此处找到该方法的文档:https://fabric-sdk-node.github.io/Channel.html#sendTransactionProposal__anchor
文档声称该方法需要一个 ChaincodeInvokeRequest 对象,但是代码不需要一个对象。以下是错误:
TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type object
at Function.from (buffer.js:225:9)
如有任何帮助,我们将不胜感激。
当 args
属性 包含非 string, Buffer, ArrayBuffer, Array, or Array-like Object.
确保数组的每个参数都匹配所需的类型。例如检查是否没有 undefined
个元素。
在您的示例中,我假设 mockAsset
是一个 json 对象。根据我的经验,你应该将你的 json 字符串化,然后在你的链代码中解析它。
const prop_response = await channel.sendTransactionProposal({
targets: peers,
chaincodeId: "ccid1",
fcn: ADD_ASSET,
args: [JSON.stringify(mockAsset)],
txId: client.newTransactionID()
});
在您的链代码中(编程模型 < 1.4):
mockAsset = JSON.parse(args[0])
编程模型 >= 1.4
mockAsset = JSON.parse(myParam)
为了使这个答案完整,您应该告诉我们什么是 mockAsset
。