Skip to content

Conversation

@nkramer44
Copy link

@nkramer44 nkramer44 commented Jun 11, 2025

The ABI files that Forge generates after running forge build contain a "bytecode" field similar to the behavior of Truffle/Hardhat. However, Truffle/Hardhat set "bytecode" to a JSON string value, whereas Forge sets "bytecode" to an object that looks like this:

"bytecode": {
    "object": "...",
    "sourceMap": "...",
    "linkReferences": {}
}

When generating sources from ABI files using web3j-maven-plugin, the plugin properly generates Contract Java wrappers, however the BINARY field of the contract is always an empty string "". This is a sneaky error because it does not fail compilation, but makes it impossible to deploy the contract via the .deploy method. Even worse, calls to .deploy do not throw an exception or fail in any way, but rather end up deploying an empty contract on chain.

This PR updates JavaClassGeneratorMojo.parseAbiFile to handle Forge generated ABI files when parsing to correctly set the BINARY field of generated classes to "bytecode"."object" if "bytecode" is a JSON object (ie when generated by Forge), or "bytecode" when "bytecode" is a JSON String.

I added a sample ERC20.json ABI file generated via Forge to the test resources, as well as the test abi-sources project. Please let me know if there are additional tests I should write.

Signed-off-by: nkramer44 <noah.ph.kramer@gmail.com>
Signed-off-by: nkramer44 <noah.ph.kramer@gmail.com>
@nkramer44 nkramer44 force-pushed the nk/forge-abi-support branch from 8b76f8e to 5c2de8d Compare June 11, 2025 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants