Hyperledger Besu Enterprise Ethereum Quick Tutorial

ยท

Hyperledger Besu is an enterprise-grade Ethereum client within the Hyperledger ecosystem, offering full compatibility with the Ethereum Mainnet. This tutorial demonstrates how to:

1. Launching the Enterprise Ethereum Network

Begin by cloning the Besu quickstart repository:

git clone https://github.com/PegaSysEng/besu-quickstart.git

Navigate to the besu-quickstart directory and execute:

./run.sh

This command builds a Docker image and launches 4 containers simulating an enterprise Ethereum network with 6 Besu nodes. Upon completion, you'll see:

*************************************
Besu Quickstart
*************************************
List endpoints and services
----------------------------------
Name                              Command               State  Ports
---------------------------------------------------------------------------------------------------------
besu-quickstart_bootnode_1        /opt/besu/bootnode_sta ...   Up    30303/tcp, 8545/tcp, 8546/tcp
besu-quickstart_explorer_1        nginx -g daemon off;         Up    0.0.0.0:32768->80/tcp
besu-quickstart_grafana_1         /run.sh                      Up    3000/tcp
besu-quickstart_minernode_1       /opt/besu/node_start.s ...   Up    30303/tcp, 8545/tcp, 8546/tcp
besu-quickstart_node_1            /opt/besu/node_start.s ...   Up    30303/tcp, 8545/tcp, 8546/tcp
besu-quickstart_node_2            /opt/besu/node_start.s ...   Up    30303/tcp, 8545/tcp, 8546/tcp
besu-quickstart_node_3            /opt/besu/node_start.s ...   Up    30303/tcp, 8545/tcp, 8546/tcp
besu-quickstart_node_4            /opt/besu/node_start.s ...   Up    30303/tcp, 8545/tcp, 8546/tcp
besu-quickstart_prometheus_1      /bin/prometheus --config.f ... Up   9090/tcp
besu-quickstart_rpcnode_1         /opt/besu/node_start.s ...   Up    30303/tcp, 8545/tcp, 8546/tcp

Access endpoints include:

****************************************************************
JSON-RPC HTTP service endpoint     : http://localhost:32768/jsonrpc
JSON-RPC WebSocket service endpoint: ws://localhost:32768/jsonws
GraphQL HTTP service endpoint      : http://localhost:32768/graphql
Web block explorer address         : http://localhost:32768
Prometheus address                 : http://localhost:32768/prometheus/graph
Grafana address                    : http://localhost:32768/grafana-dashboard
****************************************************************

Key services:

To redisplay endpoints:

./list.sh

2. Using the Enterprise Ethereum Block Explorer

We recommend the Alethio lightweight explorer. Open the Web Block Explorer endpoint in your browser to inspect:

๐Ÿ‘‰ Explore enterprise blockchain solutions for advanced use cases.

3. Monitoring Node Health

Visualize network metrics using:

Access both tools via their respective endpoints.

4. JSON-RPC API Integration

Besu supports standard Ethereum JSON-RPC methods. Examples:

Check client version:

curl -X POST --data '{
  "jsonrpc":"2.0",
  "method":"web3_clientVersion",
  "params":[],
  "id":1
}' http://localhost:32768/jsonrpc

Get peer count:

curl -X POST --data '{
  "jsonrpc":"2.0",
  "method":"net_peerCount",
  "params":[],
  "id":1
}' http://localhost:32768/jsonrpc

Query latest block:

curl -X POST --data '{
  "jsonrpc":"2.0",
  "method":"eth_blockNumber",
  "params":[],
  "id":1
}' http://localhost:32768/jsonrpc

5. Account Management

Use these genesis accounts for testing:

Account 1 (Coinbase):

Address: 0xfe3b557e8fb62b89f4916b721be55ceb828dbd73
Private Key: 0x8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63
Balance: 200000000000000000000 WEI

Account 2:

Address: 0x627306090abaB3A6e1400e9345bC60c78a8BEf57
Private Key: 0xc87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3
Balance: 2785365088392105618523029504 WEI

Connect MetaMask to your Besu node to begin transactions.

6. Truffle Pet Shop Demo on Besu

Setup:

  1. Install Truffle:

    npm install -g truffle
  2. Create project:

    mkdir pet-shop-tutorial
    cd pet-shop-tutorial
    truffle unbox pet-shop
  3. Install HD Wallet Provider:

    npm install --save @truffle/hdwallet-provider

Configuration:
Update truffle-config.js:

const PrivateKeyProvider = require("@truffle/hdwallet-provider");
const privateKey = "8f2a55949038a9610f50fb23b5883af3b4ecb3c3bb792cbcefbd1542c692be63";

module.exports = {
  networks: {
    quickstartWallet: {
      provider: () => new PrivateKeyProvider(privateKey, "http://localhost:32768/jsonrpc"),
      network_id: "*"
    }
  }
};

Deployment:

truffle migrate --network quickstartWallet

Testing:

truffle test --network quickstartWallet

๐Ÿ‘‰ Learn more about blockchain development with comprehensive guides.

7. Network Management

Temporary stop:

./stop.sh

Restart:

./resume.sh

Complete removal:

./remove.sh

FAQ

What makes Hyperledger Besu different from other Ethereum clients?

Besu offers enterprise features like permissioning, while maintaining full Ethereum Mainnet compatibility.

Can I use MetaMask with Besu?

Yes! Simply connect MetaMask to your Besu node's RPC endpoint.

How do I monitor transaction performance?

Use Grafana dashboards connected to Prometheus metrics for real-time monitoring.

What consensus mechanisms does Besu support?

Besu supports both Proof of Work (Ethash) and Proof of Authority (IBFT, QBFT, Clique).

How do I customize the genesis block?

Modify the config/besu/genesis.json file before initializing the network.

Can I deploy ERC-20 tokens on Besu?

Absolutely. Besu fully supports all standard Ethereum smart contracts.