Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't generateContractWrappers for solidity 0.8.x due result json change format #83

Closed
longdt opened this issue Nov 5, 2021 · 6 comments

Comments

@longdt
Copy link

longdt commented Nov 5, 2021

I have simple solidity contract:


contract SimpleStorage {
    uint storedData;

    function set(uint x) public {
        storedData = x;
    }

    function get() public view returns (uint) {
        return storedData;
    }
}

when I run: mvn web3j:generate-sources -e -X command I got error:
class org.json.simple.JSONArray cannot be cast to class java.lang.String (org.json.simple.JSONArray is in unnamed module of loader org.codehaus.plexus.classworlds.realm.ClassRealm @51dbd6e4; java.lang.String is in module java.base of loader 'bootstrap')
Digging more plugin log, I found some change from result json of solidity compiler 0.8.x

DEBUG] Result: {"contracts":{"/home/longdt/IdeaProjects/bscexample/src/main/resources/SimpleStorage.sol:SimpleStorage":{"abi":[{"inputs":[],"name":"get","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"set","outputs":[],"stateMutability":"nonpayable","type":"function"}],"bin":"608060405234801561001057600080fd5b5060c38061001f6000396000f3fe6080604052348015600f57600080fd5b506004361060325760003560e01c806360fe47b11460375780636d4ce63c146048575b600080fd5b60466042366004606d565b6062565b005b604e6067565b604051605991906084565b60405180910390f35b600055565b60005490565b600060208284031215607d578081fd5b5035919050565b9081526020019056fea2646970667358221220c3e27a2753ab4a634d87f9c7953cf1214a691cd65ad224ea42b29f594c0e8a8e64736f6c63430008010033","metadata":"{"compiler":{"version":"0.8.1+commit.df193b15"},"language":"Solidity","output":{"abi":[{"inputs":[],"name":"get","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"x","type":"uint256"}],"name":"set","outputs":[],"stateMutability":"nonpayable","type":"function"}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"compilationTarget":{"/home/longdt/IdeaProjects/bscexample/src/main/resources/SimpleStorage.sol":"SimpleStorage"},"evmVersion":"istanbul","libraries":{},"metadata":{"bytecodeHash":"ipfs"},"optimizer":{"enabled":true,"runs":200},"remappings":[]},"sources":{"/home/longdt/IdeaProjects/bscexample/src/main/resources/SimpleStorage.sol":{"keccak256":"0x866a2ad7baba979760a3f8399e5a67c5f84c28b1c4854a9f05b41de957d00907","urls":["bzz-raw://b054291d54d7d923a51e0c9254b37fc85e8907577eb82e623dd9c6cca804fe63","dweb:/ipfs/QmXDigRMzg7DTKZCHugyHJUqmPFbajRbF4yaCkoCDp1kRf"]}},"version":1}"}},"version":"0.8.1+commit.df193b15.Linux.g++"}

Specifically, abi field change data type from string (in version <= 0.7.x) to array (in version 0.8.x), so it cause following code in class JavaClassGeneratorMojo throws casting exception

List<AbiDefinition> functionDefinitions = loadContractDefinition(results.get(SolidityCompiler.Options.ABI.getName()));
or
String abiJson = contractResult.get(SolidityCompiler.Options.ABI.getName());

  • OS: Ubuntu 20.04
  • Java: 17
  • Solidity: 0.8.x
@longdt longdt changed the title Can't generateContractWrappers for solidity 0.8.x due result change format for abi field Can't generateContractWrappers for solidity 0.8.x due result json change format Nov 5, 2021
@longdt
Copy link
Author

longdt commented Nov 8, 2021

It seen low develop activity in this repo. I fixed by make a fork.

Thanks

@longdt longdt closed this as completed Nov 8, 2021
@harrigan
Copy link

harrigan commented Dec 8, 2021

I had the same issue and your fork fixed it for me. Thanks.

@gianx89
Copy link

gianx89 commented Dec 9, 2021

I have the same problem under Ubuntu, but not on Windows.

Using @longdt fork all is fine.

@tmac2yt
Copy link

tmac2yt commented Feb 6, 2022

It works for me.Thanks very much! @longdt

@gtebrean
Copy link
Contributor

here is also a PR part of this fix, it will be merged soon
#89

@longdt
Copy link
Author

longdt commented Feb 23, 2022

@gtebrean There is already a PR for this bug but they doesn't merge it #85 So don't hope It will be merged soon. And you should use my fork because this plugin doesn't work with solidity compiler version >= 0.8.10

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

No branches or pull requests

5 participants