我正在使用Infura和 web3j 查询以太坊区块链。我的目的是获取有关某些块的信息,因此我正在使用功能 web3.eth.getBlockByNumber ,但是它给我提供了不兼容的类型错误:int无法转换为DefaultBlockParameter。如何将整数转换为默认块参数?当前代码:
System.out.println("here " +web3j.ethGetBlockByNumber(6777, true));
我也曾尝试将6777转换为BigInteger,但这也给了我不兼容的类型错误。
答案 0 :(得分:0)
web3j使用DefaultBlockParameter类型对此类调用中的块编号进行编码,可能会处理“最新”和“未决”块状态的特殊情况。试试:
System.out.println("here " +web3j.ethGetBlockByNumber(new DefaultBlockParameter(6777), true));