org.web3j.protocol.core.methods.response.EthSendTransaction Java Examples

The following examples show how to use org.web3j.protocol.core.methods.response.EthSendTransaction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Web3jUtils.java    From web3j_demo with Apache License 2.0 7 votes vote down vote up
/**
 * Transfers the specified amount of Wei from the coinbase to the specified account.
 * The method waits for the transfer to complete using method {@link waitForReceipt}.  
 */
public static TransactionReceipt transferFromCoinbaseAndWait(Web3j web3j, String to, BigInteger amountWei) 
		throws Exception 
{
	String coinbase = getCoinbase(web3j).getResult();
	BigInteger nonce = getNonce(web3j, coinbase);
	// this is a contract method call -> gas limit higher than simple fund transfer
	BigInteger gasLimit = Web3jConstants.GAS_LIMIT_ETHER_TX.multiply(BigInteger.valueOf(2)); 
	Transaction transaction = Transaction.createEtherTransaction(
			coinbase, 
			nonce, 
			Web3jConstants.GAS_PRICE, 
			gasLimit, 
			to, 
			amountWei);

	EthSendTransaction ethSendTransaction = web3j
			.ethSendTransaction(transaction)
			.sendAsync()
			.get();

	String txHash = ethSendTransaction.getTransactionHash();
	
	return waitForReceipt(web3j, txHash);
}
 
Example #2
Source File: SigningEthSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenValueIsNull() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.withValue(null));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(transactionBuilder.withValue(FIELD_VALUE_DEFAULT)));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1666666");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #3
Source File: SigningEeaSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenToHasAddressMissingHexPrefix() {
  final Request<Object, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(
          transactionBuilder.withTo("7577919ae5df4941180eac211965f275CDCE314D"));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(
              transactionBuilder.withTo("0x7577919ae5df4941180eac211965f275CDCE314D")));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1355555");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #4
Source File: TransactionRepository.java    From trust-wallet-android-source with GNU General Public License v3.0 6 votes vote down vote up
@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());
}
 
Example #5
Source File: SigningEeaSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenValueIsNull() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.withValue(null));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(transactionBuilder.withValue(FIELD_VALUE_DEFAULT)));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1666666");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #6
Source File: SigningEeaSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signSendTransactionWithPrivacyGroupId() {
  final PrivateTransaction privateTransaction = privacyGroupIdTransaction().build();
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(privateTransaction);
  final String sendRawTransactionRequest =
      sendRawTransaction.request(sendTransaction.request(privateTransaction));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d0592102999999999");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #7
Source File: SigningEeaSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenMissingGas() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.missingGas());
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(transactionBuilder.withGas(FIELD_GAS_DEFAULT)));

  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d7777777");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #8
Source File: RawTransactionManager.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Override
public EthSendTransaction sendTransaction(
        BigInteger gasPrice,
        BigInteger gasLimit,
        String to,
        String data,
        BigInteger value,
        boolean constructor)
        throws IOException {

    BigInteger nonce = getNonce();

    RawTransaction rawTransaction =
            RawTransaction.createTransaction(nonce, gasPrice, gasLimit, to, value, data);

    return signAndSend(rawTransaction);
}
 
Example #9
Source File: SigningEeaSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenGasPriceIsNull() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.withGasPrice((null)));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(transactionBuilder.withGasPrice(FIELD_GAS_PRICE_DEFAULT)));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d0592102688888888");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #10
Source File: SigningEeaSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenMissingGasPrice() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.missingGasPrice());
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(transactionBuilder.withGasPrice(FIELD_GAS_PRICE_DEFAULT)));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d0592102688888888");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #11
Source File: SigningEeaSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenMissingValue() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.missingValue());
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(transactionBuilder.withValue(FIELD_VALUE_DEFAULT)));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1666666");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #12
Source File: SigningEthSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenFromAddressCaseMismatchesUnlockedAccount() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(
          transactionBuilder.withFrom("0x7577919ae5df4941180eac211965f275CDCE314D"));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(
              transactionBuilder.withFrom("0x7577919ae5df4941180eac211965f275cdce314d")));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1666666");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #13
Source File: SigningEthSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenEmpty0xToAddress() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.withTo("0x"));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(sendTransaction.request(transactionBuilder.missingTo()));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1355555");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #14
Source File: SigningEthSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenToHasAddressMissingHexPrefix() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(
          transactionBuilder.withTo("7577919ae5df4941180eac211965f275CDCE314D"));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(
              transactionBuilder.withTo("0x7577919ae5df4941180eac211965f275CDCE314D")));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1355555");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #15
