Open
Description
Title:
Errors in Web3j-Generated Wrapper Classes: "Cannot find symbol: class LinkReference" and Incorrect Package Name
Body:
I'm working on a Spring Boot project that interacts with Ethereum smart contracts. I'm using Web3j to compile Solidity contracts and generate ABI, binary files, and Java wrapper classes. However, the generated wrapper classes contain the following issues:
-
Compilation Error:
/home/abdulmueedshahbaz/springboot/eth/eth/src/main/java/generated/com/zuehlke/blockchain/model/HelloWorld.java:204:51 java: cannot find symbol symbol: class LinkReference location: class org.web3j.tx.Contract
This error suggests that the class
LinkReference
is missing in the generated code.
Due to this issue, I'm unable to run my Spring Boot application.
My Setup:
Dependencies (Maven):
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>crypto</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>utils</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>abi</artifactId>
<version>5.0.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.18.2</version>
</dependency>
</dependencies>
Build Plugins (Maven):
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<version>4.12.3</version>
<configuration>
<packageName>com.zuehlke.blockchain.model</packageName>
<sourceDestination>src/main/java/generated</sourceDestination>
<nativeJavaType>true</nativeJavaType>
<outputFormat>java,bin</outputFormat>
<soliditySourceFiles>
<directory>src/main/resources/solidity/</directory>
<includes>
<include>**/*.sol</include>
</includes>
</soliditySourceFiles>
<outputDirectory>
<java>src/main/java/generated</java>
<bin>src/bin/generated</bin>
<abi>src/abi/generated</abi>
</outputDirectory>
<contract>
<includes>
<include>HelloWorld</include>
</includes>
<excludes>
<exclude>mortal</exclude>
</excludes>
</contract>
<pathPrefixes>
<pathPrefix>dep=../dependencies</pathPrefix>
</pathPrefixes>
</configuration>
</plugin>
</plugins>
</build>
Steps I Followed:
- Added my Solidity files to
src/main/resources/solidity/
. - Ran
mvn generate-sources
to generate the ABI, binary, and wrapper classes. - Attempted to build and run the application.
Issues:
- The
HelloWorld.java
wrapper class references aLinkReference
class, which does not seem to exist inorg.web3j.tx.Contract
.
Question:
- How can I resolve the missing
LinkReference
error in the Web3j-generated wrapper classes - Are there any known compatibility issues between Web3j (v5.0.0) and Solidity contracts?
Any guidance would be greatly appreciated!