HomeDeveloper MaterialsCommunicate via JSON/RPCWeb3j

Web3j

An example application on Kaleido using the web3 Java library. This demonstrates how to connect to a Kaleido node using basic auth and retrieve the latest block number on the chain.

Requirements:

  1. Java 1.8+
  2. Maven

Steps

  1. Clone the Kaleido Examples project.
  2. In the java/web3j/http/src/main/java/kaleido subdirectory open App.java:
    • Replace the RPC_ENDPOINT placeholder with the RPC endpoint for your node.
    • Replace the USER placeholder with the basic auth credentials username.
    • Replace the PASS placeholder with the basic auth credentials password.
  3. Navigate to the java/webj/http subdirectory and run mvn package to install the dependencies and build the Java archive file. This will output a JAR file – kaleido-webj-example-0.0.1-SNAPSHOT-jar-with-dependencies.jar – into a newly created /target directory.
  4. Remain in java/webj/http and run java -jar target/kaleido-webj-example-0.0.1-SNAPSHOT-jar-with-dependencies.jarto kick off the program.