Instantiate Chaincode on BYFN Channel

Q

How to Instantiate Chaincode on BYFN Channel?

✍: FYIcenter.com

A

You can follow this tutorial to Instantiate Chaincode on BYFN Channel manually.

1. Verify the installed chaincode:

$ docker exec -it cli bash

bash-4.4# echo $CORE_PEER_ADDRESS
peer0.org2.example.com:7051

bash-4.4# peer chaincode list --installed
Get installed chaincodes on peer:
Name: mycc, Version: 1.0, Path: /opt/gopath/src/github.com/chaincode\
   /chaincode_example02/node/, Id: ade2b27...

2. Instantiate the chaincode on the "mychannel" channel:

bash-4.4# peer chaincode instantiate -o orderer.example.com:7050 --tls \
   --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto\
   /ordererOrganizations/example.com/orderers/orderer.example.com/msp\
   /tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -v 1.0 \
   -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"

[chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
[chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc

Error: could not assemble transaction, err proposal response was not 
successful, error code 500, msg error starting container: error starting 
container: Failed to generate platform-specific docker build: Failed to 
pull hyperledger/fabric-nodeenv:latest: API error (404): manifest for 
hyperledger/fabric-nodeenv:latest not found

As you can see, the "peer chaincode instantiate" command failed. The error is related the anchor peer in each peer organization. You need to redo the step of updating peer0 as the anchor peer in each organization using the "peer channel update" command.

3. Try again:

bash-4.4# peer chaincode instantiate -o orderer.example.com:7050 --tls \
   --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto\
   /ordererOrganizations/example.com/orderers/orderer.example.com/msp\
   /tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -v 1.0 \
   -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"

   
[chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
[chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc

Error: could not assemble transaction, err proposal response was not 
successful, error code 500, msg cannot get package for chaincode (mycc:1.0)

The command failed again. The error is related the missing chaincode on the anchor peer. You need to redo the step of installing chaincode on the anchor peer in each organization using the "peer chaincode install" command.

4. Try again:

bash-4.4# peer chaincode instantiate -o orderer.example.com:7050 --tls \
   --cafile /opt/gopath/src/github.com/hyperledger/fabric/peer/crypto\
   /ordererOrganizations/example.com/orderers/orderer.example.com/msp\
   /tlscacerts/tlsca.example.com-cert.pem -C mychannel -n mycc -v 1.0 \
   -c '{"Args":["init","a", "100", "b","200"]}' -P "AND ('Org1MSP.peer','Org2MSP.peer')"

[chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
[chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc

No more errors. The chaincode is instantiated on the channel with initial value of ["init","a", "100", "b","200"].

5. Verify the instantiated chaincode:

bash-4.4# peer chaincode list -C mychannel --instantiated

Get instantiated chaincodes on channel mychannel:
Name: mycc, Version: 1.0, Path: github.com/chaincode/chaincode_example02/go/, \
   Escc: escc, Vscc: vscc

 

Query Chaincode Property on BYFN Channel

Install Chaincode on BYFN Peers

BYFN (Build Your First Network)

⇑⇑ Hyperledger Tutorials

2019-04-14, 5666🔥, 0💬