Go-Ethereum

Web3j - Transfer.sendFunds 永遠等待

  • November 8, 2018

在解決了 Geth 的問題之後(然後我決定使用 Geth 1.8.2,它神奇地解決了問題)。

我發現了兩種發送乙太的方法: 第一種方法是以下程式碼

    EthGetTransactionCount ethGetTransactionCount = web3.ethGetTransactionCount(
    creds.getAddress(), DefaultBlockParameterName.LATEST).sendAsync().get();
    BigInteger nonce = ethGetTransactionCount.getTransactionCount();

    RawTransaction rawTransaction = RawTransaction.createEtherTransaction(
    nonce, gasPrice, gasLimit, "0x<TO_ADDRESS>",
    new BigInteger("10000"));

    byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, creds);
    String hexValue = Numeric.toHexString(signedMessage);
    // FROM here you can get the tx hash.
    EthSendTransaction ethSendTransaction =
    web3.ethSendRawTransaction(hexValue).send();

第二種方法是:

TransactionReceipt transactionReceipt = Transfer.sendFunds(
    web3, creds, "0x<TO_ADDRESS>",
    BigDecimal.valueOf(1.0),Convert.Unit.ETHER).sendAsync().get();
    String etherReceipt = transactionReceipt.getTransactionHash();

兩者都工作順利,直到我意識到第一個會直接創建交易雜湊並可以繼續下一個操作,但是第二個會送出交易,它需要我啟動礦工才能完成。有沒有辦法讓第二個生成它的事務雜湊,並且不需要程序等到它先完成然後繼續。

此外,哪個是好的/壞的做法?為什麼?我想使用第二種方法,因為它更整潔更短,而且我將 ERC20 令牌發送到另一個錢包的方法只是使用包裝器而不是創建其原始交易。

在第一種方法中,您可以操縱隨機數:),如果您的交易卡住了,這很有用

引用自:https://ethereum.stackexchange.com/questions/41563