Class Client

java.lang.Object
com.hedera.hashgraph.sdk.Client
All Implemented Interfaces:
AutoCloseable

public final class Client extends Object implements AutoCloseable
Managed client for use on the Hedera Hashgraph network.
  • Field Details

    • DEFAULT_MAX_ATTEMPTS

      static final int DEFAULT_MAX_ATTEMPTS
      See Also:
    • DEFAULT_MAX_BACKOFF

      static final Duration DEFAULT_MAX_BACKOFF
    • DEFAULT_MIN_BACKOFF

      static final Duration DEFAULT_MIN_BACKOFF
    • DEFAULT_MAX_NODE_BACKOFF

      static final Duration DEFAULT_MAX_NODE_BACKOFF
    • DEFAULT_MIN_NODE_BACKOFF

      static final Duration DEFAULT_MIN_NODE_BACKOFF
    • DEFAULT_CLOSE_TIMEOUT

      static final Duration DEFAULT_CLOSE_TIMEOUT
    • DEFAULT_REQUEST_TIMEOUT

      static final Duration DEFAULT_REQUEST_TIMEOUT
    • DEFAULT_GRPC_DEADLINE

      static final Duration DEFAULT_GRPC_DEADLINE
    • DEFAULT_NETWORK_UPDATE_PERIOD

      static final Duration DEFAULT_NETWORK_UPDATE_PERIOD
    • NETWORK_UPDATE_INITIAL_DELAY

      static final Duration NETWORK_UPDATE_INITIAL_DELAY
    • executor

      final ExecutorService executor
    • defaultMaxTransactionFee

      @Nullable Hbar defaultMaxTransactionFee
    • defaultMaxQueryPayment

      Hbar defaultMaxQueryPayment
    • network

      Network network
    • mirrorNetwork

      MirrorNetwork mirrorNetwork
  • Constructor Details

    • Client

      Client(ExecutorService executor, Network network, MirrorNetwork mirrorNetwork, @Nullable Duration networkUpdateInitialDelay, boolean shouldShutdownExecutor, @Nullable Duration networkUpdatePeriod, long shard, long realm)
      Constructor.
      Parameters:
      executor - the executor
      network - the network
      mirrorNetwork - the mirror network
      shouldShutdownExecutor -
  • Method Details

    • createExecutor

      static ExecutorService createExecutor()
      Extract the executor.
      Returns:
      the executor service
    • forNetwork

      public static Client forNetwork(Map<String,AccountId> networkMap, ExecutorService executor)
      Construct a client given a set of nodes. It is the responsibility of the caller to ensure that all nodes in the map are part of the same Hedera network. Failure to do so will result in undefined behavior. The client will load balance all requests to Hedera using a simple round-robin scheme to chose nodes to send transactions to. For one transaction, at most 1/3 of the nodes will be tried.
      Parameters:
      networkMap - the map of node IDs to node addresses that make up the network.
      executor - runs the grpc requests asynchronously.
      Returns:
      Client
    • forNetwork

      public static Client forNetwork(Map<String,AccountId> networkMap)
      Construct a client given a set of nodes.

      It is the responsibility of the caller to ensure that all nodes in the map are part of the same Hedera network. Failure to do so will result in undefined behavior.

      The client will load balance all requests to Hedera using a simple round-robin scheme to chose nodes to send transactions to. For one transaction, at most 1/3 of the nodes will be tried.

      Parameters:
      networkMap - the map of node IDs to node addresses that make up the network.
      Returns:
      Client
    • forMirrorNetwork

      public static Client forMirrorNetwork(List<String> mirrorNetworkList) throws InterruptedException, TimeoutException
      Set up the client from selected mirror network. Using default `0` values for realm and shard for retrieving addressBookFileId
      Parameters:
      mirrorNetworkList -
      Returns:
      Throws:
      InterruptedException
      TimeoutException
    • forMirrorNetwork

      public static Client forMirrorNetwork(List<String> mirrorNetworkList, long shard, long realm) throws InterruptedException, TimeoutException
      Set up the client from selected mirror network and given realm and shard
      Parameters:
      mirrorNetworkList -
      shard -
      realm -
      Returns:
      Throws:
      InterruptedException
      TimeoutException
    • forName

      public static Client forName(String name)
      Set up the client for the selected network.
      Parameters:
      name - the selected network
      Returns:
      the configured client
    • forMainnet

      public static Client forMainnet(ExecutorService executor)
      Construct a Hedera client pre-configured for Mainnet access.
      Parameters:
      executor - runs the grpc requests asynchronously.
      Returns:
      Client
    • forTestnet

      public static Client forTestnet(ExecutorService executor)
      Construct a Hedera client pre-configured for Testnet access.
      Parameters:
      executor - runs the grpc requests asynchronously.
      Returns:
      Client
    • forPreviewnet

      public static Client forPreviewnet(ExecutorService executor)
      Construct a Hedera client pre-configured for Preview Testnet nodes.
      Parameters:
      executor - runs the grpc requests asynchronously.
      Returns:
      Client
    • forMainnet

      public static Client forMainnet()
      Construct a Hedera client pre-configured for Mainnet access.
      Returns:
      Client
    • forTestnet

      public static Client forTestnet()
      Construct a Hedera client pre-configured for Testnet access.
      Returns:
      Client
    • forPreviewnet

      public static Client forPreviewnet()
      Construct a Hedera client pre-configured for Preview Testnet nodes.
      Returns:
      Client
    • fromConfig

      public static Client fromConfig(String json) throws Exception
      Configure a client based off the given JSON string.
      Parameters:
      json - The json string containing the client configuration
      Returns:
      Client
      Throws:
      Exception - if the config is incorrect
    • fromConfig

      public static Client fromConfig(Reader json) throws Exception
      Configure a client based off the given JSON reader.
      Parameters:
      json - The Reader containing the client configuration
      Returns:
      Client
      Throws:
      Exception - if the config is incorrect
    • fromConfigFile

      public static Client fromConfigFile(String fileName) throws Exception
      Configure a client based on a JSON file at the given path.
      Parameters:
      fileName - The string containing the file path
      Returns:
      Client
      Throws:
      IOException - if IO operations fail
      Exception
    • fromConfigFile

      public static Client fromConfigFile(File file) throws Exception
      Configure a client based on a JSON file.
      Parameters:
      file - The file containing the client configuration
      Returns:
      Client
      Throws:
      IOException - if IO operations fail
      Exception
    • getMirrorNetwork

      public List<String> getMirrorNetwork()
      Extract the mirror network node list.
      Returns:
      the list of mirror nodes
    • getMirrorRestBaseUrl

      public String getMirrorRestBaseUrl()
      Build the REST base URL for the next healthy mirror node. Returns a string like `https://host[:port]/api/v1`. If the selected mirror node is a local host (localhost/127.0.0.1) returns `http://localhost:{5551|8545}/api/v1`.
    • setMirrorNetwork

      public Client setMirrorNetwork(List<String> network) throws InterruptedException
      Set the mirror network nodes.
      Parameters:
      network - list of network nodes
      Returns:
      this
      Throws:
      InterruptedException - when a thread is interrupted while it's waiting, sleeping, or otherwise occupied
    • trackSubscription

      void trackSubscription(SubscriptionHandle subscriptionHandle)
    • untrackSubscription

      void untrackSubscription(SubscriptionHandle subscriptionHandle)
    • setNetworkFromAddressBook

      public Client setNetworkFromAddressBook(NodeAddressBook addressBook) throws InterruptedException, TimeoutException
      Replace all nodes in this Client with the nodes in the Address Book and update the address book if necessary.
      Parameters:
      addressBook - A list of nodes and their metadata
      Returns:
      this
      Throws:
      InterruptedException
      TimeoutException
    • getNetwork

      public Map<String,AccountId> getNetwork()
      Extract the network.
      Returns:
      the client's network
    • setNetwork

      public Client setNetwork(Map<String,AccountId> network) throws InterruptedException, TimeoutException
      Replace all nodes in this Client with a new set of nodes (e.g. for an Address Book update).
      Parameters:
      network - a map of node account ID to node URL.
      Returns:
      this for fluent API usage.
      Throws:
      TimeoutException - when shutting down nodes
      InterruptedException - when a thread is interrupted while it's waiting, sleeping, or otherwise occupied
    • setMirrorTransportSecurity

      @Deprecated public Client setMirrorTransportSecurity(boolean transportSecurity)
      Deprecated.
      Mirror nodes can only be accessed using TLS
      Set if transport security should be used to connect to mirror nodes.
      If transport security is enabled all connections to mirror nodes will use TLS.
      Parameters:
      transportSecurity - - enable or disable transport security for mirror nodes
      Returns:
      this for fluent API usage.
    • isTransportSecurity

      public boolean isTransportSecurity()
      Is tls enabled for consensus nodes.
      Returns:
      is tls enabled
    • setTransportSecurity

      public Client setTransportSecurity(boolean transportSecurity) throws InterruptedException
      Set if transport security should be used to connect to consensus nodes.
      If transport security is enabled all connections to consensus nodes will use TLS, and the server's certificate hash will be compared to the hash stored in the NodeAddressBook for the given network.
      *Note*: If transport security is enabled, but isVerifyCertificates() is disabled then server certificates will not be verified.
      Parameters:
      transportSecurity - enable or disable transport security for consensus nodes
      Returns:
      this for fluent API usage.
      Throws:
      InterruptedException - when a thread is interrupted while it's waiting, sleeping, or otherwise occupied
    • mirrorIsTransportSecurity

      public boolean mirrorIsTransportSecurity()
      Is tls enabled for mirror nodes.
      Returns:
      is tls enabled
    • isVerifyCertificates

      public boolean isVerifyCertificates()
      Is certificate verification enabled.
      Returns:
      is certificate verification enabled
    • setVerifyCertificates

      public Client setVerifyCertificates(boolean verifyCertificates)
      Set if server certificates should be verified against an existing address book
      Parameters:
      verifyCertificates - - enable or disable certificate verification
      Returns:
      this
    • ping

      public Void ping(AccountId nodeAccountId) throws PrecheckStatusException, TimeoutException
      Send a ping to the given node.
      Parameters:
      nodeAccountId - Account ID of the node to ping
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
    • ping

      public Void ping(AccountId nodeAccountId, Duration timeout) throws PrecheckStatusException, TimeoutException
      Send a ping to the given node.
      Parameters:
      nodeAccountId - Account ID of the node to ping
      timeout - The timeout after which the execution attempt will be cancelled.
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
    • pingAsync

      public CompletableFuture<Void> pingAsync(AccountId nodeAccountId)
      Send a ping to the given node asynchronously.
      Parameters:
      nodeAccountId - Account ID of the node to ping
      Returns:
      an empty future that throws exception if there was an error
    • pingAsync

      public CompletableFuture<Void> pingAsync(AccountId nodeAccountId, Duration timeout)
      Send a ping to the given node asynchronously.
      Parameters:
      nodeAccountId - Account ID of the node to ping
      timeout - The timeout after which the execution attempt will be cancelled.
      Returns:
      an empty future that throws exception if there was an error
    • pingAsync

      public void pingAsync(AccountId nodeAccountId, BiConsumer<Void,Throwable> callback)
      Send a ping to the given node asynchronously.
      Parameters:
      nodeAccountId - Account ID of the node to ping
      callback - a BiConsumer which handles the result or error.
    • pingAsync

      public void pingAsync(AccountId nodeAccountId, Duration timeout, BiConsumer<Void,Throwable> callback)
      Send a ping to the given node asynchronously.
      Parameters:
      nodeAccountId - Account ID of the node to ping
      timeout - The timeout after which the execution attempt will be cancelled.
      callback - a BiConsumer which handles the result or error.
    • pingAsync

      public void pingAsync(AccountId nodeAccountId, Consumer<Void> onSuccess, Consumer<Throwable> onFailure)
      Send a ping to the given node asynchronously.
      Parameters:
      nodeAccountId - Account ID of the node to ping
      onSuccess - a Consumer which consumes the result on success.
      onFailure - a Consumer which consumes the error on failure.
    • pingAsync

      public void pingAsync(AccountId nodeAccountId, Duration timeout, Consumer<Void> onSuccess, Consumer<Throwable> onFailure)
      Send a ping to the given node asynchronously.
      Parameters:
      nodeAccountId - Account ID of the node to ping
      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.
    • pingAll

      public Void pingAll() throws PrecheckStatusException, TimeoutException
      Sends pings to all nodes in the client's network. Combines well with setMaxAttempts(1) to remove all dead nodes from the network.
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
    • pingAll

      public Void pingAll(Duration timeoutPerPing) throws PrecheckStatusException, TimeoutException
      Sends pings to all nodes in the client's network. Combines well with setMaxAttempts(1) to remove all dead nodes from the network.
      Parameters:
      timeoutPerPing - The timeout after which each execution attempt will be cancelled.
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
    • pingAllAsync

      public CompletableFuture<Void> pingAllAsync()
      Sends pings to all nodes in the client's network asynchronously. Combines well with setMaxAttempts(1) to remove all dead nodes from the network.
      Returns:
      an empty future that throws exception if there was an error
    • pingAllAsync

      public CompletableFuture<Void> pingAllAsync(Duration timeoutPerPing)
      Sends pings to all nodes in the client's network asynchronously. Combines well with setMaxAttempts(1) to remove all dead nodes from the network.
      Parameters:
      timeoutPerPing - The timeout after which each execution attempt will be cancelled.
      Returns:
      an empty future that throws exception if there was an error
    • pingAllAsync

      public void pingAllAsync(BiConsumer<Void,Throwable> callback)
      Sends pings to all nodes in the client's network asynchronously. Combines well with setMaxAttempts(1) to remove all dead nodes from the network.
      Parameters:
      callback - a BiConsumer which handles the result or error.
    • pingAllAsync

      public void pingAllAsync(Duration timeoutPerPing, BiConsumer<Void,Throwable> callback)
      Sends pings to all nodes in the client's network asynchronously. Combines well with setMaxAttempts(1) to remove all dead nodes from the network.
      Parameters:
      timeoutPerPing - The timeout after which each execution attempt will be cancelled.
      callback - a BiConsumer which handles the result or error.
    • pingAllAsync

      public void pingAllAsync(Consumer<Void> onSuccess, Consumer<Throwable> onFailure)
      Sends pings to all nodes in the client's network asynchronously. Combines well with setMaxAttempts(1) to remove all dead nodes from the network.
      Parameters:
      onSuccess - a Consumer which consumes the result on success.
      onFailure - a Consumer which consumes the error on failure.
    • pingAllAsync

      public void pingAllAsync(Duration timeoutPerPing, Consumer<Void> onSuccess, Consumer<Throwable> onFailure)
      Sends pings to all nodes in the client's network asynchronously. Combines well with setMaxAttempts(1) to remove all dead nodes from the network.
      Parameters:
      timeoutPerPing - The timeout after which each execution attempt will be cancelled.
      onSuccess - a Consumer which consumes the result on success.
      onFailure - a Consumer which consumes the error on failure.
    • setOperator

      public Client setOperator(AccountId accountId, PrivateKey privateKey)
      Set the account that will, by default, be paying for transactions and queries built with this client.

      The operator account ID is used to generate the default transaction ID for all transactions executed with this client.

      The operator private key is used to sign all transactions executed by this client.

      Parameters:
      accountId - The AccountId of the operator
      privateKey - The PrivateKey of the operator
      Returns:
      this
    • setOperatorWith

      public Client setOperatorWith(AccountId accountId, PublicKey publicKey, UnaryOperator<byte[]> transactionSigner)
      Sets the account that will, by default, by paying for transactions and queries built with this client.

      The operator account ID is used to generate a default transaction ID for all transactions executed with this client.

      The `transactionSigner` is invoked to sign all transactions executed by this client.

      Parameters:
      accountId - The AccountId of the operator
      publicKey - The PrivateKey of the operator
      transactionSigner - The signer for the operator
      Returns:
      this
    • getNetworkName

      @Nullable @Deprecated public NetworkName getNetworkName()
      Deprecated.
      use getLedgerId() instead
      Current name of the network; corresponds to ledger ID in entity ID checksum calculations.
      Returns:
      the network name
    • setNetworkName

      @Deprecated public Client setNetworkName(@Nullable NetworkName networkName)
      Deprecated.
      Set the network name to a particular value. Useful when constructing a network which is a subset of an existing known network.
      Parameters:
      networkName - the desired network
      Returns:
      this
    • getLedgerId

      @Nullable public LedgerId getLedgerId()
      Current LedgerId of the network; corresponds to ledger ID in entity ID checksum calculations.
      Returns:
      the ledger id
    • setLedgerId

      public Client setLedgerId(@Nullable LedgerId ledgerId)
      Set the LedgerId to a particular value. Useful when constructing a network which is a subset of an existing known network.
      Parameters:
      ledgerId - the desired ledger id
      Returns:
      this
    • getMaxAttempts

      public int getMaxAttempts()
      Max number of attempts a request executed with this client will do.
      Returns:
      the maximus attempts
    • setMaxAttempts

      public Client setMaxAttempts(int maxAttempts)
      Set the max number of attempts a request executed with this client will do.
      Parameters:
      maxAttempts - the desired max attempts
      Returns:
      this
    • getMaxBackoff

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

      public Client 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 Duration getMinBackoff()
      The minimum amount of time to wait between retries
      Returns:
      minBackoff
    • setMinBackoff

      public Client 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
    • getMaxNodeAttempts

      public int getMaxNodeAttempts()
      Max number of times any node in the network can receive a bad gRPC status before being removed from the network.
      Returns:
      the maximum node attempts
    • setMaxNodeAttempts

      public Client setMaxNodeAttempts(int maxNodeAttempts)
      Set the max number of times any node in the network can receive a bad gRPC status before being removed from the network.
      Parameters:
      maxNodeAttempts - the desired minimum attempts
      Returns:
      this
    • getNodeWaitTime

      @Deprecated public Duration getNodeWaitTime()
      Deprecated.
      - Use getNodeMaxBackoff() instead
      The minimum backoff time for any node in the network.
      Returns:
      the wait time
    • setNodeWaitTime

      @Deprecated public Client setNodeWaitTime(Duration nodeWaitTime)
      Deprecated.
      - Use setNodeMinBackoff(Duration) ()} instead
      Set the minimum backoff time for any node in the network.
      Parameters:
      nodeWaitTime - the wait time
      Returns:
      the updated client
    • getNodeMinBackoff

      public Duration getNodeMinBackoff()
      The minimum backoff time for any node in the network.
      Returns:
      the minimum backoff time
    • setNodeMinBackoff

      public Client setNodeMinBackoff(Duration minBackoff)
      Set the minimum backoff time for any node in the network.
      Parameters:
      minBackoff - the desired minimum backoff time
      Returns:
      this
    • getNodeMaxBackoff

      public Duration getNodeMaxBackoff()
      The maximum backoff time for any node in the network.
      Returns:
      the maximum node backoff time
    • setNodeMaxBackoff

      public Client setNodeMaxBackoff(Duration maxBackoff)
      Set the maximum backoff time for any node in the network.
      Parameters:
      maxBackoff - the desired max backoff time
      Returns:
      this
    • getMinNodeReadmitTime

      public Duration getMinNodeReadmitTime()
      Extract the minimum node readmit time.
      Returns:
      the minimum node readmit time
    • setMinNodeReadmitTime

      public Client setMinNodeReadmitTime(Duration minNodeReadmitTime)
      Assign the minimum node readmit time.
      Parameters:
      minNodeReadmitTime - the requested duration
      Returns:
      this
    • getMaxNodeReadmitTime

      public Duration getMaxNodeReadmitTime()
      Extract the node readmit time.
      Returns:
      the maximum node readmit time
    • setMaxNodeReadmitTime

      public Client setMaxNodeReadmitTime(Duration maxNodeReadmitTime)
      Assign the maximum node readmit time.
      Parameters:
      maxNodeReadmitTime - the maximum node readmit time
      Returns:
      this
    • setMaxNodesPerTransaction

      public Client setMaxNodesPerTransaction(int maxNodesPerTransaction)
      Set the max amount of nodes that will be chosen per request. By default, the request will use 1/3rd the network nodes per request.
      Parameters:
      maxNodesPerTransaction - the desired number of nodes
      Returns:
      this
    • setAutoValidateChecksums

      public Client setAutoValidateChecksums(boolean value)
      Enable or disable automatic entity ID checksum validation.
      Parameters:
      value - the desired value
      Returns:
      this
    • isAutoValidateChecksumsEnabled

      public boolean isAutoValidateChecksumsEnabled()
      Is automatic entity ID checksum validation enabled.
      Returns:
      is validation enabled
    • getOperatorAccountId

      @Nullable public AccountId getOperatorAccountId()
      Get the ID of the operator. Useful when the client was constructed from file.
      Returns:
      {AccountId}
    • getOperatorPublicKey

      @Nullable public PublicKey getOperatorPublicKey()
      Get the key of the operator. Useful when the client was constructed from file.
      Returns:
      {PublicKey}
    • getDefaultMaxTransactionFee

      @Nullable public Hbar getDefaultMaxTransactionFee()
      The default maximum fee used for transactions.
      Returns:
      the max transaction fee
    • setDefaultMaxTransactionFee

      public Client setDefaultMaxTransactionFee(Hbar defaultMaxTransactionFee)
      Set the maximum fee to be paid for transactions executed by this client.

      Because transaction fees are always maximums, this will simply add a call to Transaction.setMaxTransactionFee(Hbar) on every new transaction. The actual fee assessed for a given transaction may be less than this value, but never greater.

      Parameters:
      defaultMaxTransactionFee - The Hbar to be set
      Returns:
      this
    • setMaxTransactionFee

      @Deprecated public Client setMaxTransactionFee(Hbar maxTransactionFee)
      Deprecated.
      Set the maximum fee to be paid for transactions executed by this client.

      Because transaction fees are always maximums, this will simply add a call to Transaction.setMaxTransactionFee(Hbar) on every new transaction. The actual fee assessed for a given transaction may be less than this value, but never greater.

      Parameters:
      maxTransactionFee - The Hbar to be set
      Returns:
      this
    • getDefaultMaxQueryPayment

      public Hbar getDefaultMaxQueryPayment()
      Extract the maximum query payment.
      Returns:
      the default maximum query payment
    • setDefaultMaxQueryPayment

      public Client setDefaultMaxQueryPayment(Hbar defaultMaxQueryPayment)
      Set the maximum default payment allowable for queries.

      When a query is executed without an explicit Query.setQueryPayment(Hbar) call, the client will first request the cost of the given query from the node it will be submitted to and attach a payment for that amount from the operator account on the client.

      If the returned value is greater than this value, a MaxQueryPaymentExceededException will be thrown from Executable.execute(Client) or returned in the second callback of Executable.executeAsync(Client, Consumer, Consumer).

      Set to 0 to disable automatic implicit payments.

      Parameters:
      defaultMaxQueryPayment - The Hbar to be set
      Returns:
      this
    • setMaxQueryPayment

      @Deprecated public Client setMaxQueryPayment(Hbar maxQueryPayment)
      Deprecated.
      Parameters:
      maxQueryPayment - The Hbar to be set
      Returns:
      this
    • getDefaultRegenerateTransactionId

      public boolean getDefaultRegenerateTransactionId()
      Should the transaction id be regenerated?
      Returns:
      the default regenerate transaction id
    • isAllowReceiptNodeFailover

      public boolean isAllowReceiptNodeFailover()
      Should node failover be enabled
      Returns:
      the node failover mode
    • setDefaultRegenerateTransactionId

      public Client setDefaultRegenerateTransactionId(boolean regenerateTransactionId)
      Assign the default regenerate transaction id.
      Parameters:
      regenerateTransactionId - should there be a regenerated transaction id
      Returns:
      this
    • setAllowReceiptNodeFailover

      public Client setAllowReceiptNodeFailover(boolean allowReceiptNodeFailover)
      Enable or disable receipt query failover to other nodes when the submitting node is unresponsive. When enabled, receipt queries will start with the submitting node but can fail over to other nodes in the network if needed. Default is `false` to preserve existing behavior where receipt queries are pinned to the submitting node only.
      Parameters:
      allowReceiptNodeFailover - should node failover be enabled
      Returns:
      this
    • getRequestTimeout

      public Duration getRequestTimeout()
      Maximum amount of time a request can run
      Returns:
      the timeout value
    • setRequestTimeout

      public Client setRequestTimeout(Duration requestTimeout)
      Set the maximum amount of time a request can run. Used only in async variants of methods.
      Parameters:
      requestTimeout - the timeout value
      Returns:
      this
    • getCloseTimeout

      public Duration getCloseTimeout()
      Maximum amount of time closing a network can take.
      Returns:
      the timeout value
    • setCloseTimeout

      public Client setCloseTimeout(Duration closeTimeout)
      Set the maximum amount of time closing a network can take.
      Parameters:
      closeTimeout - the timeout value
      Returns:
      this
    • getGrpcDeadline

      public Duration getGrpcDeadline()
      Maximum amount of time a gRPC request can run
      Returns:
      the gRPC deadline value
    • setGrpcDeadline

      public Client setGrpcDeadline(Duration grpcDeadline)
      Set the maximum amount of time a gRPC request can run.
      Parameters:
      grpcDeadline - the gRPC deadline value
      Returns:
      this
    • getOperator

      @Nullable Client.Operator getOperator()
      Extract the operator.
      Returns:
      the operator
    • getNetworkUpdatePeriod

      @Nullable public Duration getNetworkUpdatePeriod()
      Get the period for updating the Address Book
      Returns:
      the networkUpdatePeriod
    • setNetworkUpdatePeriod

      public Client setNetworkUpdatePeriod(Duration networkUpdatePeriod)
      Set the period for updating the Address Book

      Note: This method requires API level 33 or higher. It will not work on devices running API versions below 31 because it uses features introduced in API level 31 (Android 12).

      *
      Parameters:
      networkUpdatePeriod - the period for updating the Address Book
      Returns:
      this
    • updateNetworkFromAddressBook

      public Client updateNetworkFromAddressBook()
      Trigger an immediate address book update to refresh the client's network with the latest node information. This is useful when encountering INVALID_NODE_ACCOUNT_ID errors to ensure subsequent transactions use the correct node account IDs.
      Returns:
      this
    • getLogger

      public Logger getLogger()
    • setLogger

      public Client setLogger(Logger logger)
    • getRealm

      public long getRealm()
      Get the current default realm for new Client instances.
      Returns:
      the default realm
    • getShard

      public long getShard()
      Get the current default shard for new Client instances.
      Returns:
      the default shard
    • close

      public void close() throws TimeoutException
      Initiates an orderly shutdown of all channels (to the Hedera network) in which preexisting transactions or queries continue but more would be immediately cancelled.

      After this method returns, this client can be re-used. Channels will be re-established as needed.

      Specified by:
      close in interface AutoCloseable
      Throws:
      TimeoutException - if the mirror network doesn't close in time
    • close

      public void close(Duration timeout) throws TimeoutException
      Initiates an orderly shutdown of all channels (to the Hedera network) in which preexisting transactions or queries continue but more would be immediately cancelled.

      After this method returns, this client can be re-used. Channels will be re-established as needed.

      Parameters:
      timeout - The Duration to be set
      Throws:
      TimeoutException - if the mirror network doesn't close in time