简体   繁体   English

调用Chaincode时出错,Node SDK,方法:channel.sendTransactionProposal()

[英]Error Invoking Chaincode, Node SDK, Method: channel.sendTransactionProposal()

I am recieving a TypeError from the hyperledger fabric node sdk when I try to send a transaction proposal. 当我尝试发送交易建议时,我从超级账本结构节点sdk收到TypeError。 Below is my calling code: 下面是我的调用代码:

    const prop_response = await channel.sendTransactionProposal({
        targets: peers,
        chaincodeId: "ccid1",
        fcn: ADD_ASSET,
        args: [mockAsset],
        txId: client.newTransactionID()
    });

The documentation for the method can be found here: https://fabric-sdk-node.github.io/Channel.html#sendTransactionProposal__anchor 该方法的文档可在以下位置找到: https : //fabric-sdk-node.github.io/Channel.html#sendTransactionProposal__anchor
The docs claim the method is expecting a ChaincodeInvokeRequest object however the code is not expecting an object. 文档声称该方法期望使用ChaincodeInvokeRequest对象,但是代码不期望使用对象。 Below is the error: 下面是错误:

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)

Any help would be greatly appreciated. 任何帮助将不胜感激。

This happens when the args property contains data that are not of type string, Buffer, ArrayBuffer, Array, or Array-like Object. args属性包含的数据类型不是string, Buffer, ArrayBuffer, Array, or Array-like Object.时,就会发生这种情况string, Buffer, ArrayBuffer, Array, or Array-like Object.

Ensure that each argument of the array match the type required. 确保数组的每个参数都与所需的类型匹配。 Check if there is no undefined elements for example. 例如,检查是否没有undefined元素。

In your sample, I assume mockAsset is a json object. 在您的示例中,我假设mockAsset是一个json对象。 From my experience, you should stringify your json and then parse it back in your chaincode. 根据我的经验,您应该对json进行字符串化,然后再将其解析回链码中。

const prop_response = await channel.sendTransactionProposal({
        targets: peers,
        chaincodeId: "ccid1",
        fcn: ADD_ASSET,
        args: [JSON.stringify(mockAsset)],
        txId: client.newTransactionID()
    });

In your chaincode (programming model < 1.4): 在您的链码(编程模型<1.4)中:

mockAsset = JSON.parse(args[0]) 

programming model >= 1.4 编程模型> = 1.4

mockAsset = JSON.parse(myParam)

For this answer to be complete, you should tell us what is mockAsset . 为了使此答案完整,您应该告诉我们什么是mockAsset

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM