Overview

Skill Level: Intermediate

We show you how to work with Hyperledger Explorer as well as how to configure and integrate Explorer with Hyperledger Fabric for building decentralized blockchain applications.

Ingredients

To follow and complete this recipe, you need to have good knowledge of blockchain, Hyperledger transactions, JavaScript as well as basic knowledge of Linux.

Step-by-step

  1. Hyperledger Explorer Overview

    Hyperledger Explorer is a powerful utility that allows users to create user-friendly web-based applications. It is a blockchain dashboard and provides the ability to view, invoke, deploy, and query raw blockchain data and network information, including block details, chain codes, and transactions stored in the ledger.

    For those who are not familiar with Hyperledger project Intro to Hyperledger Family and Hyperledger Blockchain Ecosystem and Hyperledger Design Philosophy and Framework Architecture articles are strongly recommended.

    Hyperledger Explorer is a highly maintainable and open source browser that can be configured and built natively on macOS and Ubuntu. At the time of writing, Hyperledger Explorer has not yet gone live. The latest release, v0.3.8, supports Fabric v1.3.

    It is common to encounter errors here and there, especially around issues related to versions and/or setting up environments. To save time while debugging, I have included notes, along with recommended fixes, for some of errors you might run into while walking through this recipe.

    Since in our previous recipes (Overview of Hyperledger Explorer and its Development Environment as well as Installing Hyperledger Explorer and Setting up the Database), we installed Hyperledger Explorer and its pre-requisite environment, we are ready to configure the Explorer to connect to a blockchain network.

    In order to demonstrate how Hyperledger Explorer works, we need a working blockchain network, which in this case is Hyperledger Fabric. Refer to Blockchain Developer Guide- How to Install Hyperledger Fabric on AWS and follow the instructions to install all of the necessary Fabricdependencies on the platform on which you will be running your Hyperledger Explorer application. We will utilize the first-network scripts that should have been installed if you installed all of the pre-requisites for Fabric:

  2. Configuring Hyperledger Fabric

    1. To start with, go to the first-network directory, which can be found in the Fabric installation:

    cd fabric-samples/first-network 

    2. We will build a Fabric network with four peers, two organizations, one order node, and one channel. Execute the following command to generate the genesis block and all of the necessary certificates, keys, and channel configurations:

    $ sudo bash ./byfn.sh generate

    The script should return pretty quickly.
    Note: The previous command must be executed from the first-network sub-directory of the fabric-samples repository clone. Otherwise, the various provided scripts will be unable to run successfully.

    3. Now, let’s bring up the network:

    $ sudo ./byfn.sh up

    You will see the following screenshot:
    Hyperledger Explorer and Fabric integration 1

     

    This will continue to launch all of the containers. Upon successful completion, you will see the following screenshot:

    4. You have now successfully set up a Fabric network. To close down the network, run the following command:

    $ sudo bash ./byfn.sh down

    You will see the following screenshot upon execution of the previous command:
    Hyperledger Explorer and Fabric integration 3

    Do not execute the byfn.sh down command unless you are done using the blockchain network. This command will kill all of your containers, remove the crypto material and four artifacts, and delete the chaincode images from your Docker registry.

  3. Configuring Hyperledger Explorer

    The following steps will help you to configure Hyperledger Explorer:

    1. From another Terminal window, go to the platform/fabric subdirectory where you installed Explorer:

    cd blockchain-explorer/app/platform/fabric

    2. Open the config.json file using an editor of your choice, such as the following:

    vi config.json

    3. Update network-configs as follows:

    For keys”adminPrivateKey”, “signedCert” , “tlsCACerts” and “configtxgenToolPath” :

     

    Change fabric-path to your Fabric network path. This is the working directory in which you installed Fabric. My Fabric working directory, for example, is /cookbook/, and it is under the HOME directory. I will replace fabric-path with $HOME/cookbook. This will make the adminPrivateKey key path look as follows:

    “adminPrivateKey”: {

    “path”: “$HOME/cookbook/fabric-samples/first-network/crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore”

    },

    For each client, modify network-id.clients.client-id.channel to your default channel, which is mychannel in our example.

    Note: To avoid frustration, when you update fabric-path, do not use ~ to represent the user’s home directory in the path, even though they refer to the same thing. Otherwise, you might run into a confusing error such as
    this: {Error: ENOENT: no such file or directory, scandir’~/cookbook/fabric-samples/first-network/…/users/ Admin@org1.example.com/msp/keystore’}, even when the directory does exist!

  4. Put Things Together

    In order to integrate Hyperledger Explorer with Fabric, we will need to define a blockchain network from which explorer will gather data. This can be done by modifying the config.json file to update the network-configs property for the Fabric network.

    In next recipes, we will build a Hyperledger Explorer application and show you how to run a Hyperledger Explorer application.

    This tutorial is written in collaboration with Brian Wu who is a senior Hyperledger instructor at Coding Bootcamps school in Washington DC.

Join The Discussion