【问题标题】:How to extract data from "RemoteCall<BigInteger>" return type function in java/kotlin?如何从 java/kotlin 中的“RemoteCall<BigInteger>”返回类型函数中提取数据?
【发布时间】:2019-04-23 05:53:14
【问题描述】:

我正在尝试使用 web3j 从 erc20 代币合约中读取地址余额。我已经生成了 java 等效的合同文件。在这个文件中,一个函数返回 RemoteCall 类型的对象。现在,如何解析这个输出以便我可以简单地得到数字(大整数值)?

当我尝试使用 android log 记录输出时,我得到了某种加密输出 -

org.web3j.protocol.core.RemoteCall@48c4d84

现在我完全不知道下一步该做什么?

public RemoteCall<BigInteger> balanceOf(String param0) {
    final Function function = new Function(FUNC_BALANCEOF, Arrays.<Type>asList(new Address(param0)),
            Arrays.<TypeReference<?>>asList(new TypeReference<Uint256>() {}));
    return executeRemoteCallSingleValueReturn(function, BigInteger.class);
}

预期的输出是一个大整数类型的数字(地址的代币余额)。

【问题讨论】:

  • 该输出未编码。 org.web3j.protocol.core.RemoteCall@48c4d84 只是对象的类名和内存引用。这仅仅意味着toString() 没有在该对象上实现。
  • 您是否阅读过有关 RemoteCall 类的任何文档?有哪些方法?
  • 找不到此页面。另外,我已经尝试过 web3j 文档,但没有任何关于如何解析结果的细节。

标签: java ethereum geth web3-java


【解决方案1】:

您需要在从balanceOf() 返回的RemoteCall&lt;BigInteger&gt; 的实例上调用send()

RemoteCall<BigInteger> remoteCall = someObject.balanceOf(someParameter);
BigInteger result = remoteCall.send();

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-08
    • 1970-01-01
    相关资源
    最近更新 更多