0

When in invoking a chaincode, what is the correct way of selecting the method you wish to invoke, for example, the following commands works and produce same results:

peer chaincode invoke -n basic_go -C mychannel -c '{"function":"GetAllAssets","Args":[]}'

peer chaincode invoke -n basic_go -C mychannel -c '{"Args":["GetAllAssets"]}'

You notice the first one names the function within the function property, the second invocation, uses the first argument of the Args array to do so.

For GetAllAssets works, but for CreateAsset for instance, it doesn't. You can only invoke it using the latter approach. I'm testing with https://github.com/hyperledger/fabric-samples/tree/main/asset-transfer-basic/chaincode-go

I have not been able to find any clarification in the docs regarding this matter. Should the method be call separately as a property function, or as a first argument?

Matias Salimbene
  • 510
  • 6
  • 19

1 Answers1

2

I just tested this in my system and both methods are actually working for all chaincode invokes and queries. This is the part of the source code where the function and args are read. They are considering both cases there.

Basil K Y
  • 490
  • 5
  • 8
  • I think you are correct. However while testing I found that the InitLedger function didn't fail (return 200) but did nothing unless I specified both peers with `--peerAddresses --tlsRootCertFiles` params. I guess it has something to do with my local config. In the docs, it's only passing the orderer. – Matias Salimbene Oct 05 '22 at 15:37