Java Code Examples for org.web3j.crypto.RawTransaction#createEtherTransaction()

The following examples show how to use org.web3j.crypto.RawTransaction#createEtherTransaction() . 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: SendingEther.java    From Android-Wallet-Token-ERC20 with Apache License 2.0 6 votes vote down vote up
@Override
protected EthSendTransaction doInBackground(String... values) {
    BigInteger ammount = Convert.toWei(values[1], Convert.Unit.ETHER).toBigInteger();
    try {

        RawTransaction rawTransaction = RawTransaction.createEtherTransaction(getNonce(), getGasPrice(), getGasLimit(), values[0], ammount);

        byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, mCredentials);
        String hexValue = "0x"+ Hex.toHexString(signedMessage);

        return mWeb3j.ethSendRawTransaction(hexValue.toString()).sendAsync().get();

    } catch (ExecutionException | InterruptedException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 2
Source File: TransferTransaction.java    From besu with Apache License 2.0 5 votes vote down vote up
public String signedTransactionData() {
  final Optional<BigInteger> nonce = getNonce();

  final RawTransaction transaction =
      RawTransaction.createEtherTransaction(
          nonce.orElse(nonce.orElseGet(sender::getNextNonce)),
          gasPrice,
          INTRINSIC_GAS,
          recipient.getAddress(),
          Convert.toWei(transferAmount, transferUnit).toBigIntegerExact());

  return toHexString(
      TransactionEncoder.signMessage(transaction, sender.web3jCredentialsOrThrow()));
}
 
Example 3
Source File: SignTransactionIT.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
private static RawTransaction createTransaction() {
    BigInteger value = Convert.toWei("1", Convert.Unit.ETHER).toBigInteger();

    return RawTransaction.createEtherTransaction(
            BigInteger.valueOf(1048587), BigInteger.valueOf(500000), BigInteger.valueOf(500000),
            "0x9C98E381Edc5Fe1Ac514935F3Cc3eDAA764cf004",
            value);
}
 
Example 4
Source File: SignTransactionIT.java    From web3j with Apache License 2.0 5 votes vote down vote up
private static RawTransaction createTransaction() {
    BigInteger value = Convert.toWei("1", Convert.Unit.ETHER).toBigInteger();

    return RawTransaction.createEtherTransaction(
            BigInteger.valueOf(1048587),
            BigInteger.valueOf(500000),
            BigInteger.valueOf(500000),
            "0x9C98E381Edc5Fe1Ac514935F3Cc3eDAA764cf004",
            value);
}
 
Example 5
Source File: CreateRawTransactionIT.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
private static RawTransaction createEtherTransaction(BigInteger nonce, String toAddress) {
    BigInteger value = Convert.toWei("0.5", Convert.Unit.ETHER).toBigInteger();

    return RawTransaction.createEtherTransaction(
            nonce, GAS_PRICE, GAS_LIMIT, toAddress, value);
}
 
Example 6
Source File: CreateRawTransactionIT.java    From web3j with Apache License 2.0 4 votes vote down vote up
private static RawTransaction createEtherTransaction(BigInteger nonce, String toAddress) {
    BigInteger value = Convert.toWei("0.5", Convert.Unit.ETHER).toBigInteger();

    return RawTransaction.createEtherTransaction(nonce, GAS_PRICE, GAS_LIMIT, toAddress, value);
}
 
Example 7
Source File: BaseIntegrationTest.java    From eventeum with Apache License 2.0 3 votes vote down vote up
protected String createRawSignedTransactionHex(String toAddress, BigInteger nonce) throws ExecutionException, InterruptedException {

        final RawTransaction rawTransaction  = RawTransaction.createEtherTransaction(
                nonce, GAS_PRICE, GAS_LIMIT, toAddress, BigInteger.ONE);

        final byte[] signedTx = TransactionEncoder.signMessage(rawTransaction, CREDS);

        return Numeric.toHexString(signedTx);
    }