ubuntuhyperledger-fabricblockchainchaincode

How can I rectify from Error: flag needs an argument: 'c' in -c?


I used the following command to initialise the chaincode after committing it to the hyperledger fabric test network.

peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C testchannel -n property --peerAddresses localhost:7051 --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE_ORG1 --peerAddresses localhost:9051 --tlsRootCertFiles $CORE_PEER_TLS_ROOTCERT_FILE_ORG2 --isInit -c `{"Args":[]}`

Then I encountered with the following error,

{Args:[]}: command not found
Error: flag needs an argument: 'c' in -c

Error Screenshot

How can I rectify this error. Thanks in advance!


Solution

  • I'm not sure about this as I don't generally use the --isInit flag, but I believe that if it is used, you need to have an Init function in your contract to match the expectation of this flag i.e. it should have a method signature to suit what use of the flag expects to find.

    I tend not to use the flag and instead, call a home grown Init function, as shown below.

    -c '{"function":"initLedger","Args":[]}'
    

    Have a look at this link if you haven't already.