private TransactionReceipt processResponse(EthSendTransaction transactionResponse) throws IOException, TransactionException { if (transactionResponse.hasError()) { throw new RuntimeException("Error processing transaction request: " + transactionResponse.getError().getMessage()); } String transactionHash = transactionResponse.getTransactionHash(); return transactionReceiptProcessor.waitForTransactionReceipt(transactionHash); }
public EthSendTransaction signAndSend(RawTransaction rawTransaction) throws IOException { String hexValue = sign(rawTransaction); EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).send(); if (ethSendTransaction != null && !ethSendTransaction.hasError()) { String txHashLocal = Hash.sha3(hexValue); String txHashRemote = ethSendTransaction.getTransactionHash(); if (!txHashVerifier.verify(txHashLocal, txHashRemote)) { throw new TxHashMismatchException(txHashLocal, txHashRemote); } } return ethSendTransaction; } }
private String sendTransaction( Credentials credentials, String contractAddress, BigInteger gas, String encodedFunction) throws Exception { BigInteger nonce = getNonce(credentials.getAddress()); Transaction transaction = Transaction.createFunctionCallTransaction( credentials.getAddress(), nonce, Transaction.DEFAULT_GAS, gas, contractAddress, encodedFunction); org.web3j.protocol.core.methods.response.EthSendTransaction transactionResponse = web3j.ethSendTransaction(transaction).sendAsync().get(); assertFalse(transactionResponse.hasError()); return transactionResponse.getTransactionHash(); }
@Override public Single<String> createTransaction(Wallet from, String toAddress, BigInteger subunitAmount, BigInteger gasPrice, BigInteger gasLimit, byte[] data, String password) { final Web3j web3j = Web3jFactory.build(new HttpService(networkRepository.getDefaultNetwork().rpcServerUrl)); return Single.fromCallable(() -> { EthGetTransactionCount ethGetTransactionCount = web3j .ethGetTransactionCount(from.address, DefaultBlockParameterName.LATEST) .send(); return ethGetTransactionCount.getTransactionCount(); }) .flatMap(nonce -> accountKeystoreService.signTransaction(from, password, toAddress, subunitAmount, gasPrice, gasLimit, nonce.longValue(), data, networkRepository.getDefaultNetwork().chainId)) .flatMap(signedMessage -> Single.fromCallable( () -> { EthSendTransaction raw = web3j .ethSendRawTransaction(Numeric.toHexString(signedMessage)) .send(); if (raw.hasError()) { throw new ServiceException(raw.getError().getMessage()); } return raw.getTransactionHash(); })).subscribeOn(Schedulers.io()); }