Hyperledger Fabric: sendPeersProposal – Promise is rejected: Error: 2 UNKNOWN: chaincode error (status: 500, message: Invalid Smart Contract function name.)

This is a solution to one problem scenario while working on Hyperledger Fabric. I was working on modifying a Hyperledger Fabric Sample Application called fabcar. You can face this issue with other sample apps as well.

The issue occurred when I tried modifying the function name in the chaincode file of the sample app.

Problem:

I edited a query function name in the chaincode file of the app. Then, I tried to run node query.js command in the terminal.

Then, I got the following error:

error: [client-utils.js]: sendPeersProposal – Promise is rejected: Error: 2 UNKNOWN: chaincode error (status: 500, message: Invalid Smart Contract function name.)
at new createStatusError (/Users/mukeshchapagain/Hyperledger/fabric/fabric-samples/myapp/node_modules/fabric-client/node_modules/grpc/src/client.js:64:15)
at /Users/mukeshchapagain/Hyperledger/fabric/fabric-samples/myapp/node_modules/fabric-client/node_modules/grpc/src/client.js:583:15
Query has completed, checking results
error from query = { Error: 2 UNKNOWN: chaincode error (status: 500, message: Invalid Smart Contract function name.)
at new createStatusError (/Users/mukeshchapagain/Hyperledger/fabric/fabric-samples/myapp/node_modules/fabric-client/node_modules/grpc/src/client.js:64:15)
at /Users/mukeshchapagain/Hyperledger/fabric/fabric-samples/myapp/node_modules/fabric-client/node_modules/grpc/src/client.js:583:15
code: 2,
metadata: Metadata { _internal_repr: {} },
details: ‘chaincode error (status: 500, message: Invalid Smart Contract function name.)’ }

Solution:

To solve this issue, you need to remove the docker containers and images. After that, you can run the startFabric script.

Here are the step-by-step commands to be run to solve this issue:

docker rm -f $(docker ps -aq) && docker rmi -f $(docker images | grep dev | awk '{print $3}')
./startFabric.sh
node enrollAdmin.js
node registerUser.js
node query.js

Hope this helps. Thanks.