hyperledger / fabric-gateway

Go, Node and Java client API for Hyperledger Fabric v2.4+
https://hyperledger.github.io/fabric-gateway/
Apache License 2.0
150 stars 88 forks source link

node SDK contract.Newproposal fail when used with arguments #605

Closed a1salimbene closed 1 year ago

a1salimbene commented 1 year ago

Following documentation for "Fine-grained submit transaction" in the api docs for nodejs I'm trying to execute a transaction,

const values = JSON.stringify(payload);
const proposal = contract.newProposal(CC_TX, values);
const transaction = await proposal.endorse();
const commit = await transaction.submit();
const status = await commit.getStatus();
const result = transaction.getResult();
const txID = transaction.getTransactionId();

but I get error: chaincode response 500, Incorrect number of params. Expected 1, received 0 The documentation doesn't state a particular way to pass arguments to the chaincode this way. I tried const proposal = contract.newProposal(CC_TX, { arguments: values }); and I get chaincode response 500, could not unmarshal txValues unexpected end of JSON input

Looking inside the chaincode execution pod, I noticed that the values arguments is passed using either method, although the latter seems to add {.

I haven't been able to find samples newProposal passing arguments with the nodeJS SDK. Is it even supported?

a1salimbene commented 1 year ago

I was able to make it work by passing arguments as follow:

const proposal = contract.newProposal("name", { arguments: [values]);

But I believe that isn't documented, or am I looking at the wrong api docs?

andrew-coleman commented 1 year ago

https://hyperledger.github.io/fabric-gateway/main/api/node/interfaces/ProposalOptions.html#arguments