Class ContractCreateFlow

java.lang.Object
com.hedera.hashgraph.sdk.ContractCreateFlow

public class ContractCreateFlow extends Object
Start a new smart contract instance. After the instance is created, the ContractID for it is in the receipt.

The instance will exist for autoRenewPeriod seconds. When that is reached, it will renew itself for another autoRenewPeriod seconds by charging its associated cryptocurrency account (which it creates here). If it has insufficient cryptocurrency to extend that long, it will extend as long as it can. If its balance is zero, the instance will be deleted.

A smart contract instance normally enforces rules, so "the code is law". For example, an ERC-20 contract prevents a transfer from being undone without a signature by the recipient of the transfer. This is always enforced if the contract instance was created with the adminKeys being null. But for some uses, it might be desirable to create something like an ERC-20 contract that has a specific group of trusted individuals who can act as a "supreme court" with the ability to override the normal operation, when a sufficient number of them agree to do so. If adminKeys is not null, then they can sign a transaction that can change the state of the smart contract in arbitrary ways, such as to reverse a transaction that violates some standard of behavior that is not covered by the code itself. The admin keys can also be used to change the autoRenewPeriod, and change the adminKeys field itself. The API currently does not implement this ability. But it does allow the adminKeys field to be set and queried, and will in the future implement such admin abilities for any instance that has a non-null adminKeys.

If this constructor stores information, it is charged gas to store it. There is a fee in hbars to maintain that storage until the expiration time, and that fee is added as part of the transaction fee.

An entity (account, file, or smart contract instance) must be created in a particular realm. If the realmID is left null, then a new realm will be created with the given admin key. If a new realm has a null adminKey, then anyone can create/modify/delete entities in that realm. But if an admin key is given, then any transaction to create/modify/delete an entity in that realm must be signed by that key, though anyone can still call functions on smart contract instances that exist in that realm. A realm ceases to exist when everything within it has expired and no longer exists.

The current API ignores shardID, realmID, and newRealmAdminKey, and creates everything in shard 0 and realm 0, with a null key. Future versions of the API will support multiple realms and multiple shards.

