---
# System prepended metadata

title: Ethereum Client Scripts

---

# Ethereum Client Scripts

The `ethereum_client_scripts` directory from buidlguidlclient contains Node.js scripts that automate the setup and management of Ethereum node clients. Each script is responsible for launching, configuring, or installing a specific Ethereum client or related utility.

## What Scripts Are Included?

* `geth.js` – Launches the Geth execution client.
* `reth.js` – Launches the Reth execution client.
* `lighthouse.js` – Launches the Lighthouse consensus client.
* `prysm.js` – Launches the Prysm consensus client.
* `install.js` – Downloads and installs the required client binaries.
* `configureBGPeers.js` – Configures the BuidlGuidl peer network for enhanced connectivity.

---

## Understanding `configureBGPeers.js`

The `configureBGPeers.js` script automates the process of discovering and connecting to BuidlGuidl network peers for both Ethereum execution and consensus clients. It helps your node find and connect to other trusted nodes in the BuidlGuidl network, improving connectivity and decentralization.

### Key Functions

1. **`fetchBGExecutionPeers()`**

   * **Purpose:** Fetches a list of execution client peers (enodes) from the BuidlGuidl network, excluding the current node’s own enode.
   * **How it works:**

     * Gets the public IP address of the current machine.
     * Fetches a list of enodes from the BuidlGuidl pool endpoint.
     * Filters out any enode that matches the current node’s IP and port.
     * Returns a list of enode URLs to connect to.

2. **`configureBGExecutionPeers(bgPeers)`**

   * **Purpose:** Adds the fetched execution peers to the local Ethereum execution client (e.g., Geth) as both regular and trusted peers.
   * **How it works:**

     * For each enode, sends two JSON-RPC requests to the local client: `admin_addPeer` and `admin_addTrustedPeer`.
     * Uses curl commands executed via Node.js.
     * Logs the results for debugging.

3. **`fetchBGConsensusPeers()`**

   * **Purpose:** Fetches a list of consensus client peer IDs from the BuidlGuidl network.
   * **How it works:**

     * Requests peer IDs from the BuidlGuidl pool endpoint.
     * Filters out invalid or null entries.
     * Returns a list of valid peer IDs.

4. **`configureBGConsensusPeers()`**

   * **Purpose:** Retrieves and filters consensus peer addresses for the current consensus client, excluding the current machine.
   * **How it works:**

     * Fetches consensus peer addresses from the BuidlGuidl pool endpoint.
     * Identifies the current machine using hostname, MAC address, OS, and architecture.
     * Filters out peers that match the current machine.
     * Returns a comma-separated string of peer addresses to connect to.

### How to Use

You can use these functions in your node setup scripts to automatically discover and connect to BuidlGuidl peers.

---

## Understanding `geth.js`

The `geth.js` script is responsible for launching and managing a Geth (Go Ethereum) execution client node with custom configuration, logging, and process management. It is designed to be run from the command line and is highly configurable via arguments. ``This is the same way the other client script is setup``

### Key Features

* **Cross-platform support:** Detects the OS and uses the correct Geth binary.
* **Custom install directory:** Allows specifying where the client and data are stored.
* **Configurable ports and sync type:** Supports custom peer port and sync mode (full, archive).
* **JWT authentication:** Sets up JWT for secure communication with consensus clients.
* **Logging:** Streams Geth logs to a timestamped file and (optionally) to a parent process.
* **Graceful shutdown:** Handles process exit and errors cleanly.

### How it Works

#### Parse Command-Line Arguments

* Uses `minimist` to parse options like `--executionpeerport`, `--executiontype`, and `--directory`.

#### Determine Binary and Paths

* Sets the install directory (default: user’s home).
* Builds the path to the Geth binary and JWT secret.

#### Build Geth Command

* Constructs the command with options:

  * Network: `--mainnet`
  * Sync mode: `--syncmode` (snap, full, or archive)
  * Ports: `--port`, `--discovery.port`, `--http.port`
  * APIs: `--http.api` (enables `eth`, `net`, `engine`, `admin`)
  * Data directory and JWT secret
  * Metrics enabled

#### Spawn the Geth Process

* Uses `node-pty` to launch Geth in a pseudo-terminal.
* Sets up environment variables and working directory.

#### Log Management

* Writes all output (stdout/stderr) to a timestamped log file.
* Optionally sends logs to a parent process (for UI integration).

#### Process Management

* Handles process exit and errors, ensuring logs are closed.
* Listens for SIGINT to gracefully kill the Geth process.

---

## Understanding `install.js`

The `install.js` script automates the download, installation, and version management of Ethereum client binaries (Geth, Reth, Lighthouse, Prysm) for the buidlguidl-client system. It ensures you always have the correct version for your platform and architecture.

### Key Features

* **Cross-platform support:** Handles macOS (darwin), Linux, and multiple CPU architectures (x64, arm64).
* **Automatic download and extraction:** Downloads the correct binary or script for your OS/arch, extracts it, and sets permissions.
* **Version management:** Checks installed client versions and compares them to the latest supported versions.
* **Clean installation:** Creates necessary directories and cleans up after installation.
* **Removes old clients:** Can remove existing client installations if needed.

### How it Works

#### Defines Latest Versions

* Maintains constants for the latest supported versions of Geth, Reth, and Lighthouse.

#### Platform and Architecture Detection

* Uses Node.js `os` module to detect your OS and CPU architecture.
* Selects the correct binary or script name for your platform.

#### Download and Install

* If the client is not already installed:

  * Creates the client’s directory structure.
  * Downloads the appropriate binary or script using `curl`.
  * Extracts `.tar.gz` files for Geth, Reth, and Lighthouse.
  * For Prysm, downloads the shell script and makes it executable.
  * Moves binaries to the correct location and cleans up temporary files.

#### Version Checking

* Provides a function to get the installed client’s version by running its `--version` command.
* Compares the installed version to the latest version and reports if an update is needed.

#### Removal

* Can remove a client’s directory and all its contents.
