Explore Courses Blog Tutorials Interview Questions
0 votes
in Blockchain by (12.7k points)

Is it possible to update or alter smart contract (chaincode) deployed in Hyperledger network? i.e. I have deployed a smart contract, Blocks are created with transactions, after some time, I want to alter the chain code, is it possible to do that

1 Answer

0 votes
by (29.5k points)
edited by

we cannot update the installed chaincode for a certain channel, but we can use the chaincode version to distinguish with the newer updated chaincode from older chaincode.To  use newly updated chaincode, we have to install the updated chaincode with the new version with same chaincode name as the older chaincode name on a peer:

peer chaincode install -p chaincodedev/chaincode/sacc -n mycc -v 1

See the -v tag in the above command with version 1 and -n tag with c

haincode name.

Then upgrade the
on the channel:

peer chaincode upgrade -n mycc -v 1 -c '{"Args":["a","10"]}' -C myc

See the -v tag again in
above command with version 1, -n tag with c

haincode name and -C tag with channel name on which it is instantiated.
So, once 
chaincode is installed and upgraded it retains on the channel and we can use newer updated chaincode by upgrading them. When we invoke the chaincode on a peer it will invoke the latest chaincode
that is installed on a channel.


Browse Categories