Class TransactionId

java.lang.Object
com.hedera.hashgraph.sdk.TransactionId
All Implemented Interfaces:
Comparable<TransactionId>

public final class TransactionId extends Object implements Comparable<TransactionId>
The client-generated ID for a transaction.

This is used for retrieving receipts and records for a transaction, for appending to a file right after creating it, for instantiating a smart contract with bytecode in a file just created, and internally by the network for detecting when duplicate transactions are submitted.

  • Field Details

    • accountId

      @Nullable public final AccountId accountId
      The Account ID that paid for this transaction.
    • validStart

      @Nullable public final Instant validStart
      The time from when this transaction is valid.

      When a transaction is submitted there is additionally a validDuration (defaults to 120s) and together they define a time window that a transaction may be processed in.

  • Constructor Details

    • TransactionId

      public TransactionId(@Nullable AccountId accountId, @Nullable Instant validStart)
      No longer part of the public API. Use `Transaction.withValidStart()` instead.
      Parameters:
      accountId - the account id
      validStart - the valid start time
  • Method Details

    • withValidStart

      public static TransactionId withValidStart(AccountId accountId, Instant validStart)
      Create a transaction id.
      Parameters:
      accountId - the account id
      validStart - the valid start time
      Returns:
      the new transaction id
    • generate

      public static TransactionId generate(AccountId accountId)
      Generates a new transaction ID for the given account ID.

      Note that transaction IDs are made of the valid start of the transaction and the account that will be charged the transaction fees for the transaction.

      Parameters:
      accountId - the ID of the Hedera account that will be charge the transaction fees.
      Returns:
      TransactionId
    • fromProtobuf

      static TransactionId fromProtobuf(TransactionID transactionID)
      Create a transaction id from a protobuf.
      Parameters:
      transactionID - the protobuf
      Returns:
      the new transaction id
    • fromString

      public static TransactionId fromString(String s)
      Create a new transaction id from a string.
      Parameters:
      s - the string representing the transaction id
      Returns:
      the new transaction id
    • fromBytes

      public static TransactionId fromBytes(byte[] bytes) throws com.google.protobuf.InvalidProtocolBufferException
      Create a new transaction id from a byte array.
      Parameters:
      bytes - the byte array
      Returns:
      the new transaction id
      Throws:
      com.google.protobuf.InvalidProtocolBufferException - when there is an issue with the protobuf
    • getScheduled

      public boolean getScheduled()
      Extract the scheduled status.
      Returns:
      the scheduled status
    • setScheduled

      public TransactionId setScheduled(boolean scheduled)
      Assign the scheduled status.
      Parameters:
      scheduled - the scheduled status
      Returns:
      this
    • getNonce

      @Nullable public Integer getNonce()
      Extract the nonce.
      Returns:
      the nonce value
    • setNonce

      public TransactionId setNonce(@Nullable Integer nonce)
      Assign the nonce value.
      Parameters:
      nonce - the nonce value
      Returns:
      this
    • getReceipt

      Fetch the receipt of the transaction.
      Parameters:
      client - The client with which this will be executed.
      Returns:
      the transaction receipt
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
      ReceiptStatusException - when there is an issue with the receipt
    • getReceipt

      Fetch the receipt of the transaction.
      Parameters:
      client - The client with which this will be executed.
      timeout - The timeout after which the execution attempt will be cancelled.
      Returns:
      the transaction receipt
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
      ReceiptStatusException - when there is an issue with the receipt
    • getReceiptAsync

      public CompletableFuture<TransactionReceipt> getReceiptAsync(Client client)
      Fetch the receipt of the transaction asynchronously.
      Parameters:
      client - The client with which this will be executed.
      Returns:
      future result of the transaction receipt
    • getReceiptAsync

      public CompletableFuture<TransactionReceipt> getReceiptAsync(Client client, Duration timeout)
      Fetch the receipt of the transaction asynchronously.
      Parameters:
      client - The client with which this will be executed.
      timeout - The timeout after which the execution attempt will be cancelled.
      Returns:
      the transaction receipt
    • getReceiptAsync

      public void getReceiptAsync(Client client, BiConsumer<TransactionReceipt,Throwable> callback)
      Fetch the receipt of the transaction asynchronously.
      Parameters:
      client - The client with which this will be executed.
      callback - a BiConsumer which handles the result or error.
    • getReceiptAsync

      public void getReceiptAsync(Client client, Duration timeout, BiConsumer<TransactionReceipt,Throwable> callback)
      Fetch the receipt of the transaction 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.
    • getReceiptAsync

      public void getReceiptAsync(Client client, Consumer<TransactionReceipt> onSuccess, Consumer<Throwable> onFailure)
      Fetch the receipt of the transaction 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.
    • getReceiptAsync

      public void getReceiptAsync(Client client, Duration timeout, Consumer<TransactionReceipt> onSuccess, Consumer<Throwable> onFailure)
      Fetch the receipt of the transaction 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.
    • getRecord

      Fetch the record of the transaction.
      Parameters:
      client - The client with which this will be executed.
      Returns:
      the transaction record
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
      ReceiptStatusException - when there is an issue with the receipt
    • getRecord

      Fetch the record of the transaction.
      Parameters:
      client - The client with which this will be executed.
      timeout - The timeout after which the execution attempt will be cancelled.
      Returns:
      the transaction record
      Throws:
      TimeoutException - when the transaction times out
      PrecheckStatusException - when the precheck fails
      ReceiptStatusException - when there is an issue with the receipt
    • getRecordAsync

      public CompletableFuture<TransactionRecord> getRecordAsync(Client client)
      Fetch the record of the transaction asynchronously.
      Parameters:
      client - The client with which this will be executed.
      Returns:
      future result of the transaction record
    • getRecordAsync

      public CompletableFuture<TransactionRecord> getRecordAsync(Client client, Duration timeout)
      Fetch the record of the transaction 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 the transaction record
    • getRecordAsync

      public void getRecordAsync(Client client, BiConsumer<TransactionRecord,Throwable> callback)
      Fetch the record of the transaction asynchronously.
      Parameters:
      client - The client with which this will be executed.
      callback - a BiConsumer which handles the result or error.
    • getRecordAsync

      public void getRecordAsync(Client client, Duration timeout, BiConsumer<TransactionRecord,Throwable> callback)
      Fetch the record of the transaction 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.
    • getRecordAsync

      public void getRecordAsync(Client client, Consumer<TransactionRecord> onSuccess, Consumer<Throwable> onFailure)
      Fetch the record of the transaction 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.
    • getRecordAsync

      public void getRecordAsync(Client client, Duration timeout, Consumer<TransactionRecord> onSuccess, Consumer<Throwable> onFailure)
      Fetch the record of the transaction 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.
    • toProtobuf

      TransactionID toProtobuf()
      Extract the transaction id protobuf.
      Returns:
      the protobuf representation
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toStringWithChecksum

      public String toStringWithChecksum(Client client)
      Convert to a string representation with checksum.
      Parameters:
      client - the configured client
      Returns:
      the string representation with checksum
    • toBytes

      public byte[] toBytes()
      Extract the byte array representation.
      Returns:
      the byte array representation
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • compareTo

      public int compareTo(TransactionId o)
      Specified by:
      compareTo in interface Comparable<TransactionId>