Applied Blockchain Center (ABC)
  • System requirements for ABC
  • Hedera
    • ๐Ÿ…ฐ๏ธAbout Hedera
    • ๐Ÿ–ฅ๏ธEnvironment Setup
    • Tutorials
      • Accounts
        • Get My Account Info
        • Get Other Account Info
        • Transfer HBAR
      • Consensus Service
        • Create Topic
        • Subscribe to a topic
        • Submit a message
      • File Service
        • Create a File
        • Retrieve File
      • Scheduled_TX
        • Create Scheduled Transaction
        • Scheduled Transaction Info
        • Delete Scheduled Transaction
        • Submit Signature
      • SmartContract Service
        • Deploy to Hedera
        • Seal Document
        • Get Seal
        • Check Seal Revocation Status
        • Revoke Document
      • Token Service
        • Fungible Token
        • Non-fungible Token
  • Hyperledger Fabric
    • ๐Ÿ“‘About Hyperledger Fabric
    • ๐Ÿ’ปPrerequisite Installation
    • Fabric Installation
      • ๐ŸงชInstallation & Test
      • โœˆ๏ธLaunch Network
      • โ›“๏ธChannel Creation
      • ๐ŸššChaincode Deployment
      • โ–ถ๏ธChaincode Execution
  • Hyperledger Besu
    • Besu Network Set
Powered by GitBook
On this page
  • 1. Overview
  • 2. Prerequisites
  • 4. Step-by-Step Setup
  • 5. Monitoring (Optional): Prometheus and Grafana
  • 6. Troubleshooting
  • 7. Conclusion

Was this helpful?

  1. Hyperledger Besu

Besu Network Set

1. Overview

Hyperledger Besu is an open-source Ethereum client that supports both public and private networks. It provides different consensus algorithms, including QBFT for permissioned networks. In this guide, we'll use QBFT to set up a private blockchain network with 4 validator nodes and 1 RPC node.

What You'll Set Up:

  • Validator Nodes: Validate transactions and blocks in the network.

  • RPC Node: Allows external applications to interact with the blockchain via JSON-RPC or WebSocket.

  • Prometheus & Grafana (Optional): Monitoring tools for visualizing metrics from the Besu nodes.

2. Prerequisites

Before proceeding, ensure the following tools are installed:

For Docker Setup:

  • Docker: Install Docker

  • Docker Compose: Install Docker Compose

3. Architecture

We will set up the following:

  • 4 Validator Nodes: Each node will validate blocks and transactions using the QBFT consensus algorithm.

  • 1 RPC Node: Provides a JSON-RPC and WebSocket interface for interacting with the blockchain.

Ports Used:

  • Validator Nodes: P2P ports (30303, 30304, 30305, 30306) and RPC ports (8545, 8547, 8548, 8549)

  • RPC Node: P2P port (30307), RPC port (8550), WebSocket port (8551)

4. Step-by-Step Setup

Step 1: Install Docker and Docker Compose

If you haven't already, install Docker and Docker Compose.

  • Docker Installation on Linux:

sudo apt-get update  
sudo apt-get install docker.io  
sudo systemctl start docker  
sudo systemctl enable docker 

  • Docker Compose Installation:

sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose 

Verify the installation by running:

docker --version 
docker-compose --version 

Step 2: Create a Directory Structure

  1. Create a directory for your Besu network setup:

mkdir besu-network 
cd besu-network 
  1. Inside this directory, create subdirectories for each validator and the RPC node:

mkdir -p data/validator1 data/validator2 data/validator3 data/validator4 data/rpcnode 
 

Step 3: Generate Node Private Keys

To generate private keys for each validator node, you can use the besu CLI or generate them manually. The private keys will be required for each validator to participate in the consensus.

Run the following command for each validator node:

besu operator generate-blockchain-config --config-file=configFile --to=networkFiles --private-key-file-name=key 

Place each validator's private key in its respective directory (e.g., data/validator1/key).

Step 4: Create the Genesis File

The genesis.json file defines the initial state and configuration of your blockchain. Create a file named genesis.json inside your besu-network directory:

{ 
  "config": { 
    "chainId": 1337, 
    "isQuorum": true, 
    "qbft": { 
      "blockperiodseconds": 5, 
      "epochlength": 30000, 
      "requesttimeoutseconds": 10 
    } 
  }, 
  "nonce": "0x0", 
  "timestamp": "0x58ee40ba", 
  "gasLimit": "0x47b760", 
  "difficulty": "0x1", 
  "alloc": {}, 
  "extraData": "0x", 
  "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", 
  "mixHash": "0x00000000000000000000000000000000000000647572616c65787365646c6578", 
  "coinbase": "0x0000000000000000000000000000000000000000", 
  "gasUsed": "0x0", 
  "number": "0x0" 
} 

The extraData field will include your validator addresses. You can generate this once the private keys are ready.

Step 5: Create the Docker Compose File

Now create a docker-compose.yml file to define your services (4 validators and 1 RPC node).

version: "3.7" 
 
