Web3j Documentation

repository·main·Indexed 26 days ago

https://github.com/lfdt-web3j/web3j

A lightweight, modular, and reactive Java/Android library for interacting with the Ethereum blockchain and working with Smart Contracts. Includes a CLI for project management and Java wrapper generation from Solidity ABI files. Requires Java 21 for standard Java applications.

Tokens
1.1K
Snippets
4
Records
8
Agent score
40%

What's inside Web3j

  1. Add Web3j as a Maven dependency

    main

    To use Web3j in a Java project, add the following dependency to your pom.xml.

    Important: Web3j Java binaries are compiled using Java 21. You must use Java 21 or a more recent version to use Web3j as a dependency.

    For standard Java applications, use the core artifact. For Android applications, use the -android suffix version.

    <!-- Standard Java (Requires Java 21+)
    <dependency>
      <groupId>org.web3j</groupId>
      <artifactId>core</artifactId>
      <version>5.0.3</version>
    </dependency>
    
    <!-- Android
    <dependency>
      <groupId>org.web3j</groupId>
      <artifactId>core</artifactId>
      <version>4.12.3-android</version>
    </dependency>
  2. Install the Web3j CLI

    main

    The Web3j CLI can be used to create new projects and manage Ethereum-related tasks. Follow the installation instructions for your operating system:

    Unix: Use curl to download and run the installer, then source the environment script.

    Windows (PowerShell): Use the provided PowerShell command to bypass execution policy and run the installer script.

    # Unix
    curl -L get.web3j.io | sh && source ~/.web3j/source.sh
    
    # Windows (PowerShell)
    Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/hyperledger/web3j-installer/main/installer.ps1'))
  3. Build Web3j and manage integration tests

    main

    Web3j uses Gradle for its build process. You can run builds with or without integration tests.

    Full build (excluding integration tests): Use ./gradlew check.

    Running integration tests: Integration tests require a live Ethereum client and Docker. You must set the following environment variables to pull Docker images: registry.username and registry.password. Run with: ./gradlew -Pintegration-tests=true :integration-tests:test

    Explicitly disabling integration tests: ./gradlew -Pintegration-tests=false :test

  4. ENS PublicResolver profiles and EIP support

    main

    The ENS PublicResolver implements several Ethereum Improvement Proposals (EIPs) through different resolver profiles:

    ProfileEIPDescription
    ABIResolverEIP 205ABI support (ABI())
    AddrResolverEIP 137 / EIP 2304Contract address interface and Multicoin support (addr())
    ContentHashResolverEIP 1577Content hash support (contenthash())
    InterfaceResolverEIP 165Interface Detection (supportsInterface())
    NameResolverEIP 181Reverse resolution (name())
    PubkeyResolverEIP 619SECP256k1 public keys (pubkey())
    TextResolverEIP 634Text records (text())
    DNSResolverExperimentalHosting DNS domains on Ethereum via ENS