Hyperledger Fabric: Cannot update chaincode

0 votes


set -e
# don't rewrite paths for Windows Git Bash users
starttime=$(date +%s)

if [ ! -d ~/.hfc-key-store/ ]; then
    mkdir ~/.hfc-key-store/

# launch network; create channel and join peer to channel
cd ../basic-network

# Now launch the CLI container in order to install, instantiate chaincode
# and prime the ledger with our 10 tuna catches

docker-compose -f ./docker-compose.yml up -d cli
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode install -n tuna-app -v 1.0 -p github.com/test-app
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode instantiate -o orderer.example.com:7050 -C mychannel -n tuna-app -v 1.0 -c '{"Args":[""]}' -P "OR ('Org1MSP.member','Org2MSP.member')"
sleep 10
docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode invoke -o orderer.example.com:7050 -C mychannel -n tuna-app -c '{"function":"initLedger","Args":[""]}'

printf "\nTotal execution time : $(($(date +%s) - starttime)) secs ...\n\n"
printf "\nStart with the registerAdmin.js, then registerUser.js, then server.js\n\n"

I also added the following line after peer chaincode instantiate :

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode upgrade -o orderer.example.com:7050 -C mychannel -n tuna-app -c '{"function":"initLedger","Args":[""]}'

But it gives the following error:

Error: Chaincode version is not provided for upgrade

When I change upgrade statement to:

docker exec -e "CORE_PEER_LOCALMSPID=Org1MSP" -e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" cli peer chaincode upgrade -o orderer.example.com:7050 -C mychannel -n tuna-app -v 1.0 -c '{"function":"initLedger","Args":[""]}'

Error changes to:

Error: Error endorsing chaincode: rpc error: code = Unknown desc = chaincode error (status: 500, message: version already exists for chaincode with name 'tuna-app')

What is the solution for this?

Oct 31, 2018 in Blockchain by slayer
• 29,040 points

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

First, stop and delete all the containers:

docker stop $(docker ps -aq)
docker rm -f $(docker ps -aq)

Find the following image when you run docker images.

REPOSITORY TAG, IMAGE ID, CREATED, SIZE: dev-peer0.org1.example.com-tuna-app-1.0-b58eb533ofm3ed10f52cc063bda3jfj93a4272089a3f9a23hfo58nnai304jae9b, latest, 0919d7c15f0a, 6 minutes ago, 78MB

Delete it using the following command:

docker rmi 0919d7c15f0a

Run the fabric again:

npm install
node registerAdmin.js
node registerUser.js
node server.js. 

It should work

answered Oct 31, 2018 by Omkar
• 65,810 points

Related Questions In Blockchain

+16 votes
4 answers
+1 vote
2 answers
+1 vote
2 answers

How to return value from a chaincode in Hyperledger Fabric?

Hyperledger Fabric supports only 2 types of ...READ MORE

answered Jun 13, 2018 in Blockchain by Perry
• 16,450 points
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Hyperledger Fabric: cannot run chaincode from github on Ubuntu terminal

Like the error says: *SimpleChaincode does not implement ...READ MORE

answered Oct 31, 2018 in Blockchain by Omkar
• 65,810 points
0 votes
1 answer

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.