Search code examples
hyperledger-fabricchaincode

fabric chaincode invocation arguments usage


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?


Solution

  • 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.