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

The following examples show how to use org.web3j.crypto.RawTransaction#createContractTransaction() . 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: HumanStandardTokenIT.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
private String sendCreateContractTransaction(
        Credentials credentials, BigInteger initialSupply) throws Exception {
    BigInteger nonce = getNonce(credentials.getAddress());

    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.asList(
                            new Uint256(initialSupply),
                            new Utf8String("web3j tokens"),
                            new Uint8(BigInteger.TEN),
                            new Utf8String("w3j$")));

    RawTransaction rawTransaction = RawTransaction.createContractTransaction(
            nonce,
            GAS_PRICE,
            GAS_LIMIT,
            BigInteger.ZERO,
            getHumanStandardTokenBinary() + encodedConstructor);

    byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
    String hexValue = Numeric.toHexString(signedMessage);

    EthSendTransaction transactionResponse = web3j.ethSendRawTransaction(hexValue)
            .sendAsync().get();

    return transactionResponse.getTransactionHash();
}
 
Example 2
Source File: EthereumUtils.java    From jbpm-work-items with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: HumanStandardTokenIT.java    From web3j with Apache License 2.0 5 votes vote down vote up
private String sendCreateContractTransaction(Credentials credentials, BigInteger initialSupply)
        throws Exception {
    BigInteger nonce = getNonce(credentials.getAddress());

    String encodedConstructor =
            FunctionEncoder.encodeConstructor(
                    Arrays.asList(
                            new Uint256(initialSupply),
                            new Utf8String("web3j tokens"),
                            new Uint8(BigInteger.TEN),
                            new Utf8String("w3j$")));

    RawTransaction rawTransaction =
            RawTransaction.createContractTransaction(
                    nonce,
                    GAS_PRICE,
                    GAS_LIMIT,
                    BigInteger.ZERO,
                    getHumanStandardTokenBinary() + encodedConstructor);

    byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
    String hexValue = Numeric.toHexString(signedMessage);

    EthSendTransaction transactionResponse =
            web3j.ethSendRawTransaction(hexValue).sendAsync().get();

    return transactionResponse.getTransactionHash();
}
 
Example 4
Source File: CreateRawTransactionIT.java    From etherscan-explorer with GNU General Public License v3.0 4 votes vote down vote up
private static RawTransaction createSmartContractTransaction(BigInteger nonce)
        throws Exception {
    return RawTransaction.createContractTransaction(
            nonce, GAS_PRICE, GAS_LIMIT, BigInteger.ZERO, getFibonacciSolidityBinary());
}
 
Example 5
Source File: CreateRawTransactionIT.java    From web3j with Apache License 2.0 4 votes vote down vote up
private static RawTransaction createSmartContractTransaction(BigInteger nonce)
        throws Exception {
    return RawTransaction.createContractTransaction(
            nonce, GAS_PRICE, GAS_LIMIT, BigInteger.ZERO, getFibonacciSolidityBinary());
}