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

The following examples show how to use org.web3j.protocol.core.methods.response.EthSendTransaction. These examples are extracted from open source projects. 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
@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 2
@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 3
@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 4
@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 5
@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
@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 7
@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 8
@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 9
@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 10
Source Project: ethsigner   Source File: EeaSendTransaction.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Due to the underlying server mocking, When only a single request is used, the contents does not
 * actually matter, only their equivalence does.
 */
public Request<Object, EthSendTransaction> request(final PrivateTransaction privateTransaction) {
  final JsonObject jsonObject = new JsonObject();
  putValue(jsonObject, FIELD_FROM, privateTransaction.getFrom());
  putValue(jsonObject, FIELD_NONCE, privateTransaction.getNonce());
  putValue(jsonObject, FIELD_GAS_PRICE, privateTransaction.getGasPrice());
  putValue(jsonObject, FIELD_GAS, privateTransaction.getGas());
  putValue(jsonObject, FIELD_TO, privateTransaction.getTo());
  putValue(jsonObject, FIELD_VALUE, privateTransaction.getValue());
  putValue(jsonObject, FIELD_DATA, privateTransaction.getData());
  putValue(jsonObject, FIELD_PRIVATE_FROM, privateTransaction.getPrivateFrom());
  putValue(jsonObject, FIELD_PRIVATE_FOR, privateTransaction.getPrivateFor());
  putValue(jsonObject, FIELD_PRIVACY_GROUP_ID, privateTransaction.getPrivacyGroupId());
  putValue(jsonObject, FIELD_RESTRICTION, privateTransaction.getRestriction());
  return createRequest(jsonObject);
}
 
Example 11
@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 12
@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 13
@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
@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
@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
@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
@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 18
@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
@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
@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
@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 Project: web3j   Source File: RawTransactionManager.java    License: 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
@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 24
Source Project: web3j   Source File: CreateRawTransactionIT.java    License: 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 25
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());
}
 
Example 26
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 27
Source Project: web3j   Source File: PrivateTransactionManager.java    License: 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 Project: web3j_demo   Source File: Web3jUtils.java    License: Apache License 2.0 6 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 29
@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 30
@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()));
}