Source File: SigningEthSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenToAddressIsNull() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.withTo(null));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(sendTransaction.request(transactionBuilder.missingTo()));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1355555");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #16
Source File: SigningEthSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenMissingValue() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.missingValue());
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(transactionBuilder.withValue(FIELD_VALUE_DEFAULT)));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1666666");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #17
Source File: SigningEthSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenEmptyToAddress() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.withTo(""));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(sendTransaction.request(transactionBuilder.missingTo()));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d1355555");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #18
Source File: SigningEthSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenMissingGas() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.missingGas());
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(transactionBuilder.withGas(FIELD_GAS_DEFAULT)));

  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d7777777");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #19
Source File: SigningEthSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenGasIsNull() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.withGas(null));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(transactionBuilder.withGas(FIELD_GAS_DEFAULT)));

  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d05921026d7777777");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #20
Source File: SigningEthSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signTransactionWhenGasPriceIsNull() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.withGasPrice(null));
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(transactionBuilder.withGasPrice(FIELD_GAS_PRICE_DEFAULT)));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d0592102688888888");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #21
Source File: SigningEthSendTransactionIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signSendTransactionWhenMissingData() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(transactionBuilder.missingData());
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(transactionBuilder.withData(FIELD_DATA_DEFAULT)));
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d0592102999999999");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #22
Source File: RawTransactionManager.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Override
public EthSendTransaction sendTransactionEIP1559(
        BigInteger gasPremium,
        BigInteger feeCap,
        BigInteger gasLimit,
        String to,
        String data,
        BigInteger value,
        boolean constructor)
        throws IOException {

    BigInteger nonce = getNonce();

    RawTransaction rawTransaction =
            RawTransaction.createTransaction(
                    nonce, null, gasLimit, to, value, data, gasPremium, feeCap);

    return signAndSend(rawTransaction);
}
 
Example #23
Source File: RawTransactionManager.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Override
public EthSendTransaction sendTransaction(
        BigInteger gasPrice, BigInteger gasLimit, String to,
        String data, BigInteger value) throws IOException {

    BigInteger nonce = getNonce();

    RawTransaction rawTransaction = RawTransaction.createTransaction(
            nonce,
            gasPrice,
            gasLimit,
            to,
            value,
            data);

    return signAndSend(rawTransaction);
}
 
Example #24
Source File: SigningEthSendTransactionWithChainIdIntegrationTest.java    From ethsigner with Apache License 2.0 6 votes vote down vote up
@Test
void signSendTransactionWhenContractWithLongChainId() {
  final Request<?, EthSendTransaction> sendTransactionRequest =
      sendTransaction.request(Transaction.smartContract());
  final String sendRawTransactionRequest =
      sendRawTransaction.request(
          sendTransaction.request(Transaction.smartContract()), 4123123123L);
  final String sendRawTransactionResponse =
      sendRawTransaction.response(
          "0xe670ec64341771606e55d6b4ca35a1a6b75ee3d5145a99d0592102688888888");
  setUpEthNodeResponse(
      request.ethNode(sendRawTransactionRequest), response.ethNode(sendRawTransactionResponse));

  sendPostRequestAndVerifyResponse(
      request.ethSigner(sendTransactionRequest), response.ethSigner(sendRawTransactionResponse));

  verifyEthNodeReceived(sendRawTransactionRequest);
}
 
Example #25
Source File: CreateRawTransactionIT.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDeploySmartContract() throws Exception {
    BigInteger nonce = getNonce(ALICE.getAddress());
    RawTransaction rawTransaction = createSmartContractTransaction(nonce);

    byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, ALICE);
    String hexValue = Numeric.toHexString(signedMessage);

    EthSendTransaction ethSendTransaction =
            web3j.ethSendRawTransaction(hexValue).sendAsync().get();
    String transactionHash = ethSendTransaction.getTransactionHash();

    assertFalse(transactionHash.isEmpty());

    TransactionReceipt transactionReceipt =
            waitForTransactionReceipt(transactionHash);

    assertThat(transactionReceipt.getTransactionHash(), is(transactionHash));

    assertFalse("Contract execution ran out of gas",
            rawTransaction.getGasLimit().equals(transactionReceipt.getGasUsed()));
}
 
