当我尝试发送交易建议时,我从超级账本结构节点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)
任何帮助将不胜感激。
答案 0 :(得分:1)
当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
。