The optional memo field can contain a string whose length is up to 100 bytes. That is the size after Unicode NFD then UTF-8 conversion. This field can be used to describe the smart contract. It could also be used for other purposes. One recommended purpose is to hold a hexadecimal string that is the SHA-384 hash of a PDF file containing a human-readable legal contract. Then, if the admin keys are the public keys of human arbitrators, they can use that legal document to guide their decisions during a binding arbitration tribunal, convened to consider any changes to the smart contract in the future. The memo field can only be changed using the admin keys. If there are no admin keys, then it cannot be changed after the smart contract is created.

  • Field Details

  • Constructor Details

    • ContractCreateFlow

      public ContractCreateFlow()
      Constructor
  • Method Details

    • getBytecode

      public String getBytecode()
      Extract the hex-encoded bytecode of the contract.
      Returns:
      the hex-encoded bytecode of the contract.
    • setBytecode

      public ContractCreateFlow setBytecode(String bytecode)
      Sets the bytecode of the contract in hex.
      Parameters:
      bytecode - the string to assign
      Returns:
      this
    • setBytecode

      public ContractCreateFlow setBytecode(byte[] bytecode)
      Sets the bytecode of the contract in raw bytes.
      Parameters:
      bytecode - the byte array
      Returns:
      this
    • setBytecode

      public ContractCreateFlow setBytecode(com.google.protobuf.ByteString bytecode)
      Sets the bytecode of the contract in raw bytes.
      Parameters:
      bytecode - the byte string
      Returns:
      the contract in raw bytes
    • getMaxChunks

      @Nullable public Integer getMaxChunks()
      Get the maximum number of chunks
      Returns:
      the maxChunks
    • setMaxChunks

      public ContractCreateFlow setMaxChunks(int maxChunks)
      Set the maximal number of chunks
      Parameters:
      maxChunks - the maximum number of chunks
      Returns:
      this
    • getAdminKey

      @Nullable public Key getAdminKey()
      Extract the admin key.
      Returns:
      the admin key
    • setAdminKey

      public ContractCreateFlow setAdminKey(Key adminKey)
      Sets the state of the instance and its fields can be modified arbitrarily if this key signs a transaction to modify it. If this is null, then such modifications are not possible, and there is no administrator that can override the normal operation of this smart contract instance. Note that if it is created with no admin keys, then there is no administrator to authorize changing the admin keys, so there can never be any admin keys for that instance.
      Parameters:
      adminKey - The Key to be set
      Returns:
      this
    • getGas

      public long getGas()
      Extract the gas.
      Returns:
      the gas
    • setGas

      public ContractCreateFlow setGas(long gas)
      Sets the gas to run the constructor.
      Parameters:
      gas - The long to be set as gas
      Returns:
      this
    • getInitialBalance

      public Hbar getInitialBalance()
      Extract the initial balance in hbar.
      Returns:
      the initial balance in hbar
    • setInitialBalance

      public ContractCreateFlow setInitialBalance(Hbar initialBalance)
      Sets the initial number of hbars to put into the cryptocurrency account associated with and owned by the smart contract.
      Parameters:
      initialBalance - The Hbar to be set as the initial balance
      Returns:
      this
    • getProxyAccountId

      @Nullable @Deprecated public AccountId getProxyAccountId()
      Deprecated.
      with no replacement

      Extract the proxy account id.

      Returns:
      the proxy account id
    • setProxyAccountId

      @Deprecated public ContractCreateFlow setProxyAccountId(AccountId proxyAccountId)
      Deprecated.
      with no replacement

      Sets the ID of the account to which this account is proxy staked.

      If proxyAccountID is null, or is an invalid account, or is an account that isn't a node, then this account is automatically proxy staked to a node chosen by the network, but without earning payments.

      If the proxyAccountID account refuses to accept proxy staking , or if it is not currently running a node, then it will behave as if proxyAccountID was null.

      Parameters:
      proxyAccountId - The AccountId to be set
      Returns:
      this
    • getMaxAutomaticTokenAssociations

      public int getMaxAutomaticTokenAssociations()
      The maximum number of tokens that an Account can be implicitly associated with. Defaults to 0 and up to a maximum value of 1000.
      Returns:
      The maxAutomaticTokenAssociations.
    • setMaxAutomaticTokenAssociations

      public ContractCreateFlow setMaxAutomaticTokenAssociations(int maxAutomaticTokenAssociations)
      The maximum number of tokens that an Account can be implicitly associated with. Defaults to 0 and up to a maximum value of 1000.
      Parameters:
      maxAutomaticTokenAssociations - The maxAutomaticTokenAssociations to set
      Returns:
      this
    • getAutoRenewPeriod

      @Nullable public Duration getAutoRenewPeriod()
      Extract the auto renew period.
      Returns:
      the auto renew period
    • setAutoRenewPeriod

      public ContractCreateFlow setAutoRenewPeriod(Duration autoRenewPeriod)
      Sets the period that the instance will charge its account every this many seconds to renew.
      Parameters:
      autoRenewPeriod - The Duration to be set for auto renewal
      Returns:
      this
    • getAutoRenewAccountId

      @Nullable public AccountId getAutoRenewAccountId()
      Get the account ID which will be charged for renewing this account
      Returns:
      the auto-renewal account id
    • setAutoRenewAccountId

      public ContractCreateFlow setAutoRenewAccountId(AccountId autoRenewAccountId)
      Set the account ID which will be charged for renewing this account
      Parameters:
      autoRenewAccountId - the autoRenewAccountId to set
      Returns:
      this
    • getConstructorParameters

      public com.google.protobuf.ByteString getConstructorParameters()
      Extract the byte string representation.
      Returns:
      the byte string representation
    • setConstructorParameters

      public ContractCreateFlow setConstructorParameters(byte[] constructorParameters)
      Sets the constructor parameters as their raw bytes.

      Use this instead of setConstructorParameters(ContractFunctionParameters) if you have already pre-encoded a solidity function call.

      Parameters:
      constructorParameters - The constructor parameters
      Returns:
      this
    • setConstructorParameters

      public ContractCreateFlow setConstructorParameters(ContractFunctionParameters constructorParameters)
      Sets the parameters to pass to the constructor.
      Parameters:
      constructorParameters - The contructor parameters
      Returns:
      this
    • getContractMemo

      public String getContractMemo()
      Extract the contract memo.
      Returns:
      the contract memo
    • setContractMemo

      public ContractCreateFlow setContractMemo(String memo)
      Sets the memo to be associated with this contract.
      Parameters:
      memo - The String to be set as the memo
      Returns:
      this
    • getStakedAccountId

      @Nullable public AccountId getStakedAccountId()
      ID of the account to which this contract will stake
      Returns:
      ID of the account to which this contract will stake.
    • setStakedAccountId

      public ContractCreateFlow setStakedAccountId(@Nullable AccountId stakedAccountId)
      Set the account to which this contract will stake
      Parameters:
      stakedAccountId - ID of the account to which this contract will stake.
      Returns:
      this
    • getStakedNodeId

      @Nullable public Long getStakedNodeId()
      The node to which this contract will stake
      Returns:
      ID of the node this contract will be staked to.
    • setStakedNodeId

      public ContractCreateFlow setStakedNodeId(@Nullable Long stakedNodeId)
      Set the node to which this contract will stake
      Parameters:
      stakedNodeId - ID of the node this contract will be staked to.
      Returns:
      this
    • getDeclineStakingReward

      public boolean getDeclineStakingReward()
      If true, the contract declines receiving a staking reward. The default value is false.
      Returns:
      If true, the contract declines receiving a staking reward. The default value is false.
    • setDeclineStakingReward

      public ContractCreateFlow setDeclineStakingReward(boolean declineStakingReward)
      If true, the contract declines receiving a staking reward. The default value is false.
      Parameters:
      declineStakingReward - - If true, the contract declines receiving a staking reward. The default value is false.
      Returns:
      this
    • getNodeAccountIds

      @Nullable public List<AccountId> getNodeAccountIds()
      Extract the list of node account id's.
      Returns:
      the list of node account id's
    • setNodeAccountIds

      public ContractCreateFlow setNodeAccountIds(List<AccountId> nodeAccountIds)
      Set the account IDs of the nodes that this transaction will be submitted to.

      Providing an explicit node account ID interferes with client-side load balancing of the network. By default, the SDK will pre-generate a transaction for 1/3 of the nodes on the network. If a node is down, busy, or otherwise reports a fatal error, the SDK will try again with a different node.

      Parameters:
      nodeAccountIds - The list of node AccountIds to be set
      Returns:
      this
    • freezeWith

      public ContractCreateFlow freezeWith(Client client)
      Set the client that this transaction will be frozen with.
      Parameters:
      client - the client with the transaction to execute
      Returns:
      this
    • sign

      public ContractCreateFlow sign(PrivateKey privateKey)
      Set the private key that this transaction will be signed with.
      Parameters:
      privateKey - the private key used for signing
      Returns:
      this
    • signWith

      public ContractCreateFlow signWith(PublicKey publicKey, UnaryOperator<byte[]> transactionSigner)
      Set the public key and key list that this transaction will be signed with.
      Parameters:
      publicKey - the public key
      transactionSigner - the key list
      Returns:
      this
    • signWithOperator

      public ContractCreateFlow signWithOperator(Client client)
      Set the operator that this transaction will be signed with.
      Parameters:
      client - the client with the transaction to execute
      Returns:
      this
    • createTransactionReceiptQuery

      TransactionReceiptQuery createTransactionReceiptQuery(TransactionResponse response)
      Create a new transaction receipt query.
      Parameters:
      response - the transaction response
      Returns:
      the receipt query
    • execute

      Execute the transactions in the flow with the passed in client.
      Parameters:
      client - the client with the transaction to execute
      Returns:
      the response
      Throws:
      PrecheckStatusException - when the precheck fails
      TimeoutException - when the transaction times out
    • execute

      public TransactionResponse execute(Client client, Duration timeoutPerTransaction) throws PrecheckStatusException, TimeoutException
      Execute the transactions in the flow with the passed in client.
      Parameters:
      client - the client with the transaction to execute
      timeoutPerTransaction - The timeout after which each transaction's execution attempt will be cancelled.
      Returns:
      the response
      Throws:
      PrecheckStatusException - when the precheck fails
      TimeoutException - when the transaction times out
    • executeAsync

      public CompletableFuture<TransactionResponse> executeAsync(Client client)
      Execute the transactions in the flow with the passed in client asynchronously.
      Parameters:
      client - the client with the transaction to execute
      Returns:
      the response
    • executeAsync

      public CompletableFuture<TransactionResponse> executeAsync(Client client, Duration timeoutPerTransaction)
      Execute the transactions in the flow with the passed in client asynchronously.
      Parameters:
      client - the client with the transaction to execute
      timeoutPerTransaction - The timeout after which each transaction's execution attempt will be cancelled.
      Returns:
      the response
    • executeAsync

      public void executeAsync(Client client, BiConsumer<TransactionResponse,Throwable> callback)
      Execute the transactions in the flow with the passed in client asynchronously.
      Parameters:
      client - the client with the transaction to execute
      callback - a BiConsumer which handles the result or error.
    • executeAsync

      public void executeAsync(Client client, Duration timeoutPerTransaction, BiConsumer<TransactionResponse,Throwable> callback)
      Execute the transactions in the flow with the passed in client asynchronously.
      Parameters:
      client - the client with the transaction to execute
      timeoutPerTransaction - The timeout after which each transaction's execution attempt will be cancelled.
      callback - a BiConsumer which handles the result or error.
    • executeAsync

      public void executeAsync(Client client, Consumer<TransactionResponse> onSuccess, Consumer<Throwable> onFailure)
      Execute the transactions in the flow with the passed in client asynchronously.
      Parameters:
      client - the client with the transaction to execute
      onSuccess - a Consumer which consumes the result on success.
      onFailure - a Consumer which consumes the error on failure.
    • executeAsync

      public void executeAsync(Client client, Duration timeoutPerTransaction, Consumer<TransactionResponse> onSuccess, Consumer<Throwable> onFailure)
      Execute the transactions in the flow with the passed in client asynchronously.
      Parameters:
      client - the client with the transaction to execute
      timeoutPerTransaction - The timeout after which each transaction's execution attempt will be cancelled.
      onSuccess - a Consumer which consumes the result on success.
      onFailure - a Consumer which consumes the error on failure.