Example #26
Source File: CreateRawTransactionIT.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testTransferEther() throws Exception {
    BigInteger nonce = getNonce(ALICE.getAddress());
    RawTransaction rawTransaction = createEtherTransaction(
            nonce, BOB.getAddress());

    byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, ALICE);
    String hexValue = Numeric.toHexString(signedMessage);

    EthSendTransaction ethSendTransaction =
            web3j.ethSendRawTransaction(hexValue).sendAsync().get();
    String transactionHash = ethSendTransaction.getTransactionHash();

    assertFalse(transactionHash.isEmpty());

    TransactionReceipt transactionReceipt =
            waitForTransactionReceipt(transactionHash);

    assertThat(transactionReceipt.getTransactionHash(), is(transactionHash));
}
 
Example #27
Source File: PrivateTransactionManager.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Override
public String sendCall(
        final String to, final String data, final DefaultBlockParameter defaultBlockParameter)
        throws IOException {
    try {
        EthSendTransaction est =
                sendTransaction(
                        gasProvider.getGasPrice(),
                        gasProvider.getGasLimit(),
                        to,
                        data,
                        BigInteger.ZERO);
        final TransactionReceipt ptr = processResponse(est);

        if (!ptr.isStatusOK()) {
            throw new ContractCallException(
                    String.format(REVERT_ERR_STR, extractRevertReason(ptr, data, besu, false)));
        }
        return ((PrivateTransactionReceipt) ptr).getOutput();
    } catch (TransactionException e) {
        log.error("Failed to execute call", e);
        return null;
    }
}
 
Example #28
Source File: CreateTransactionInteract.java    From Upchain-wallet with GNU Affero General Public License v3.0 6 votes vote down vote up
public Single<String> createTransaction(ETHWallet from, BigInteger gasPrice, BigInteger gasLimit, String data, String password) {

        final Web3j web3j = Web3j.build(new HttpService(networkRepository.getDefaultNetwork().rpcServerUrl));

        return networkRepository.getLastTransactionNonce(web3j, from.address)
                .flatMap(nonce -> getRawTransaction(nonce, gasPrice, gasLimit, BigInteger.ZERO, data))
                .flatMap(rawTx -> signEncodeRawTransaction(rawTx, password, from, networkRepository.getDefaultNetwork().chainId))
                .flatMap(signedMessage -> Single.fromCallable( () -> {
                    EthSendTransaction raw = web3j
                            .ethSendRawTransaction(Numeric.toHexString(signedMessage))
                            .send();
                    if (raw.hasError()) {
                        throw new Exception(raw.getError().getMessage());
                    }
                    return raw.getTransactionHash();
                })).subscribeOn(Schedulers.io());

    }
 
Example #29
Source File: CreateRawTransactionIT.java    From web3j with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeploySmartContract() throws Exception {
    BigInteger nonce = getNonce(ALICE.getAddress());
    RawTransaction rawTransaction = createSmartContractTransaction(nonce);

    byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, ALICE);
    String hexValue = Numeric.toHexString(signedMessage);

    EthSendTransaction ethSendTransaction =
            web3j.ethSendRawTransaction(hexValue).sendAsync().get();
    String transactionHash = ethSendTransaction.getTransactionHash();

    assertFalse(transactionHash.isEmpty());

    TransactionReceipt transactionReceipt = waitForTransactionReceipt(transactionHash);

    assertEquals(transactionHash, transactionReceipt.getTransactionHash());

    assertFalse(
            rawTransaction.getGasLimit().equals(transactionReceipt.getGasUsed()),
            "Contract execution ran out of gas");
}
 
Example #30
Source File: CreateTransactionInteract.java    From Upchain-wallet with GNU Affero General Public License v3.0 6 votes vote down vote up
public Single<String> createTransaction(ETHWallet from, String toAddress, BigInteger subunitAmount, BigInteger gasPrice, BigInteger gasLimit, String data, String password) {
    final Web3j web3j = Web3j.build(new HttpService(networkRepository.getDefaultNetwork().rpcServerUrl));

    return networkRepository.getLastTransactionNonce(web3j, from.address)
            .flatMap(nonce -> getRawTransaction(nonce, gasPrice, gasLimit,toAddress, subunitAmount,  data))
            .flatMap(rawTx -> signEncodeRawTransaction(rawTx, password, from, networkRepository.getDefaultNetwork().chainId))
            .flatMap(signedMessage -> Single.fromCallable( () -> {
                EthSendTransaction raw = web3j
                        .ethSendRawTransaction(Numeric.toHexString(signedMessage))
                        .send();
                if (raw.hasError()) {
                    throw new Exception(raw.getError().getMessage());
                }
                return raw.getTransactionHash();
            })).subscribeOn(Schedulers.io());
}