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;
}
Aggregations