Class TopicId

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

public final class TopicId extends Object implements Comparable<TopicId>
Unique identifier for a topic (used by the consensus service).
  • Field Details

    • shard

      @Nonnegative public final long shard
      The shard number
    • realm

      @Nonnegative public final long realm
      The realm number
    • num

      @Nonnegative public final long num
      The id number
  • Constructor Details

    • TopicId

      @Deprecated public TopicId(@Nonnegative long num)
      Deprecated.
      Constructor.
      Parameters:
      num - the num part Constructor that uses shard, realm and num should be used instead as shard and realm should not assume 0 value
    • TopicId

      public TopicId(@Nonnegative long shard, @Nonnegative long realm, @Nonnegative long num)
      Constructor.
      Parameters:
      shard - the shard part
      realm - the realm part
      num - the num part
    • TopicId

      TopicId(@Nonnegative long shard, @Nonnegative long realm, @Nonnegative long num, @Nullable String checksum)
      Constructor.
      Parameters:
      shard - the shard part
      realm - the realm part
      num - the num part
      checksum - the checksum
  • Method Details

    • fromString

      public static TopicId fromString(String id)
      Create a topic id from a string.
      Parameters:
      id - the string representation
      Returns:
      the new topic id
    • fromSolidityAddress

      @Deprecated public static TopicId fromSolidityAddress(String address)
      Deprecated.
      This method is deprecated. Use fromEvmAddress(long, long, String) instead.
      Retrieve the topic id from a solidity address.
      Parameters:
      address - a string representing the address
      Returns:
      the topic id object
    • fromProtobuf

      static TopicId fromProtobuf(TopicID topicId)
      Create a topic id from a protobuf.
      Parameters:
      topicId - the protobuf
      Returns:
      the new topic id
    • fromBytes

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

      @Deprecated public String toSolidityAddress()
      Deprecated.
      This method is deprecated. Use toEvmAddress() instead.
      Extract the solidity address.
      Returns:
      the solidity address as a string
    • fromEvmAddress

      public static TopicId fromEvmAddress(long shard, long realm, String evmAddress)
      Constructs a TopicId from shard, realm, and EVM address. The EVM address must be a "long zero address" (first 12 bytes are zero).
      Parameters:
      shard - the shard number
      realm - the realm number
      evmAddress - the EVM address as a hex string
      Returns:
      the TopicId object
      Throws:
      IllegalArgumentException - if the EVM address is not a valid long zero address
    • toEvmAddress

      public String toEvmAddress()
      Converts this TopicId to an EVM address string. Creates a solidity address using shard=0, realm=0, and the file number.
      Returns:
      the EVM address as a hex string
    • toProtobuf

      TopicID toProtobuf()
      Extracts a protobuf representing the token id.
      Returns:
      the protobuf representation
    • validate

      @Deprecated public void validate(Client client) throws BadEntityIdException
      Deprecated.
      Parameters:
      client - to validate against
      Throws:
      BadEntityIdException - if entity ID is formatted poorly
    • validateChecksum

      public void validateChecksum(Client client) throws BadEntityIdException
      Verify that the client has a valid checksum.
      Parameters:
      client - the client to verify
      Throws:
      BadEntityIdException - if entity ID is formatted poorly
    • getChecksum

      @Nullable public String getChecksum()
      Extracts the checksum.
      Returns:
      the checksum
    • toBytes

      public byte[] toBytes()
      Extracts a byte array representation.
      Returns:
      the byte array representation
    • toString

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

      public String tostringwithchecksum(Client client)
      Create a string representation that includes the checksum.
      Parameters:
      client - the client
      Returns:
      the string representation with the checksum
    • hashCode

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

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • compareTo

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