Search in sources :

Example 1 with RawTransaction

use of org.web3j.crypto.RawTransaction in project jbpm-work-items by kiegroup.

the class EthereumUtils method deployContract.

public static String deployContract(Credentials credentials, Web3j web3j, String contractBinary, int toSendEther, boolean waitForReceipt, int sleepDuration, int attempts) throws Exception {
    BigInteger depositEtherAmountToSend = BigInteger.valueOf(toSendEther);
    RawTransaction rawTransaction = RawTransaction.createContractTransaction(getNextNonce(credentials.getAddress(), web3j), DEFAULT_GAS_PRICE, DEFAULT_GAS_LIMIT, depositEtherAmountToSend, contractBinary);
    byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
    String hexValue = Numeric.toHexString(signedMessage);
    EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).sendAsync().get();
    if (waitForReceipt) {
        TransactionReceipt transReceipt = waitForTransactionReceipt(ethSendTransaction.getTransactionHash(), sleepDuration, attempts, web3j);
        if (transReceipt != null) {
            return transReceipt.getContractAddress();
        }
    }
    // we dont have a contract address
    logger.warn("Unable to retrieve contract address.");
    return null;
}
Also used : EthSendTransaction(org.web3j.protocol.core.methods.response.EthSendTransaction) RawTransaction(org.web3j.crypto.RawTransaction) TransactionReceipt(org.web3j.protocol.core.methods.response.TransactionReceipt) EthGetTransactionReceipt(org.web3j.protocol.core.methods.response.EthGetTransactionReceipt) BigInteger(java.math.BigInteger)

Aggregations

BigInteger (java.math.BigInteger)1 RawTransaction (org.web3j.crypto.RawTransaction)1 EthGetTransactionReceipt (org.web3j.protocol.core.methods.response.EthGetTransactionReceipt)1 EthSendTransaction (org.web3j.protocol.core.methods.response.EthSendTransaction)1 TransactionReceipt (org.web3j.protocol.core.methods.response.TransactionReceipt)1