Technical Documentation: LFDT-web3j/web3j
โน๏ธ Provenance: Multi-Tier Ingestion ยท CodeWiki Reference
Overview (`README.md`)
Web3j: Web3 Java Ethereum Dapp API
Web3j is a lightweight, highly modular, reactive, type safe Java and
Android library for working with Smart Contracts and integrating with
clients (nodes) on the Ethereum network:
This allows you to work with the Ethereum
blockchain, without the additional overhead of having to write your own
integration code for the platform.
The Java and the Blockchain talk provides
an overview of blockchain, Ethereum and Web3j.
NEW! Get involved!
Since Web3J moved under Hyperledger we started to do Web3J Contributors calls every 2 weeks!
Subscribe to our community page and to see check our call schedule.
Your contribution matters!
- Community Link - Check our last updates!
- Calendar Invite - Add the contributor call to your calendar!
Features
- Complete implementation of Ethereum's
JSON-RPC client
API over HTTP and IPC - Ethereum wallet support
- Auto-generation of Java smart contract wrappers to create, deploy,
transact with and call smart contracts from native Java code
(Solidity
and
Truffle
definition formats supported) - Reactive-functional API for working with filters
- Ethereum Name Service (ENS) support
- Support for Parity's
Personal,
and Geth's
Personal
client APIs - Support for Alchemy and Infura, so you don't have to run
an Ethereum client yourself - Comprehensive integration tests demonstrating a number of the above
scenarios - Command line tools
- Android compatible
- Support for JP Morgan's Quorum via
web3j-quorum - Support for EEA Privacy features as described in EEA
documentation and
implemented in Hyperledger
Besu.
It has five runtime dependencies:
- RxJava for its
reactive-functional API - OKHttp
for HTTP connections - Jackson Core for fast
JSON serialisation/deserialization - Bouncy Castle for
crypto - Jnr-unixsocket for *nix
IPC (not available on Android) - Java-WebSocket
It also uses JavaPoet for
generating smart contract wrappers.
QuickStart
The simplest way to start your journey with Web3j is to create a project.
We provide this functionality using the Web3j CLI. This latter can be installed as follows:
For Unix:
installer=$(mktemp) &&
curl --disable --proto '=https' --proto-redir '=https' --fail --show-error --silent --location https://get.web3j.io -o "$installer" &&
bash "$installer" && rm -f "$installer" && source ~/.web3j/source.shFor Windows, in Powershell:
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/hyperledger/web3j-installer/main/installer.ps1'))Create a new project by running:
$ web3j newOr use our Maven or
Gradle plugins to
generate java files from Solidity contracts.
Please head to the [Web3j Documentation](https://docs.web3j.io) for further instructions on using Web3j.
Maven
Java:
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>6.1.0</version>
</dependency>Note: The Web3j Java binaries are compiled using Java 21. Java 21 or a more recent version is required to use Web3j
as a dependency.
Android:
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>4.12.3-android</version>
</dependency>Gradle
Java:
implementation ('org.web3j:core:6.1.0')Android:
implementation ('org.web3j:core:4.12.3-android')Build instructions
Web3j includes integration tests for running against a live Ethereum
client. If you do not have a client running, you can exclude their
execution as per the below instructions.
To run a full build (excluding integration tests):
$ ./gradlew checkTo run the integration tests, you will need to set up these variables in order to pull the Docker
images from the Docker Hub registry:
registry.usernameregistry.password
Then run the following command:
$ ./gradlew -Pintegration-tests=true :integration-tests:testIf you do not want the integration test to run:
$ ./gradlew -Pintegration-tests=false :testCheck the Docker client API
for more information on configuration options.
Projects using Web3j
Commercial support and training
Commercial support and training is available from
web3labs.com.
License
Apache 2.0
Overview (`.github/actions/emudhra-trust/README.md`)
CI containment for the eMudhra certificate incident
Following Oracle guidance, this action removes the emSign ECC Root CA - G3 and AAA Certificate Services roots from an isolated copy of the selected JDK truststore. It identifies roots by SHA-256, preserves other anchors, and never changes the installed JDK. Removing these roots may reject legitimate services that still use them.
The action validates fixture checksums, then checks that the effective JSSE trust manager rejects all twelve compromised TLS chains. Missing, malformed or expired fixtures fail the gate. Four hostname-verified TLS handshakes check legitimate dependency/publication hosts. No credentials or HTTP requests are sent. JAVA_TOOL_OPTIONS selects the isolated store for subsequent JVMs; a Gradle init script verifies that each Gradle daemon uses it and excludes both roots.
The public certificate fixtures come from this pinned incident-research commit. They cover DV/OV/EV, G3B/G3C and both issuer paths. No private keys or third-party code are included. SHA256SUMS records their exact bytes. Refresh the fixtures before their validity expires, preserving all twelve paths and provenance.
Build, integration, snapshot, release, Javadocs and CodeQL jobs use the action before Gradle. Changes to this action trigger the non-publishing release rehearsal. PR and manual rehearsal events cannot enter the push-only publishing steps.
This protects default Java TLS trust within these jobs. It does not update Node actions, Git/curl, Python, OS/container trust, consumer JDKs, custom trust managers or JVMs launched with overriding trust options. Those need independent verification. It does not change the Web3j library's API or consumer trust policy.
Overview (`.agents/skills/web3j/assets/erc20-example/README.md`)
ERC20 Example Starters
Use these starter assets when a user wants one example that shows how Web3j modules and companion tools fit together around an ERC20-like contract.
Templates
basic-erc20-app/- minimal JVM-side app and test suite
- covers Solidity source, wrapper generation, deploy/load/call flow, typed events, and
@EVMTest - best answer for
show me a basic erc20 example,how do the web3j pieces fit together, orcreate a basic erc20 app
Agent workflow
When the user asks for a quick scaffold:
- copy
basic-erc20-app/into the target directory - keep the package names and wrapper package unless the user asks to rename them
- patch token metadata, endpoint defaults, or transfer env vars only if the user provided concrete values
- mention
web3j newif they asked for a CLI-generated template - mention
web3j_openapionly if they want an HTTP layer on top of the same contract flow
Overview (`.agents/skills/web3j/assets/event-subscriptions/README.md`)
Event Subscription Starters
Use these starter projects when a user asks for a runnable Web3j event-listening example.
Templates
websocket-newheads/- subscribes to new block headers over WebSocket
- best default runnable example
contract-logs/- subscribes to contract logs with
EthFilter - best when the user already has a contract address and event topic
- subscribes to contract logs with
Agent workflow
When the user asks for a quick scaffold:
- copy the closest starter into the target directory
- rename the package or project only if the user cares
- patch the env-var defaults if the user gave a concrete endpoint or contract
- explain the exact env vars required to run it
Runtime expectations
These templates are minimal Gradle Java apps.
Typical run commands:
gradle runor, if the target project has a wrapper:
./gradlew runEnvironment variables
`websocket-newheads`
WEB3J_WS_URL
`contract-logs`
WEB3J_HTTP_URLWEB3J_CONTRACT_ADDRESSWEB3J_EVENT_TOPIC0optional
Overview (`.agents/skills/web3j/assets/erc20-example/basic-erc20-app/README.md`)
Basic ERC20 App
This starter is the shortest repo-grounded example that ties together:
- Solidity source in
src/main/solidity - wrapper generation via the Web3j Gradle plugin
- wrapper-based deploy, call, and transfer flows
- typed
Transferevent subscriptions - Web3j Unit
@EVMTestcoverage
It is intentionally a JVM-side starter, not a browser UI. If the user wants an HTTP layer, keep this contract/test flow and add web3j_openapi on top.
Files
src/main/solidity/ExampleToken.sol- small ERC20-like contract with
TransferandApprovalevents
- small ERC20-like contract with
src/main/java/example/Erc20ExampleApp.java- deploys the wrapper, reads token state, performs a transfer, and listens for
Transferevents
- deploys the wrapper, reads token state, performs a transfer, and listens for
src/test/java/example/Erc20EvmTest.java- runs the same pattern under
@EVMTest
- runs the same pattern under
build.gradle- applies the Web3j Gradle plugin and fixes generated wrappers to
example.contracts
- applies the Web3j Gradle plugin and fixes generated wrappers to
Commands
Run the test path:
./gradlew testRun the deploy/interact/event path:
WEB3J_PRIVATE_KEY=0xyourprivatekey ./gradlew runEnvironment variables
WEB3J_HTTP_URL- defaults to
http://localhost:8545
- defaults to
WEB3J_PRIVATE_KEY- required for
run
- required for
WEB3J_TOKEN_NAME- defaults to
Skill Token
- defaults to
WEB3J_TOKEN_SYMBOL- defaults to
SKILL
- defaults to
WEB3J_INITIAL_SUPPLY- defaults to
1000000
- defaults to
WEB3J_TRANSFER_TO- defaults to the deployer address so the transfer path can run without a second account
WEB3J_TRANSFER_AMOUNT- defaults to
1
- defaults to
How companion tools fit
CLI scaffolding:
- the published CLI docs already expose
web3j new, anderc20is one of the documented templates
Web3j Sokt:
- the published
v5.0.3docs position Sokt as the direct compiler-resolution and nativesolchelper - the docs-backed shape is
SolidityFile -> getCompilerInstance() -> execute(...) - this starter keeps the shortest runnable path on the Gradle-plugin side for wrapper generation, and leaves direct Sokt wiring as a follow-on step when the user asks for compiler-management code specifically
Web3j Unit and Web3j EVM:
Erc20EvmTestshows the concrete@EVMTestflow documented for Web3j Unit- when a user asks about
web3j-unitorweb3j-evm, point them to the test first because it is the most directly runnable path in this starter
--- METRICS ---
- Files Extracted: 5
- Estimated Token Budget: ~3997 tokens
- Canonical Reference: https://codewiki.google/github.com/LFDT-web3j/web3j