Hyperledger Fabric project builds a blockchain browser
1. Download configuration file
Blockchain browser website: https://github.com/hyperledger/blockchain-explorer
# Deploy according to the official website # Create a folder in the project directory # org1 deploy block explorer mkdir explorer cd explorer # Download the configuration file wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/examples/net1/config.json wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/examples/net1/connection-profile/test-network.json -P connection-profile wget https://raw.githubusercontent.com/hyperledger/blockchain-explorer/main/docker-compose.yaml # If the virtual machine is not connected to the Internet and cannot be downloaded, you can click on the three configuration files on the official website, create the corresponding name, copy and save it, # config.json and docker-compose.yaml are directly placed in the explorer folder, # But pay attention to test-network.json, you need to create a new connection-profile folder first, and then put test-network.json into the connection-profile folder
2. Copy certificate directory
mkdir organizations cp -r ../crypto-config/* organizations cd explorer
At this point, the directory structure is shown in the figure below
3. Take two organizations, each with a peer node as an example, to modify the configuration file
3.1 Modify test-network.json – network configuration file, including identity specification
# First modify the test-network.json file to org1-network.json mv test-network.json org1-network.json # Enter and modify the corresponding parameters in org1-network.json vim org1-network.json # Modify the certificate connection file # Replace the user's certificate with the admin certificate and secret (private key) in the connection configuration file (test-network.json) before fixing "adminPrivateKey": {<!-- --> "path": "/tmp/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/priv_sk" } After modification, change [email protected] to [email protected] "adminPrivateKey": {<!-- --> "path": "/tmp/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/priv_sk" } # Save and exit after modification # Make a copy and name it org2-network.json cp org1-network.json org2-network.json # Modify the corresponding parameters in org2-network.json vim org2-network.json #Modify all Org1 to Org2, as shown below Org1MSP -----> Org2MSP, org1 -----> org2 # Save and exit after modification # or use sed sed -i "s/org1/org2/g" org2-network.json sed -i "s/Org1/Org2/g" org2-network.json
3.2. Modify config.json – multi-network configuration file
# Only one organization network is configured in the config.json file, so a second organization network needs to be added vim config.json # Modify to the following configuration {<!-- --> "network-configs": {<!-- --> "org1-network": {<!-- --> // need to correspond to the name in org1-network.json "name": "org1-network", "profile": "./connection-profile/org1-network.json" // corresponding configuration file }, "org2-network": {<!-- --> // need to correspond to the name in org2-network.json "name": "org2-network", "profile": "./connection-profile/org2-network.json" // corresponding configuration file } }, "license": "Apache-2.0" } # Exit after modification
3.3 Modify docker-compose – deployment configuration file
First find the name of the network used by the fabric, run the blockchain project, and then enter docker network ls to find the blockchain network
docker network ls
then enter
vim docker-compose.yaml
The modified docker-compose.yaml is as follows:
version: '2.1' volumes: pgdata: walletstore: networks: mynetwork.com: external: name: multinodes_default # Modify to your own fabric network services: explorerdb.mynetwork.com: image: hyperledger/explorer-db:latest container_name: explorerdb.mynetwork.com hostname: explorerdb.mynetwork.com ports: # expose ports - 5432:5432 restart: always # Add restart parameter environment: - DATABASE_DATABASE=fabricexplorer # db library - DATABASE_USERNAME=exploreradmin # db account - DATABASE_PASSWORD=exploreradminpw # db password health check: test: "pg_isready -h localhost -p 5432 -q -U postgres" interval: 30s timeout: 10s retries: 5 volumes: - pgdata:/var/lib/postgresql/data - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime # Keep consistent with local time - /etc/hosts:/etc/hosts # Map the hosts file, otherwise it will not be able to connect to other nodes, or add extra_hosts parameters networks: -mynetwork.com explorer.mynetwork.com: image: hyperledger/explorer:latest container_name: explorer.mynetwork.com hostname: explorer.mynetwork.com environment: - DATABASE_HOST=explorerdb.mynetwork.com - DATABASE_DATABASE=fabricexplorer # Keep consistent with the above db library, account number and password - DATABASE_USERNAME=exploreradmin - DATABASE_PASSWD=exploreradminpw - LOG_LEVEL_APP=info - LOG_LEVEL_DB=info - LOG_LEVEL_CONSOLE=debug - LOG_CONSOLE_STDOUT=true # Whether the browser enables remote access, true means only deployed machines can access - DISCOVERY_AS_LOCALHOST=false volumes: - ./config.json:/opt/explorer/app/platform/fabric/config.json - ./connection-profile:/opt/explorer/app/platform/fabric/connection-profile - ../crypto-config:/tmp/crypto # Map certificate directory - /usr/share/zoneinfo/Asia/Shanghai:/etc/localtime - /etc/hosts:/etc/hosts - walletstore:/opt/explorer/wallet ports: -8080:8080 restart: always depends_on: explorerdb.mynetwork.com: condition: service_healthy networks: -mynetwork.com
4. Start the blockchain browser
docker-compose -f docker-compose.yaml up -d # If it is the first startup, it will automatically pull the browser image # If the virtual machine does not have a network, you need to pull explorer-db and explorer from the external network in advance, and then import them to the corresponding virtual machine docker pull hyperledger/explorer-db:latest docker pull hyperledger/explorer:latest
docker ps # The result should look like this CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 72d7227b1306 hyperledger/explorer:latest "docker-entrypoint.s…" 39 seconds ago Up 3 seconds 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp explorer.mynetwork.com 5ac9b1f927cb hyperledger/explorer-db:latest "docker-entrypoint.s…" 39 seconds ago Up 36 seconds (healthy) 5432/tcp explorerdb.mynetwork.com 6735ebc7baf2 hyperledger/fabric-orderer:2.4.2 "orderer" 22 hours ago Up 48 minutes 0.0.0.0:7050->7050/tcp, :::7050->7050/tcp orderer.example.com
To close the blockchain browser, you need to enter in the explorer path
docker-compose down -v (here -v cannot be removed, because deleting the persistent data can start the blockchain browser successfully next time)
5. Access blockchain browser
You can directly enter localhost:8080 in the browser in the virtual machine to access the blockchain browser, or you can enter the virtual machine (server) ip: 8080 (need to open the port) in the host machine to access
explorer account: exploreradmin
explorer password: exploreradminpw
After logging in, you can view information such as the blockchain network, blocks, and transactions.
6. Configuration files of multiple peer nodes in the organization
If the project is a network with two peer nodes in the organization, if you want to configure the configuration file of this network, you only need to add peer1 to all the positions where peer0 appears in org1-network.json. In the same way, just add a few more peers, as shown below
{<!-- --> "name": "org1-network", "version": "1.0.0", "client": {<!-- --> "tlsEnable": true, "adminCredential": {<!-- --> "id": "exploreradmin", "password": "exploreradminpw" }, "enableAuthentication": true, "organization": "Org1MSP", "connection": {<!-- --> "timeout": {<!-- --> "peer": {<!-- --> "endorser": "300" }, "orderer": "300" } } }, "channels": {<!-- --> "mychannel": {<!-- --> "peers": {<!-- --> "peer0.org1.example.com": {<!-- -->}, //add peer1 "peer1.org1.example.com": {<!-- -->} }, "connection": {<!-- --> "timeout": {<!-- --> "peer": {<!-- --> "endorser": "6000", "eventHub": "6000", "eventReg": "6000" } } } } }, "organizations": {<!-- --> "Org1MSP": {<!-- --> "mspid": "Org1MSP", "adminPrivateKey": {<!-- --> "path": "/tmp/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/priv_sk" }, //Add peer1 "peers": ["peer0.org1.example.com","peer1.org1.example.com"], "signedCert": {<!-- --> "path": "/tmp/crypto/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]" } } }, "peers": {<!-- --> "peer0.org1.example.com": {<!-- --> "tlsCACerts": {<!-- --> "path": "/tmp/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt" }, "url": "grpcs://peer0.org1.example.com:7051" }, //add peer1 "peer1.org1.example.com": {<!-- --> "tlsCACerts": {<!-- --> "path": "/tmp/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt" }, "url": "grpcs://peer1.org1.example.com:9051" } } }