After struggling with issue from Geth (then I decided to use Geth 1.8.2, magically it solve the problem).
I found 2 approaches to send ether : The First approach are the codes following
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();
And 2nd approach is :
TransactionReceipt transactionReceipt = Transfer.sendFunds( web3, creds, "0x<TO_ADDRESS>", BigDecimal.valueOf(1.0),Convert.Unit.ETHER).sendAsync().get(); String etherReceipt = transactionReceipt.getTransactionHash();
Both are working smoothly, until I realized that the first one will directly create a transaction hash and the next operation can be continued, but the 2nd one will submit a transaction, it require me to start miner in order for it to be completed. Is there any way for the 2nd one to generate its transaction hash and does not require for the program to wait until it finish first then it continue.
Beside, which is the good/bad practice? Why? I would like to use the 2nd approach because it is tidier and shorter , also my way to send ERC20 token to another wallet is just using the wrapper instead of creating its raw transaction.