Skip to main content
added 459 characters in body
Source Link
Greg Jeanmart
  • 7.2k
  • 2
  • 20
  • 35

If you want to send an unsigned transaction and let the client pick up the account from to use to sign the transaction. You can do the following:

Ether transaction

Transaction transaction = Transaction.createEtherTransaction(from, nonce, gasPrice, gasLimit, to, value);
web3.ethSendTransaction(transaction);

Smart contract transaction

Function function = new Function<>(
        "functionName",  // function we're calling
        Arrays.asList(new Type(value), ...),  // Parameters to pass as Solidity Types
        Arrays.asList(new TypeReference<Type>() {}, ...));

String encodedFunction = FunctionEncoder.encode(function)
Transaction transaction = Transaction.createContractTransaction(from, nonce, gasPrice, encodedFunction);
web3.ethSendTransaction(transaction);

Transaction Receipt:

String txHash = web3.ethSendTransaction(transaction).send().getTransactionHash();

EthGetTransactionReceipt transactionReceipt =
         web3j.ethGetTransactionReceipt(txHash).send();

if (transactionReceipt.getTransactionReceipt.isPresent()) {
    String contractAddress = transactionReceipt.get().getContractAddress();
} else {
    // try again until it's mined
}

If you want to send an unsigned transaction and let the client pick up the account from to use to sign the transaction. You can do the following:

Ether transaction

Transaction transaction = Transaction.createEtherTransaction(from, nonce, gasPrice, gasLimit, to, value);
web3.ethSendTransaction(transaction);

Smart contract transaction

Function function = new Function<>(
        "functionName",  // function we're calling
        Arrays.asList(new Type(value), ...),  // Parameters to pass as Solidity Types
        Arrays.asList(new TypeReference<Type>() {}, ...));

String encodedFunction = FunctionEncoder.encode(function)
Transaction transaction = Transaction.createContractTransaction(from, nonce, gasPrice, encodedFunction);
web3.ethSendTransaction(transaction);

If you want to send an unsigned transaction and let the client pick up the account from to use to sign the transaction. You can do the following:

Ether transaction

Transaction transaction = Transaction.createEtherTransaction(from, nonce, gasPrice, gasLimit, to, value);
web3.ethSendTransaction(transaction);

Smart contract transaction

Function function = new Function<>(
        "functionName",  // function we're calling
        Arrays.asList(new Type(value), ...),  // Parameters to pass as Solidity Types
        Arrays.asList(new TypeReference<Type>() {}, ...));

String encodedFunction = FunctionEncoder.encode(function)
Transaction transaction = Transaction.createContractTransaction(from, nonce, gasPrice, encodedFunction);
web3.ethSendTransaction(transaction);

Transaction Receipt:

String txHash = web3.ethSendTransaction(transaction).send().getTransactionHash();

EthGetTransactionReceipt transactionReceipt =
         web3j.ethGetTransactionReceipt(txHash).send();

if (transactionReceipt.getTransactionReceipt.isPresent()) {
    String contractAddress = transactionReceipt.get().getContractAddress();
} else {
    // try again until it's mined
}
Source Link
Greg Jeanmart
  • 7.2k
  • 2
  • 20
  • 35

If you want to send an unsigned transaction and let the client pick up the account from to use to sign the transaction. You can do the following:

Ether transaction

Transaction transaction = Transaction.createEtherTransaction(from, nonce, gasPrice, gasLimit, to, value);
web3.ethSendTransaction(transaction);

Smart contract transaction

Function function = new Function<>(
        "functionName",  // function we're calling
        Arrays.asList(new Type(value), ...),  // Parameters to pass as Solidity Types
        Arrays.asList(new TypeReference<Type>() {}, ...));

String encodedFunction = FunctionEncoder.encode(function)
Transaction transaction = Transaction.createContractTransaction(from, nonce, gasPrice, encodedFunction);
web3.ethSendTransaction(transaction);