Invoking chaincode

Now we have a running chaincode, we can start to invoke some functions. Our chaincode has several methods that create and retrieve assets. For now, we will only invoke two of them; the first creates a new trade agreement and the second retrieves it from the ledger. To do this, complete the following steps:

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

We now have a running network in devmode and we have tested our chaincode successfully. In the following section, we will learn how to create and test chaincode from scratch.

Dev Mode
In a production environment, the lifetime of the chaincode is managed by the peer. When we need to repeatedly modify and test the chaincode in a development environment, we can use devmode, which allows the developer to control the life cycle of the chaincode. Additionally, devmode directs the stdout and stderr standard files into the terminal; these are otherwise disabled in a production environment.

To use devmode, the peer must be connected to other network components, as in a production environment, and started with the argument peer-chaincodedev=true. The chaincode is then started separately and configured to connect to the peer. The chaincode can be repeatedly compiled, started, invoked, and stopped as needed from the terminal during development.

We will use the devmode enabled network in the following sections.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset