Java web3j调用合约返回数据编码

image.png

生成Java文件的代码

public RemoteFunctionCall<TransactionReceipt> averagePrice() {
        final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
                FUNC_AVERAGEPRICE, 
                Arrays.<Type>asList(), 
                Collections.<TypeReference<?>>emptyList());
        return executeRemoteCallTransaction(function);
    }

调用返回数据:

RemoteFunctionCall<TransactionReceipt> transactionReceiptRemoteFunctionCall = token.averagePrice();
        String s = transactionReceiptRemoteFunctionCall.encodeFunctionCall();
        System.out.println(s);//返回结果 0xa0352ea3

请问下这个返回要怎么编码转换。

请先 登录 后评论

最佳答案 2023-07-13 10:07

    public RemoteFunctionCall<Uint256> getAveragePrice() {
        final org.web3j.abi.datatypes.Function function = new org.web3j.abi.datatypes.Function(
                FUNC_AVERAGEPRICE,
                Arrays.<Type>asList(),
                Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {
                }));
        return executeRemoteCallSingleValueReturn(function);
    }

        CompletableFuture<Uint256> value = gsToken.getAveragePrice().sendAsync();
        System.out.println(value.get().getValue());
请先 登录 后评论

其它 2 个回答

nono
请先 登录 后评论
Phoenix
请先 登录 后评论
  • 3 关注
  • 0 收藏,2246 浏览
  • lfhuang 提出于 2022-03-25 17:14

相似问题