Moriarty
Moriarty

Reputation: 535

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. 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
The docs claim the method is expecting a ChaincodeInvokeRequest object however the code is not expecting an object. 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.

Upvotes: 0

Views: 348

Answers (1)

Itération 122442
Itération 122442

Reputation: 2962

This happens when the args property contains data that are not of type 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.

In your sample, I assume mockAsset is a json object. From my experience, you should stringify your json and then parse it back in your chaincode.

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):

mockAsset = JSON.parse(args[0]) 

programming model >= 1.4

mockAsset = JSON.parse(myParam)

For this answer to be complete, you should tell us what is mockAsset.

Upvotes: 2

Related Questions