Java Code Examples for org.web3j.protocol.core.methods.request.Transaction#createContractTransaction()

The following examples show how to use org.web3j.protocol.core.methods.request.Transaction#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: DeployContractIT.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
private String sendTransaction() throws Exception {
    BigInteger nonce = getNonce(ALICE.getAddress());

    Transaction transaction = Transaction.createContractTransaction(
            ALICE.getAddress(),
            nonce,
            GAS_PRICE,
            GAS_LIMIT,
            BigInteger.ZERO,
            getFibonacciSolidityBinary());

    org.web3j.protocol.core.methods.response.EthSendTransaction
            transactionResponse = web3j.ethSendTransaction(transaction)
            .sendAsync().get();

    return transactionResponse.getTransactionHash();
}
 
Example 2
Source File: GreeterContractIT.java    From etherscan-explorer with GNU General Public License v3.0 6 votes vote down vote up
private String sendCreateContractTransaction() throws Exception {
    BigInteger nonce = getNonce(ALICE.getAddress());

    String encodedConstructor =
            FunctionEncoder.encodeConstructor(Collections.singletonList(new Utf8String(VALUE)));

    Transaction transaction = Transaction.createContractTransaction(
            ALICE.getAddress(),
            nonce,
            GAS_PRICE,
            GAS_LIMIT,
            BigInteger.ZERO,
            getGreeterSolidityBinary() + encodedConstructor);

    org.web3j.protocol.core.methods.response.EthSendTransaction
            transactionResponse = web3j.ethSendTransaction(transaction)
            .sendAsync().get();

    return transactionResponse.getTransactionHash();
}
 
Example 3
Source File: DeployContractIT.java    From web3j with Apache License 2.0 6 votes vote down vote up
private String sendTransaction() throws Exception {
    BigInteger nonce = getNonce(ALICE.getAddress());

    Transaction transaction =
            Transaction.createContractTransaction(
                    ALICE.getAddress(),
                    nonce,
                    GAS_PRICE,
                    GAS_LIMIT,
                    BigInteger.ZERO,
                    getFibonacciSolidityBinary());

    org.web3j.protocol.core.methods.response.EthSendTransaction transactionResponse =
            web3j.ethSendTransaction(transaction).sendAsync().get();

    return transactionResponse.getTransactionHash();
}
 
Example 4
Source File: GreeterContractIT.java    From web3j with Apache License 2.0 6 votes vote down vote up
private String sendCreateContractTransaction() throws Exception {
    BigInteger nonce = getNonce(ALICE.getAddress());

    String encodedConstructor =
            FunctionEncoder.encodeConstructor(Collections.singletonList(new Utf8String(VALUE)));

    Transaction transaction =
            Transaction.createContractTransaction(
                    ALICE.getAddress(),
                    nonce,
                    GAS_PRICE,
                    GAS_LIMIT,
                    BigInteger.ZERO,
                    getGreeterSolidityBinary() + encodedConstructor);

    org.web3j.protocol.core.methods.response.EthSendTransaction transactionResponse =
            web3j.ethSendTransaction(transaction).sendAsync().get();

    return transactionResponse.getTransactionHash();
}
 
Example 5
Source File: SmartContractAcceptanceTest.java    From ethsigner with Apache License 2.0 5 votes vote down vote up
@Test
public void invokeContract() {
  final Transaction contract =
      Transaction.createContractTransaction(
          richBenefactor().address(),
          richBenefactor().nextNonceAndIncrement(),
          GAS_PRICE,
          GAS_LIMIT,
          BigInteger.ZERO,
          SIMPLE_STORAGE_BINARY);

  final String hash = ethSigner().publicContracts().submit(contract);
  ethNode().publicContracts().awaitBlockContaining(hash);

  final String contractAddress = ethNode().publicContracts().address(hash);
  final Transaction valueBeforeChange =
      Transaction.createEthCallTransaction(
          richBenefactor().address(), contractAddress, SIMPLE_STORAGE_GET);
  final BigInteger startingValue = hex(ethSigner().publicContracts().call(valueBeforeChange));
  final Transaction changeValue =
      Transaction.createFunctionCallTransaction(
          richBenefactor().address(),
          richBenefactor().nextNonceAndIncrement(),
          GAS_PRICE,
          GAS_LIMIT,
          contractAddress,
          SIMPLE_STORAGE_SET_7);

  final String valueUpdate = ethSigner().publicContracts().submit(changeValue);
  ethNode().publicContracts().awaitBlockContaining(valueUpdate);

  final Transaction valueAfterChange =
      Transaction.createEthCallTransaction(
          richBenefactor().address(), contractAddress, SIMPLE_STORAGE_GET);
  final BigInteger endValue = hex(ethSigner().publicContracts().call(valueAfterChange));
  assertThat(endValue).isEqualTo(startingValue.add(BigInteger.valueOf(7)));
}
 
Example 6
Source File: TestnetConfig.java    From etherscan-explorer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Transaction buildTransaction() {
    return Transaction.createContractTransaction(
            validAccount(),
            BigInteger.ZERO,  // nonce
            Transaction.DEFAULT_GAS,
            validContractCode()
    );
}
 
Example 7
Source File: TestnetConfig.java    From web3j with Apache License 2.0 5 votes vote down vote up
@Override
public Transaction buildTransaction() {
    return Transaction.createContractTransaction(
            validAccount(),
            BigInteger.ZERO, // nonce
            Transaction.DEFAULT_GAS,
            validContractCode());
}