20 java调用solidity 结构体和二维数组报错问题

首先: solidity代码

function getList(address[][] memory paths)
        public
        pure 
        returns (address  )
    {
        return paths[0][0];
    }

通过web3j的生成器,用abi生成

org.web3j.codegen.SolidityFunctionWrapperGenerator.main(
                new String[]{
//                            solidityContractPath,
                        "-a" + a,  // 使用正确的选项和参数
//                        "-b" + b,  // 使用正确的选项和参数
                        "-p", packageName,
                        "-o", outputDir
                }
        );

生成之后代码如下:

public RemoteFunctionCall<String> getList(List<List<String>> paths) {
        final Function function = new Function(FUNC_GETLIST,
                Arrays.<Type>asList(new DynamicArray<>( DynamicArray.class,
                        Utils.typeMap(paths, DynamicArray.class, Address.class))),
                Arrays.asList(new TypeReference<Address>() {
                }));
        return executeRemoteCallSingleValueReturn(function, String.class);
    }

通过java调用,返回 Exception in thread "main" org.web3j.tx.exceptions.ContractCallException: Contract Call has been reverted by the EVM with the reason: 'execution reverted'.

但是上述solidity代码再remix里面部署是可以用的,然后其他方法,只要入参不是二维数组和结构体,都正常可以用,web3j的版本是5.0.0, 有没有会java的哥们教一下怎么办,解决之后,我 V10U作为感谢!!

请先 登录 后评论

1 个回答

zhangdachui
请先 登录 后评论
  • 1 关注
  • 0 收藏,549 浏览
  • 没那么简单 提出于 2024-08-14 13:42