/besu-guild-sample

Introduction to Hyperledger Besu Guild

Primary LanguageTypeScript

Introduction to Hyperledger Besu Guild

This repository serves as a comprehensive sample project for Hyperledger Besu, an Ethereum client designed to meet enterprise needs, offering both permissioned and public network functionalities.

Repository Structure

The folder structure of this project is organized as follows:

Sample_Network/
├── Node-1
│   ├── data
├── Node-2
│   ├── data
└── Node-3
    ├── data
Token_Client/
├── index.ts
Token_Contract/
├── contracts
│   ├── Token.sol
├── scripts
│   ├── deploy_token.ts
README.md

Folder Description

  • Sample_Network: Contains a sample Hyperledger Besu network setup using the Clique consensus protocol. The nodes in this folder are preconfigured to simulate a simple private network.
  • Token_Contract: Houses the code for an ERC-20 Smart Contract, which is a standard for creating fungible tokens on the Ethereum blockchain. This folder also includes deployment scripts leveraging the Hardhat development environment.
  • Token_Client: Contains a Node.js client that interacts with the deployed token contract using the web3.js library. This client provides several commands to interact with the token contract, such as checking the token name, minting new tokens, and checking account balances.

Setting Up the Besu Network

Pre-requisites

Before you begin, ensure you have the following installed:

The Sample_Network folder is preconfigured for local execution. To start the network, follow these steps:

  1. Navigate to the scripts folder:
cd Sample_Network/scripts
  1. Set execution permissions for the scripts:
chmod +x start_node1.sh && chmod +x start_node2.sh && chmod +x start_node3.sh
  1. Start the first node:
./start_node1.sh
  1. Open a new terminal and start the second node:
./start_node2.sh
  1. Open another terminal and start the third node:
./start_node3.sh

Monitoring the Network

To monitor the network using Prometheus, follow these steps:

  1. Navigate to the scripts folder:
cd Sample_Network/scripts
  1. Start Prometheus:
./start_prometheus.sh
  1. Open a browser and navigate to http://localhost:9090 to access the Prometheus dashboard. More infomation on setting up Prometheus can be found in the Hyperledger Besu documentation.

To know more about the network setup, refer to the Hyperledger Besu documentation.

Deploying the Token Contract

Pre-requisites

Before you begin, ensure you have the following installed:

The Token_Contract folder is preconfigured for deploying the token contract. Please note that the Besu nodes must be running before deploying the contract.

Optional: Customizing the Token

If you wish to customize the token’s name and symbol, follow these steps:

  1. Navigate to the contracts folder:
cd Token_Contract/contracts/
  1. Open the Token.sol file and edit the contract constructor as needed. For example, to change the token name to “AnotherName” and the symbol to “ANTK”, update the following lines:

Before:

    constructor(
        address initialOwner
    )
        ERC20("GuildToken", "GTK")
        Ownable(initialOwner)
        ERC20Permit("GuildToken")
    {}

After:

    constructor(
        address initialOwner
    )
        ERC20("AnotherName", "ANTK")
        Ownable(initialOwner)
        ERC20Permit("AnotherName")
    {}

Deploying the Contract

  1. Navigate to the contract folder:
cd Token_Contract/
  1. Install the necessary dependencies:
npm install
  1. Deploy the contract:
npm run deploy

This will use the Hardhat library to deploy the contract to your running Besu network.

Interacting with the Deployed Contract

Pre-requisites

Ensure that Node.js is installed, and the Besu network is running with the token contract already deployed.

To interact with the contract, follow these steps:

  1. Navigate to the client folder:
cd Token_Client/
  1. Install the necessary dependencies:
npm install
  1. Verify the connection to the Besu network:

Run the following command to check if the client is communicating correctly with Besu:

npm run assetCode

If successful, this command should return the asset code defined in the contract. For example, if unchanged, it should return GTK.

Available commands:

  • Get the token name:
npm run name
  • Mint a specified amount of tokens to the owner account:
npm run mint <amount>
  • Check the owner account balance:
npm run balance

These commands allow you to interact with the deployed token contract, enabling token minting, querying balances, and more.

This README provides a detailed guide on setting up a Hyperledger Besu network, deploying an ERC-20 token contract, and interacting with it using Node.js. Follow the steps carefully to ensure a successful setup and deployment process.