0

我想在 web3j 中广播原始 ETH 交易并为其支付费用,我使用以下代码获取交易的十六进制值

EthGetTransactionCount ethGetTransactionCount = web3j.ethGetTransactionCount(credentials.getAddress(), DefaultBlockParameterName.PENDING).send();
        BigInteger nonce =  ethGetTransactionCount.getTransactionCount();
        
        RawTransaction rawTransaction = RawTransaction.createEtherTransaction(nonce, gasPrice, gasLimit, to, value);

        // Sign the Transaction
        byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);

        String hexValue = Numeric.toHexString(signedMessage);
        System.out.println(hexValue);

如何使用我的钱包广播和支付十六进制值的交易费用?

4

1 回答 1

1

简单地做这样的事情:

EthSendTransaction result = web3j.ethSendRawTransaction(hexValue).send();
String hash = result.getTransactionHash();
于 2021-11-10T14:22:18.640 回答