HyperledgerHandsOn/trade-finance-logistics

Instantiate chaincode error - book Hands-On Blockchain with Hyperledger

Closed this issue · 8 comments

Hi,
I've installed chaincode successfully but when I tried to instantiate the chaincode as per instruction on page 250 but received the following error:

...
2018-07-03 02:42:35.654 UTC [chaincodeCmd] checkChaincodeCmdParams -> INFO 05f Using default vscc
2018-07-03 02:42:35.654 UTC [chaincodeCmd] getChaincodeSpec -> DEBU 060 java chaincode enabled
2018-07-03 02:42:35.655 UTC [msp/identity] Sign -> DEBU 061 Sign: plaintext: 0AB0070A6A08031A0C089BC5EBD90510...6E740A000A04657363630A0476736363
2018-07-03 02:42:35.655 UTC [msp/identity] Sign -> DEBU 062 Sign: digest: 26532ECA4A0FFA52BA8554EB203C324CF77E9B2E888F0890954F5E8C5DD4F70F
Error: Error endorsing chaincode: rpc error: code = Unknown desc = failed to init chaincode: handler not found for chaincode tw:0
Usage:
peer chaincode instantiate [flags]

Background:
i started the network in development mode:
$> ./trade.sh up -d true

then i build the chaincode:
$> docker exec -it chaincode bash

go build

install chaincode:
$> docker exec -it cli bash

peer chaincode install -p chaincodedev/chaincode/trade_workflow_v1 -n tw -v 0

instantiate chaincode:

peer chaincode instantiate -n tw -v 0 -c '{"Args":["init","LumberInc","LumberBank","100000","WoodenToys","ToyBank","200000","UniversalFreight","ForestryDepartment"]}' -C tradechannel

then i got the above-mentioned errors..

Any suggestion on the cause of this error?

nizam

@nizamk I don't see any instructions for chaincode instantiation on Page 250. (I only have a PDF copy at this point.) I'm guessing it's Chapter 4 you are referring to, based on the nature of your query? Page 103-104?

@jcmldev FYI.

@nizamk Based on the commands you listed above, you seem to have missed the chaincode start command, which you need to run immediatedly after go build in the chaincode container:

2. Run the chaincode with the following command:
$ CORE_PEER_ADDRESS=peer:7052 CORE_CHAINCODE_ID_NAME=tw:0 ./trade_workflow_v1

Can you verify?

Also, for invocations and queries, please use the following commands (the invoke command listed in the book in page 104 is missing an ID argument):

1. Put a new trade agreement on the ledger with the following command:
    $ peer chaincode invoke -n tw -c '{"Args":["requestTrade", "trade-12", "50000", "Wood for Toys"]}' -C tradechannel
2. Retrieve the trade agreement from the ledger with the following command:
    $ peer chaincode invoke -n tw -c '{"Args":["getTradeStatus", "trade-12"]}' -C tradechannel

The parameter trade-12 refers to the ID of a trade instance.

@VRamakrishna You're correct. Actually right after my post i just realised i had killed the chaincode after starting it. It's working now. Thanks.

BTW I also had problems with Invoke command as you had correctly pointed out. It was complaining insufficient arguments. It's working now as per your suggestion.

@VRamakrishna I have another question. When starting fabric network in dev mode, we have to start the chaincode container manually and issue start command: $ CORE_PEER_ADDRESS=peer:7052 CORE_CHAINCODE_ID_NAME=tw:0 ./trade_workflow_v1. In this command we actually starts the chaincode executable residing in ./trade_workflow_v1.

My question is why are we installing chaincode again in the following command from CLI container?
$ peer chaincode install -p chaincodedev/chaincode/trade_workflow_v1 -n tw -v 0

Earlier we had already started the chaincode in chaincode container, and now it seems to me we're installing the chaincode source codes since the path "chaincodedev/chaincode/trade_workflow_v1 " is referring to source codes.

@nizamk The goal of the dev mode is to enable control of redeployment of the chaincode by the developer, without stopping the network or any of the containers. The command is there to show how the chaincode can be installed and updated after the source code was modified.

Can we close this issue, @nizamk ?

@VRamakrishna yes sure, you can close this one. Thanks.