In this section, we will execute the entire network setup and business workflow using a single script representing our test cases.

You can download the source code of the book from GitHub location –, if you haven’t downloaded it yet.

Go to hyperledger-fabric folder. The following shows the structure of the hyperledger-fabric folder

  • The docker file  – docker-trade-finance.yaml, discussed earlier that sets up the trade finance blockchain network, resides in the root folder.
  • The chaincode folder contains our trade finance chaincode – tradefinancecontract.go.
  • The crypto-config.yaml, explained in Defining Network Topology section earlier, is used for generating cryptographic artifacts for our entire network.
  • The script folder contains the script file, which runs the end-to-end trade finance application. The script is bootstrapped in docker-trade-finance.yaml and executed upon the network startup.
  • The script is the entry point to the application, which has commands to generate certificates and execute the end-to-end trade application using docker runtime.

To start with, change directory to hyperledger-fabric and download the IBM Hyperledger platform specific binaries by using the following command

curl -SSL | bash

You would see a bin folder created, which contains platform-specific binaries, namely cryptogen and configtxgen which are used for generating certificates and channel artifacts respectively

Let’s generate the certificates and channel artifacts for our blockchain network using the following command.

./ -m generate

The generate option calls the cryptogen for generating certificates and configtxgen for channel artifacts based on our configuration file.  We had explained the command and configuration earlier in Application Deployment section.

You should see the following output.

This would generate the crypto artifacts in the crypto-config folder and channel artifacts in the channel-artifacts folder.

If you inspect the crypto-config folder, you would see “ordererOrganizations” and “peerOrganizations” folder. If you navigate to the peerOrganizations-> and drill down to respective folders, you would see the following structure as shown below.

The msp folder contains cryptographic credentials for The keystore folder contains the User1 private key and signcerts contains the public key certificate for verification. We pass this msp path of in our script file ( to invoke functions on behalf of this user and artifacts under this path are used for identification and verification. Similarly, for all peers and users, we have a similar configuration and are being referenced in the file. 

Next, we would execute the application by running the following script:

./ -m up

As discussed earlier, this would set up the network using docker files and execute the file. The following shows the output of running the script

  • First, you would see channel -“tradechannel,” being created as shown in the figure below.
  • Next, all peers would join the channel one by one. The following shows peer 0 joining the network. Similar messages would be displayed for peer 1, peer 2, peer 3, peer 4 and peer 5.
  • Next, the chain code would be deployed on all peers. You would see a message – “Chaincode is installed on remote peer.”
  • Next, the chain code would be instantiated on peer 1. You should see a message – “Chaincode Instantiation on PEER 1 on channel ‘tradechannel’ is successful.”
  • Next, we would query the initial state after instantiation on different peers, say peer 2, which shows that chaincode is instantiated on all other peers as well.
  • Next, we would execute the createLOC command using importer bank user (i.e., Following shows the output of invocation. A successful message stating –“ Invoke:createLOC transaction on PEER PEER2 on channel ‘tradechannel’ is successful.” should be printed.
  • Next, we execute the approveLOC method using (exporter bank), initiateShipment method using (Seller) , deliverGoods method using (Shipment Org user) and shipmentDelivered method using (Buyer). After every method invocation, we query the ledger to verify the trade status,
  • At the final step, we query the status of the trade, which shows the expected output as ‘Trade completed” as shown below.

This completes an end-to-end invocation of trade finance blockchain application from grounds up. Another approach of building the blockchain application could be through an open development framework called Hyperledger Composer. Hyperledger Composer is an extensive, open development toolset and framework that makes developing blockchain applications easier. You can use Hyperledger Composer to quickly model assets, business networks, and transactions methods. The Hyperledger Composer generates an archive file that can be deployed to the blockchain network. Hyperledger Composer is under active development, and we would revisit the tooling environment in a later edition. For more details, refer to –

Tags : blockchain-guide

The author Navveen