How Can I Setup up Blockchain Explorer For Hyperledger Fabric? (Works for v1.2)

hyperledger
hyperledger-fabric

(Varun Raj) #1

In this topic I’ll explain the step to step procedure of how to setup Blockchain Explorer for your Hyperledger Fabric project. We’ll be using https://github.com/xuehuiit/fabric-explorer for this demo as it comes with MySQL Support.

Requirements

  • docker 1.12.6
  • docker-compose 1.11.2
  • golang 1.8
  • nodejs 6.9.5
  • git
  • mysql (5.7 Prefered)

Before getting into the article, I assume that you already have a fabric network running and we’re only configuring the explorer to talk with it.

Step 1

Clone the repository to your local machine or the server where you want to run the explorer.

git clone https://github.com/xuehuiit/fabric-explorer
cd fabric-explorer

Step 2

Now in order to make it work properly, checkout to the branch v1.0

git checkout v1.0

Step 3

Copy paste the crypto config folder from your network to explorer’s root folder (Where you have the main.js file).

Step 4

Update the config.json for configure your database connection (In this we’ll use mysql so it’s pretty straight forward), channel list, loglevel, key store path, etc.

{
   "host": "localhost",
   "port": "8080",
   "keyValueStore": "keystore",
   "eventWaitTime": "30000",
   "GOPATH":"../artifacts",
   "users":[
      {
         "username":"admin",
         "secret":"adminpw"
      }
   ],
   "enableTls": true,
   "channelsList": ["mychannel"],
   "loglevel":"ERROR",
   "mysql": {
      "host": "localhost",
      "port": "3306",
      "database": "bc_explorer",
      "username": "root",
      "passwd": "root"
   }
}

Step 5

Now after configuration, it’s time to update the network configuration. it’ll be placed in the file app/network-config-tls.json for TLS enabled network and app/network-config.json for non TLS system.

Here I’ve attached my network configuration, update it based on yours.

{
	"network-config": {
		"orderer": [{
			"url": "grpcs://127.0.0.1:7050",
			"server-hostname": "orderer0.example.com",
			"tls_cacerts": "crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt"
		}],
		"org1": {
			"name": "peerOrg1",
			"mspid": "Org1MSP",
			"ca": "https://127.0.0.1:7054",
			"peer1": {
				"requests": "grpcs://127.0.0.1:7051",
				"events": "grpcs://127.0.0.1:7053",
				"server-hostname": "peer0.org1.example.com",
				"tls_cacerts": "crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt"
			},
			"peer2": {
				"requests": "grpcs://127.0.0.1:8051",
				"events": "grpcs://127.0.0.1:8053",
				"server-hostname": "peer1.org1.example.com",
				"tls_cacerts": "crypto-config/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt"
			},
			"admin": {
				"key": "crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/keystore",
				"cert": "crypto-config/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp/signcerts"
			}
		},
		"org2": {
			"name": "peerOrg2",
			"mspid": "Org2MSP",
			"ca": "https://127.0.0.1:8054",
			"peer1": {
				"requests": "grpcs://127.0.0.1:9051",
				"events": "grpcs://127.0.0.1:9053",
				"server-hostname": "peer0.org2.example.com",
				"tls_cacerts": "crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt"
			},
			"peer2": {
				"requests": "grpcs://127.0.0.1:10051",
				"events": "grpcs://127.0.0.1:10053",
				"server-hostname": "peer1.org2.example.com",
				"tls_cacerts": "crypto-config/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt"
			},
			"admin": {
				"key": "crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/keystore",
				"cert": "crypto-config/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp/signcerts"
			}
		}
	}
}

Make sure if you’ve the crypto config placed in the root folder as we’re referencing here accordingly.

Step 6

Create the database in mysql with the name you mentioned in the config.json and import the schema with the sql file provided under db/fabricexplorer.sql.

mysql -u root -p bc_explorer < db/fabricexplorer.sql

Step 7

Run the explorer with the following command.

node main.js

and if you want to run as demon.

./start.sh

If everything is good, you’ll be able to see the explorer running in

http://localhost:8080

I’m yet to test this procedure with Fabric 1.3 since there are couple of changes made to core apis (What’s new in Hyperledger Fabric 1.3)