Smart Contract Wrapper Generation in error with functions with parameters without name
Hi, I was using web3j (0.5.1) to create the Smart Contract wrapper. But I have this error:
Exception in thread "main" java.lang.IllegalArgumentException: not a valid name: at com.squareup.javapoet.Util.checkArgument(Util.java:64) at com.squareup.javapoet.ParameterSpec.builder(ParameterSpec.java:83) at com.squareup.javapoet.MethodSpec$Builder.addParameter(MethodSpec.java:379) at org.web3j.codegen.SolidityFunctionWrapperGenerator.createFunctionDefinitions(SolidityFunctionWrapperGenerator.java:191) at org.web3j.codegen.SolidityFunctionWrapperGenerator.generateSolidityWrappers(SolidityFunctionWrapperGenerator.java:159) at org.web3j.codegen.SolidityFunctionWrapperGenerator.generate(SolidityFunctionWrapperGenerator.java:124) at org.web3j.codegen.SolidityFunctionWrapperGenerator.main(SolidityFunctionWrapperGenerator.java:66) at com.nttdata.ethereum.marketplace.Test.main(Test.java:26)
I debugged the code, and I noticed that in the ABI there was a function like this:
{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"insuranceWithdraw","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"}
This function is created by Solidity because of I'm using a public map
mapping (address => unit) public insuranceWithdraw;
I think the best thing is to give a default name, with an increasing number.
I'm presuming you updated to the latest release?
Yes, I was using an old version.
3.2 is the latest release ri8 ?
The same problem occurs with unnamed event parameters. I’m guessing it’s the same underlying bug. @conor10 Example:
// HelloWorld.sol
pragma solidity ^0.4.24;
contract HelloWorld {
event Foo(uint);
}
$ solc HelloWorld.sol --bin --abi -o ./
$ web3j solidity generate HelloWorld.bin HelloWorld.abi -o . -p org.web3j.sample
_ _____ _ _
| | |____ (_) (_)
__ _____| |__ / /_ _ ___
\ \ /\ / / _ \ '_ \ \ \ | | | / _ \
\ V V / __/ |_) |.___/ / | _ | || (_) |
\_/\_/ \___|_.__/ \____/| |(_)|_| \___/
_/ |
|__/
Generating org.web3j.sample.HelloWorld ... Exception in thread "main" java.lang.IllegalArgumentException: not a valid name:
at com.squareup.javapoet.Util.checkArgument(Util.java:64)
at com.squareup.javapoet.FieldSpec.builder(FieldSpec.java:92)
at com.squareup.javapoet.TypeSpec$Builder.addField(TypeSpec.java:499)
at org.web3j.codegen.SolidityFunctionWrapper.buildEventResponseObject(SolidityFunctionWrapper.java:753)
at org.web3j.codegen.SolidityFunctionWrapper.buildEventFunctions(SolidityFunctionWrapper.java:896)
at org.web3j.codegen.SolidityFunctionWrapper.buildFunctionDefinitions(SolidityFunctionWrapper.java:255)
at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityFunctionWrapper.java:130)
at org.web3j.codegen.SolidityFunctionWrapper.generateJavaFiles(SolidityFunctionWrapper.java:111)
at org.web3j.codegen.SolidityFunctionWrapperGenerator.generate(SolidityFunctionWrapperGenerator.java:123)
at org.web3j.codegen.SolidityFunctionWrapperGenerator.main(SolidityFunctionWrapperGenerator.java:87)
at org.web3j.codegen.SolidityFunctionWrapperGenerator.run(SolidityFunctionWrapperGenerator.java:48)
at org.web3j.console.Runner.main(Runner.java:38)
Once a name is added, it works fine.