Skip to content

web3j/web3j-eth2

Repository files navigation

Web3j Ethereum 2.0

Web3j - Ethereum 2.0

This project contains Ethereum 2.0 related modules.

At the moment it only contains the Beacon Node API client.

Beacon Node API Client

Web3j client library for the Eth2 Beacon Node API.

Dependencies

Quickstart

You can add the library to your project using either Gradle or Maven.

Maven

<dependency>
  <groupId>org.web3j.eth2</groupId>
  <artifactId>beacon-node-api</artifactId>
  <version>1.0.0</version>
</dependency>

Gradle

implementation 'org.web3j.eth2:beacon-node-api:1.0.0'

Create a service pointing to your Beacon Chain node:

var service = new BeaconNodeService("http://public-mainnet-node.ethereum.org/api");

Build a client instance using the client factory:

var client = BeaconNodeClientFactory.build(service);

That's it! You can start using the client to call the node endpoints, for instance:

client.getBeacon().getBlocks().findById(NamedBlockId.HEAD);

Test and build

Run this command on a console:

./gradlew build

Integration tests

This library is tested against different Beacon Node API nodes to ensure that it works on all of them. At the moment the tests run against Lighthouse and Teku.

Other Beacon Node implementations providing Docker images such as Nimbus and Prysm will be included in the future.

To run the integration tests, you'll need Docker running. Unless you pull the images manually, you will also need to define these variables in order to pull the Docker images from the Docker Hub registry:

  • registry.username
  • registry.password

Check the Docker client API for more information on configuration options.

Run this command on a console:

./gradlew integrationTest