Interacting with the Ethereum Network - Kerala-Blockchain-Academy/ethereum-developer-program GitHub Wiki
Previously, we saw that we could connect to various Ethereum networks using the MetaMask light wallet. This can also be done using the Ethereum clients.
Please keep in mind that if you are trying to sync with mainnet or test networks to run a full node,the sync time and speed will depend on your internet connectivity and available storage .
After the merge update, Ethereum client layer consist of two clients: a consensus client and an execution client.
To learn more about the usage of other clients visit: https://clientdiversity.org/
Any combination of execution client and consensus client can be used. Here we will use Hyperledger Besu as execution client and Teku as consensus client.
Since Besu and Teku are based on Java, the system should have java installed. Make sure you update and install java
sudo apt update
sudo apt install openjdk-21-jdk
Ensure that java has been installed successfully by doing a version check.
java --version
- Install Besu and Teku: Choose the installation method that suits you best.
- Check Prerequisites:
- Binary Distributions: If you're using pre-built binaries, make sure you have Java 17 or a newer version installed on your system.
- Other Methods: Review the specific requirements for your chosen installation method (e.g., building from source).
- System Requirements: Before running Besu on public Ethereum networks, ensure your system meets the minimum hardware and software specifications. You can find detailed information about these requirements in the official Besu documentation.
To create a shared JWT secret for Besu and Teku authentication, execute this command in your terminal:
openssl rand -hex 32 | tr -d "\n" > jwtsecret.hex
This command generates a random 32-byte hexadecimal string and saves it to a file named jwtsecret.hex. You'll need to provide this file when starting both Besu and Teku, as it serves as the shared secret for authentication using the Engine API.
Run the following command
besu --sync-mode=SNAP --data-storage-format=BONSAI --rpc-http-enabled=true --rpc-http-host="0.0.0.0" --rpc-ws-enabled=true --rpc-ws-host="0.0.0.0" --host-allowlist="all" --engine-host-allowlist="all" --engine-rpc-enabled --engine-jwt-secret=./jwtsecret.hex
Let us take a look at the options:
JWT Secret:
--engine-jwt-secret /path/to/your/jwtsecret.hex
Replace /path/to/your/jwtsecret.hex
with the actual path to the jwtsecret.hex
file you generated in the previous step.
IP Address:
--host-allowlist your_besu_node_ip
--engine-host-allowlist your_besu_node_ip
Replace your_besu_node_ip
with the IP address of your Besu node.
Here's a breakdown of the command and its key options:
-
--sync-mode snap
: Enables snap sync, a faster synchronization method. -
--data-storage-format bonsai
: Utilizes Bonsai Tries for data storage, offering improved performance. -
--rpc-http-enabled
: Activates the HTTP JSON-RPC service. -
--rpc-http-host 0.0.0.0
: Allows remote connections to the HTTP JSON-RPC service from any IP address. -
--rpc-ws-enabled
: Activates the WebSocket JSON-RPC service. -
--rpc-ws-host 0.0.0.0
: Allows remote connections to the WebSocket JSON-RPC service from any IP address. -
--engine-rpc-enabled
: Enables the Engine API, required for interaction with Teku.
You can customize these options and add others as needed to configure Besu according to your specific requirements. Refer to the Besu command line options documentation for a comprehensive list of available options.
Teku is an Ethereum consensus client written in Java. Teku contains a full beacon node implementation and a validator client for participating in proof of stake consensus.
Open a new terminal window.
To operate Teku solely as a beacon node without taking on validator responsibilities, execute the following command:
teku --ee-endpoint=http://localhost:8551 --ee-jwt-secret-file=./jwtsecret.hex --metrics-enabled=true --rest-api-enabled=true --checkpoint-sync-url=https://beaconstate.info --rest-api-cors-origins=* --rest-api-host-allowlist=* --rest-api-interface=0.0.0.0
When starting Teku as a beacon node, include the following:
JWT Secret:
--ee-jwt-secret-file=/path/to/your/jwtsecret.hex
Replace /path/to/your/jwtsecret.hex
with the actual path to the jwtsecret.hex
file you generated earlier.
The command also includes these options:
-
--ee-endpoint
: Defaults to Besu's Engine API URL. If your Besu node is running on a different address, modify this accordingly. -
--metrics-enabled
: Activates Teku's metrics exporter for monitoring and performance analysis. -
--rest-api-enabled
: Enables Teku's REST API service for programmatic interaction.
You can customize these values and incorporate additional Teku command line options to tailor Teku's behavior to your specific needs. Consult the Teku command line options documentation for a comprehensive list of available options and their functionalities.
The node will take a considerable time to sync and once completed, the imported blocks can be seen in the terminal
Note: To change the sync network, set --network=sepolia
or --network=goerli
for besu. --network=sepolia
or --network=goerli
for teku.