services: 
  validator1: 
    image: hyperledger/besu:latest 
    container_name: validator1 
    volumes: 
      - ./data/validator1:/opt/besu/data 
      - ./genesis.json:/opt/besu/genesis.json 
    command: > 
      --genesis-file=/opt/besu/genesis.json 
      --data-path=/opt/besu/data 
      --node-private-key-file=/opt/besu/data/key 
      --p2p-port=30303 
      --rpc-http-enabled 
      --rpc-http-port=8545 
      --rpc-http-api=ETH,NET,WEB3,CLIQUE,ADMIN 
      --host-whitelist=* 
      --sync-mode=FULL 
      --miner-enabled 
      --min-gas-price=0 
      --miner-coinbase=0x0000000000000000000000000000000000000000 
    ports: 
      - "30303:30303" 
      - "8545:8545" 
 
  validator2: 
    image: hyperledger/besu:latest 
    container_name: validator2 
    volumes: 
      - ./data/validator2:/opt/besu/data 
      - ./genesis.json:/opt/besu/genesis.json 
    command: > 
      --genesis-file=/opt/besu/genesis.json 
      --data-path=/opt/besu/data 
      --node-private-key-file=/opt/besu/data/key 
      --p2p-port=30304 
      --rpc-http-enabled 
      --rpc-http-port=8547 
      --rpc-http-api=ETH,NET,WEB3,CLIQUE,ADMIN 
      --host-whitelist=* 
      --sync-mode=FULL 
      --miner-enabled 
      --min-gas-price=0 
      --miner-coinbase=0x0000000000000000000000000000000000000000 
    ports: 
      - "30304:30304" 
      - "8547:8547" 
 
  validator3: 
    image: hyperledger/besu:latest 
    container_name: validator3 
    volumes: 
      - ./data/validator3:/opt/besu/data 
      - ./genesis.json:/opt/besu/genesis.json 
    command: > 
      --genesis-file=/opt/besu/genesis.json 
      --data-path=/opt/besu/data 
      --node-private-key-file=/opt/besu/data/key 
      --p2p-port=30305 
      --rpc-http-enabled 
      --rpc-http-port=8548 
      --rpc-http-api=ETH,NET,WEB3,CLIQUE,ADMIN 
      --host-whitelist=* 
      --sync-mode=FULL 
      --miner-enabled 
      --min-gas-price=0 
      --miner-coinbase=0x0000000000000000000000000000000000000000 
    ports: 
      - "30305:30305" 
      - "8548:8548" 
 
  validator4: 
    image: hyperledger/besu:latest 
    container_name: validator4 
    volumes: 
      - ./data/validator4:/opt/besu/data 
      - ./genesis.json:/opt/besu/genesis.json 
    command: > 
      --genesis-file=/opt/besu/genesis.json 
      --data-path=/opt/besu/data 
      --node-private-key-file=/opt/besu/data/key 
      --p2p-port=30306 
      --rpc-http-enabled 
      --rpc-http-port=8549 
      --rpc-http-api=ETH,NET,WEB3,CLIQUE,ADMIN 
      --host-whitelist=* 
      --sync-mode=FULL 
      --miner-enabled 
      --min-gas-price=0 
      --miner-coinbase=0x0000000000000000000000000000000000000000 
    ports: 
      - "30306:30306" 
      - "8549:8549" 
 
  rpcnode: 
    image: hyperledger/besu:latest 
    container_name: rpcnode 
    volumes: 
      - ./data/rpcnode:/opt/besu/data 
      - ./genesis.json:/opt/besu/genesis.json 
    command: > 
      --genesis-file=/opt/besu/genesis.json 
      --data-path=/opt/besu/data 
      --p2p-port=30307 
      --rpc-http-enabled 
      --rpc-http-port=8550 
      --rpc-http-api=ETH,NET,WEB3,ADMIN,DEBUG,TXPOOL 
      --rpc-ws-enabled 
      --rpc-ws-port=8551 
      --rpc-ws-api=ETH,NET,WEB3,ADMIN,DEBUG,TXPOOL 
      --host-whitelist=* 
      --sync-mode=FAST 
    ports: 
      - "30307:30307" 
      - "8550:8550" 
      - "8551:8551" 

Step 6: Launch the Network

With your docker-compose.yml, genesis file, and private keys in place, launch the Besu network:

docker-compose up -d 

This will spin up 4 validator nodes and 1 RPC node.

Step 7: Verify and Interact with the Network

  1. List Running Containers:

docker ps
  1. Check Node Logs:

View logs for a specific validator to ensure it's working correctly:

docker logs validator1 
  1. Interact with the Network:

Using curl, you can interact with the blockchain via the RPC node:

  1. Get the current block number:

curl -X POST --data '{"jsonrpc":"2.0","method":"eth_blockNumber","params":[],"id":1}' 
http://localhost:8550
  1. Connect using web3.js or ethers.js to perform more advanced actions such as sending transactions and deploying smart contracts.

5. Monitoring (Optional): Prometheus and Grafana

Prometheus and Grafana can be used to monitor your Besu nodes in real time. First, create a prometheus.yml configuration file:

scrape_configs: 
  - job_name: 'besu' 
    static_configs: 
      - targets: ['validator1:9545', 'validator2:9546', 'rpcnode:9547'] 

Add the services to your Docker Compose file:

prometheus: 
  image: prom/prometheus 
  volumes: 
    - ./prometheus.yml:/etc/prometheus/prometheus.yml 
  ports: 
    - "9090:9090" 
 
grafana: 
  image: grafana/grafana 
  ports: 
    - "3000:3000" 

Start the services:

docker-compose up -d 

6. Troubleshooting

  1. Nodes Not Syncing:

    1. Ensure all nodes use the same genesis.json.

    2. Verify that all nodes can reach each other through their P2P ports.

  2. No Peer Connections:

    1. Check firewall settings to ensure P2P ports are open.

    2. Use docker network ls to verify that all containers are on the same network.

  3. Node Crashes:

    1. View the logs using docker logs <container-name> to diagnose the issue.

    2. Check if private keys are correctly placed.

7. Conclusion

By following this guide, you now have a fully functional Hyperledger Besu private blockchain network with 4 validator nodes and 1 RPC node. You can now expand this network, add new nodes, or deploy smart contracts. Monitoring tools such as Prometheus and Grafana can also be added for better visibility into node performance.

PreviousChaincode Execution

Last updated 1 month ago

Was this helpful?

You can access Grafana on and Prometheus on .

http://localhost:3000
http://localhost:9090