FISCO-BCOS / solcJ

a jar for the solidity compiler
Apache License 2.0
7 stars 10 forks source link

使用不同的版本编译合约表现不一致 #34

Open 13813385093 opened 11 months ago

13813385093 commented 11 months ago

我使用v0.4.25.0编译HelloWorld.sol可以编译通过,但是当我切换成v0.6.10.0或0.8.11.1编译同样的合约的时候,就报错了。错误提示:"No input files given. If you wish to use the standard input please specify "-" explicitly."。请问应该如何解决。

kyonRay commented 11 months ago

请提供 0.4.25调用编译时使用的参数。

kyonRay commented 11 months ago

在使用SolidityCompiler.compile(byte[] source, boolean sm, boolean combinedJson, Option... options) 接口时,当solc版本高于0.5的时候,要带上 “-” 的option,和注释描述的一样,在0.5的solc之后对于stdin都需要加上 '-' 的参数。

使用释例:

File file = new File(url.getFile());
byte[] bytes = new byte[(int) file.length()];
try (FileInputStream fileInputStream = new FileInputStream(file)) {
    if (fileInputStream.read(bytes) != bytes.length) {
        throw new IOException("incomplete reading of file: " + file);
    }
}
SolidityCompiler.Option option = new SolidityCompiler.CustomOption("", "-");
Result compile = SolidityCompiler.compile(bytes, false, true, ABI, BIN, METADATA,option);