通过在Android中使用Web3j与智能合约交互失败

时间:2020-09-04 07:54:35

标签: android smartcontracts web3js

我无法从合同中获得确切的哈希值。它似乎无法连接到特定的智能合约。 通过使用ransaction.createEthCallTransaction和ethCall从合同中获得价值是成功的。但是设置值不是。

我使用infura节点,其他设置很好。你能解释为什么我失败了吗?

     private String store(int num){
    Function function = new Function(
            "store",
            Arrays.asList(new Uint256(num)),
            Collections.emptyList()
    );return storeEthCall(function, num);
}
private String storeEthCall(Function function, int num){
    Log.d(TAG, "storeEthCall()...");

    String encodedFunction = FunctionEncoder.encode(function);

    try {
        BigInteger nonce = getNonce();
        Transaction transaction = Transaction.createFunctionCallTransaction(credentials.getAddress(), nonce  ,BigInteger.valueOf(100), BigInteger.valueOf(50000L),"0x1ae7954BC0f3CfAAb7bd4562C71a6C17d7cDBd4c", (BigInteger.valueOf(num)),  encodedFunction );
        EthSendTransaction transactionResponse = web3j.ethSendTransaction(transaction).sendAsync().get();
        System.out.println(transactionResponse.getResult());
        Log.d(TAG, "Hash : "+transactionResponse.getTransactionHash());
    } catch (ExecutionException e) {
        e.printStackTrace();
        return "fail";
    } catch (InterruptedException e) {
        e.printStackTrace();
        return "fail";
    }




    return "success";
}

0 个答案:

没有答案