Class TopicCreateTransaction

java.lang.Object
com.hedera.hashgraph.sdk.Transaction<TopicCreateTransaction>
com.hedera.hashgraph.sdk.TopicCreateTransaction

public final class TopicCreateTransaction extends Transaction<TopicCreateTransaction>
Create a topic to be used for consensus.

If an autoRenewAccount is specified, that account must also sign this transaction.

If an adminKey is specified, the adminKey must sign the transaction.

On success, the resulting TransactionReceipt contains the newly created TopicId. See Hedera Documentation See Hedera Documentation

  • Field Details

    • random

      protected static final Random random
    • maxAttempts

      @Nullable protected Integer maxAttempts
      The maximum times execution will be attempted
    • maxBackoff

      @Nullable protected Duration maxBackoff
      The maximum amount of time to wait between retries
    • minBackoff

      @Nullable protected Duration minBackoff
      The minimum amount of time to wait between retries
    • nodeAccountIds

      protected com.hedera.hashgraph.sdk.LockableList<AccountId> nodeAccountIds
      List of account IDs for nodes with which execution will be attempted.
    • nodes

      protected com.hedera.hashgraph.sdk.LockableList<com.hedera.hashgraph.sdk.Node> nodes
      List of healthy and unhealthy nodes with which execution will be attempted.
    • attemptedAllNodes

      protected boolean attemptedAllNodes
      Indicates if the request has been attempted to be sent to all nodes
    • grpcDeadline

      protected Duration grpcDeadline
      The timeout for each execution attempt
    • logger

      protected Logger logger
  • Constructor Details

    • TopicCreateTransaction

      public TopicCreateTransaction()
      Constructor.
  • Method Details

    • getTopicMemo

      public String getTopicMemo()
      Extract the topic memo.
      Returns:
      the topic memo
    • setTopicMemo

      public TopicCreateTransaction setTopicMemo(String memo)
      Set a short publicly visible memo on the new topic.
      Parameters:
      memo - The memo to be set
      Returns:
      this
    • getAdminKey

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

      public TopicCreateTransaction setAdminKey(Key adminKey)
      Set the admin key for the new topic.

      Access control for updateTopic/deleteTopic.

      Anyone can increase the topic's expirationTime regardless of the adminKey. If no adminKey is specified, updateTopic may only be used to extend the topic's expirationTime, and deleteTopic is disallowed.

      Parameters:
      adminKey - The Key to be set
      Returns:
      this
    • getSubmitKey

      @Nullable public Key getSubmitKey()
      Extract the submit key.
      Returns:
      the submit key
    • setSubmitKey

      public TopicCreateTransaction setSubmitKey(Key submitKey)
      Set the submit key for the new topic.

      Access control for submitMessage. If unspecified, no access control is performed on ConsensusService.submitMessage (all submissions are allowed).

      Parameters:
      submitKey - The Key to be set
      Returns:
      this
    • getAutoRenewPeriod

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

      public TopicCreateTransaction setAutoRenewPeriod(Duration autoRenewPeriod)
      Set the auto renew period for the new topic.

      The initial lifetime of the topic and the amount of time to attempt to extend the topic's lifetime by automatically at the topic's expirationTime, if the autoRenewAccount is configured (once autoRenew functionality is supported by HAPI).

      Parameters:
      autoRenewPeriod - The Duration to be set for auto renewal
      Returns:
      this
    • getAutoRenewAccountId

      @Nullable public AccountId getAutoRenewAccountId()
      Extract the auto renew account id.
      Returns:
      the auto renew account id
    • setAutoRenewAccountId

      public TopicCreateTransaction setAutoRenewAccountId(AccountId autoRenewAccountId)
      Set the ID of the auto renew account for the new topic.

      Optional account to be used at the topic's expirationTime to extend the life of the topic (once autoRenew functionality is supported by HAPI).

      The topic lifetime will be extended up to a maximum of the autoRenewPeriod or however long the topic can be extended using all funds on the account (whichever is the smaller duration/amount and if any extension is possible with the account's funds).

      If specified, there must be an adminKey and the autoRenewAccount must sign this transaction.

      Parameters:
      autoRenewAccountId - The AccountId to be set for auto renewal
      Returns:
      this
    • grpcDeadline

      public final Duration grpcDeadline()
      When execution is attempted, a single attempt will time out when this deadline is reached. (The SDK may subsequently retry the execution.)
      Returns:
      The timeout for each execution attempt
    • setGrpcDeadline

      public final TopicCreateTransaction setGrpcDeadline(Duration grpcDeadline)
      When execution is attempted, a single attempt will timeout when this deadline is reached. (The SDK may subsequently retry the execution.)
      Parameters:
      grpcDeadline - The timeout for each execution attempt
      Returns:
      this
    • getMaxBackoff

      public final Duration getMaxBackoff()
      The maximum amount of time to wait between retries
      Returns:
      maxBackoff
    • setMaxBackoff

      public final TopicCreateTransaction setMaxBackoff(Duration maxBackoff)
      The maximum amount of time to wait between retries. Every retry attempt will increase the wait time exponentially until it reaches this time.
      Parameters:
      maxBackoff - The maximum amount of time to wait between retries
      Returns:
      this
    • getMinBackoff

      public final Duration getMinBackoff()
      The minimum amount of time to wait between retries
      Returns:
      minBackoff
    • setMinBackoff

      public final TopicCreateTransaction setMinBackoff(Duration minBackoff)
      The minimum amount of time to wait between retries. When retrying, the delay will start at this time and increase exponentially until it reaches the maxBackoff.
      Parameters:
      minBackoff - The minimum amount of time to wait between retries
      Returns:
      this
    • getMaxRetry

      @Deprecated public final int getMaxRetry()
      Deprecated.
      Use getMaxAttempts() instead.
      Returns:
      Number of errors before execution will fail.
    • setMaxRetry

      @Deprecated public final TopicCreateTransaction setMaxRetry(int count)
      Deprecated.
      Use setMaxAttempts(int) instead.
      Parameters:
      count - Number of errors before execution will fail
      Returns:
      this
    • getMaxAttempts

      public final int getMaxAttempts()
      Get the maximum times execution will be attempted.
      Returns:
      Number of errors before execution will fail.
    • setMaxAttempts

      public final TopicCreateTransaction setMaxAttempts(int maxAttempts)
      Set the maximum times execution will be attempted.
      Parameters:
      maxAttempts - Execution will fail after this many errors.
      Returns:
      this
    • getNodeAccountIds

      @Nullable public final List<AccountId> getNodeAccountIds()
      Get the list of account IDs for nodes with which execution will be attempted.
      Returns:
      the list of account IDs
    • setRequestListener

      public final TopicCreateTransaction setRequestListener(UnaryOperator<Transaction> requestListener)
      Set a callback that will be called right before the request is sent. As input, the callback will receive the protobuf of the request, and the callback should return the request protobuf. This means the callback has an opportunity to read, copy, or modify the request that will be sent.
      Parameters:
      requestListener - The callback to use
      Returns:
      this
    • setResponseListener

      public final TopicCreateTransaction setResponseListener(UnaryOperator<TransactionResponse> responseListener)
      Set a callback that will be called right before the response is returned. As input, the callback will receive the protobuf of the response, and the callback should return the response protobuf. This means the callback has an opportunity to read, copy, or modify the response that will be read.
      Parameters:
      responseListener - The callback to use
      Returns:
      this
    • setLogger

      public TopicCreateTransaction setLogger(Logger logger)
      Set the logger
      Parameters:
      logger - the new logger
      Returns:
      this
    • execute

      Execute this transaction or query
      Parameters:
      client - The client with which this will be executed.
      Returns:
      Result of execution
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
    • execute

      public TransactionResponse execute(Client client, Duration timeout) throws TimeoutException, PrecheckStatusException
      Execute this transaction or query with a timeout
      Parameters:
      client - The client with which this will be executed.
      timeout - The timeout after which the execution attempt will be cancelled.
      Returns:
      Result of execution
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
    • executeAsync

      public CompletableFuture<TransactionResponse> executeAsync(Client client)
      Execute this transaction or query asynchronously.
      Parameters:
      client - The client with which this will be executed.
      Returns:
      Future result of execution
    • executeAsync

      public CompletableFuture<TransactionResponse> executeAsync(Client client, Duration timeout)
      Execute this transaction or query asynchronously.
      Parameters:
      client - The client with which this will be executed.
      timeout - The timeout after which the execution attempt will be cancelled.
      Returns:
      Future result of execution
    • executeAsync

      public void executeAsync(Client client, BiConsumer<TransactionResponse,Throwable> callback)
      Execute this transaction or query asynchronously.
      Parameters:
      client - The client with which this will be executed.
      callback - a BiConsumer which handles the result or error.
    • executeAsync

      public void executeAsync(Client client, Duration timeout, BiConsumer<TransactionResponse,Throwable> callback)
      Execute this transaction or query asynchronously.
      Parameters:
      client - The client with which this will be executed.
      timeout - The timeout after which the 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 this transaction or query asynchronously.
      Parameters:
      client - The client with which this will be executed.
      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 timeout, Consumer<TransactionResponse> onSuccess, Consumer<Throwable> onFailure)
      Execute this transaction or query asynchronously.
      Parameters:
      client - The client with which this will be executed.
      timeout - The timeout after which the execution attempt will be cancelled.
      onSuccess - a Consumer which consumes the result on success.
      onFailure - a Consumer which consumes the error on failure.
    • logTransaction

      protected void logTransaction(TransactionId transactionId, Client client, com.hedera.hashgraph.sdk.Node node, boolean isAsync, int attempt, @Nullable TransactionResponse response, @Nullable Throwable error)
      Logs the transaction's parameters
      Parameters:
      transactionId - the transaction's id
      client - the client that executed the transaction
      node - the node the transaction was sent to
      isAsync - whether the transaction was executed asynchronously
      attempt - the attempt number
      response - the transaction response if the transaction was successful
      error - the error if the transaction was not successful