Closed rampatra closed 3 years ago
I am compiling my solidity files via web3j-maven-plugin
by running mvn web3j:generate-sources
.
And, if I remove the pragma version and the constructor, it compiles and runs fine. So, I am now sure that this is related to an incompatible solidity version. I need at least 0.7.4
but my project is somehow using 0.4.19
.
This is what I get in my system's console:
$ solc --version
solc, the solidity compiler commandline interface
Version: 0.8.3+commit.8d00100c.Darwin.appleclang
Can you try :
solidity {
version = "<solidity_version>"
}
in your build.gradle
?
Oh, you're using maven. Can you set that same property ?
The maven plugin is a little lagging behind... can you switch to gradle ? I doubt you will have this problem using that
@SweeXordious thanks for helping me out here. Do you mean like this?
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<version>4.6.5</version>
<configuration>
<soliditySourceFiles/>
<solidity>
<version>
0.7.4
</version>
</solidity>
</configuration>
</plugin>
We are stuck with maven for now. We can't move to gradle as our pipelines, etc. is all maven, unfotunately.
maybe try that way and see if it will be compiled as needed
Tried, didn't work. Is this PR related to this issue: https://github.com/web3j/web3j-maven-plugin/pull/57 ?
can you share the logs you are seeing ?
Sure.
Error:(3, 1) src/main/resources/MyContract.sol:3:1: Error: Source file requires different compiler version (current compiler is 0.4.19-develop.2018.1.12+commit.c4cbbb05.Darwin.appleclang - note that nightly builds are considered to be strictly less than the released version
pragma solidity 0.7.4;
^--------------------^
When I remove the pragma line and the constructor and other 0.7.4 features, it works. Basically, whatever 0.7.4 solidity features I use, it complains as it using an older version of solidity compiler here, i.e., 0.4.19
do you have multiple contracts you're compiling with different versions ?
No, all contracts have pragma solidity 0.7.4;
That is weird. Can you create a dummy project with the config you are using and share it with me ?
Sure. But I am not using any custom configs. Just this: https://github.com/web3j/web3j/issues/1394#issuecomment-808192413. The pom.xml
looks like:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>poc</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>4.8.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<version>4.6.5</version>
<configuration>
<soliditySourceFiles/>
<solidity>
<version>
0.7.4
</version>
</solidity>
</configuration>
</plugin>
</plugins>
</build>
</project>
As you can see it is a plain java maven project with web3j and web3j-maven-plugin in it. And, I am running a local Besu n/w following these instructions: https://besu.hyperledger.org/en/stable/Tutorials/Private-Network/Create-IBFT-Network/.
What surprises me is that this java project was working fine when I was running besu in docker (before installing it on my machine). But after I followed the instructions here (https://besu.hyperledger.org/en/stable/Tutorials/Private-Network/Create-IBFT-Network/) to set besu locally, my java project gave me problems. Something strange going on here, I feel.
Can you please try with:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<solidity.version>0.7.4</solidity.version>
</properties>
Tried, no luck :(
what is the issue now ? are you sure you're not messing something else ? because I tested it on a dummy project with a complicated contract 0.7.4 and it worked fine. Can you provide more logs ?
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>poc</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<solidity.version>0.7.4</solidity.version>
</properties>
<dependencies>
<dependency>
<groupId>org.web3j</groupId>
<artifactId>core</artifactId>
<version>4.8.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.web3j</groupId>
<artifactId>web3j-maven-plugin</artifactId>
<version>4.6.5</version>
<configuration>
<soliditySourceFiles/>
</configuration>
</plugin>
</plugins>
</build>
</project>
Only this error I am getting now: https://github.com/web3j/web3j/issues/1394#issuecomment-808204122
Did adding the solidity version in the pom file have any impact on your side? It didn't on mine. Also, what solc
is installed locally in your case? In other words, what does solc --version
return?
I wish there was a way to see what solidity version web3j is using. 🤔
solc --version
won't give you which compiler it is using to compile the contracts.
What the solidity plugin will do is check the contracts for which solidity version they are using, install that version on your machine automatically and use it to compile the contract.
I think I read somewhere it uses the one present in your system path. Maybe I am wrong. But if what you're saying is the case then I totally don't get my issue here :(
Because I am sure the web3 plugin is getting the wrong sol version as when I remove the constructor and the pragma line from the contract, it compiles and runs fine.
Did you make sure to add the solidity.version
tag ?
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<solidity.version>0.7.4</solidity.version>
</properties>
Yes, I have added the version in the pom and then I ran mvn web3j:generate-sources
(this successfully generates the java files from my solidity files), and finally, I ran the java main method from the IDE. And, when running the main method, I get the above error.
So, based on the above, I think the maven plugin is doing its job but the web3j library isn't able to build my code because of the incorrect solidity version. Am I right in my understanding?
I don't think it is related to web3j-core
... Because once the wrappers are generated successfully, we no longer touch the smart contracts, and we use the wrappers for all future interactions.
Your exception says that there is an error with the constructor
of the smart contract.
If this is the case then why am I seeing the error while running and not while doing mvn web3j:generate-sources
? I mean is there some role of web3j maven plugin while building and running the project? I thought the maven plugin only comes into play when running mvn web3j:generate-sources
(that is, for converting the sol files to java files). That's it. Am I mistaken?
When running the application, it also executes the generate-sources
automatically in case the wrappers are not yet generated or they changed, but your issue is different. I can't judge from the inputs you're giving me. I need more details
This is the project I am trying to run. You can simply run the main()
method from the Main.java
class. If you need more info, I can surely help you with that as well.
I can't reproduce. When I run the project I get:
java.lang.RuntimeException: java.lang.RuntimeException: Error processing transaction request: transaction underpriced
when trying to deploy the auth
contract.
Try to clean the project directory maybe
You can run your ethereum n/w with min gas price of 0. Or, may change the price in ContractGasPrice.java
as per your eth network.
Btw, this is the longest chat I've ever had on Github. Thanks for your help once again 🙏
I am suspecting something to do with your path settings i am able to run the besu-poc project just fine, i changed the version to 0.7.5 (looks like this is the max it supports) and ran mvn web3j:generate-sources it automatically downloaded the solc for that and compile and i was able to start the app and issue coins. btw i don't have solc installed in my path. Not sure if that helps
[INFO] --- web3j-maven-plugin:4.6.5:generate-sources (default-cli) @ besu-poc --- [INFO] No Solidity directory specified, using default directory [src/main/resources] [INFO] No Solidity contracts specified, using the default [**/*.sol] [INFO] Adding to process 'Coin.sol' [INFO] Adding to process 'SafeMath.sol' [INFO] Adding to process 'Auth.sol' Solidity version 0.7.5 is not installed. Downloading and installing it to ~/.web3j/solc/0.7.5 [INFO] Built Class for contract 'Coin' [WARNING] Unable to parse input ABI file [INFO] Built Class for contract 'SafeMath' [INFO] Built Class for contract 'Auth' [INFO] ------------------------------------------------------------------------
@perusworld Same here. The plugin is supposed to do download the correct solc
version for you and compile the contracts using it.
@rampatra hope it works for you now.
@SweeXordious unfortunately, it still doesn't work. I even tried deleting the ~/.web3j
folder, restarting my machine, etc.
I think somewhere it's cached in my system 🤔 Do you know if there are any folders I can remove and try re-running the application?
@rampatra any progress on this ? can I close ?
@SweeXordious no, I didn't work much on this over the weekend but would again start debugging now. Btw, do you have any idea regarding this? Now, we are at least sure that my code is okay but there's something wrong with my environment. The web3j library is somehow picking up the wrong Solidity version. So, any folders to delete, any cache to clear, anything to reinstall/uninstall?
Maybe try creating another project and see if the issue still persists ? (without copy pasting anything)
Finally, I was able to get past this issue.
The issue was apparently because of Intellij-Solidity plugin. 🤦♂️
Removing this plugin from the IDE, made the project run fine. Closing this issue now. Can't thank enough to both of you for helping me out here.
My sample web3j java project was running fine but suddenly I started getting this error when I ran my vanilla Java project (with web3j as a dependency) (not sure what I changed except the installed Java version in my system). The error is :
I am actually not sure what the problem is here as the solidity files compile fine but when I run my java project, I get the above error. So, what may be the problem here? Any hints?