Class TokenId

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

public class TokenId extends Object implements Comparable<TokenId>
Constructs a TokenId. See Hedera Documentation
  • 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

    • TokenId

      @Deprecated public TokenId(@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
    • TokenId

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

      TokenId(@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 TokenId fromString(String id)
      Create a token id from a string.
      Parameters:
      id - the string representation
      Returns:
      the new token id
    • fromProtobuf

      static TokenId fromProtobuf(TokenID tokenId)
      Create a token id from a protobuf.
      Parameters:
      tokenId - the protobuf
      Returns:
      the new token id
    • fromBytes

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

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

      public static TokenId fromEvmAddress(long shard, long realm, String evmAddress)
      Constructs a TokenID 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 TokenID object
      Throws:
      IllegalArgumentException - if the EVM address is not a valid long zero address
    • toEvmAddress

      public String toEvmAddress()
      Converts this TokenId 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
    • nft

      public NftId nft(@Nonnegative long serial)
      Create an nft id.
      Parameters:
      serial - the serial number
      Returns:
      the new nft id
    • toSolidityAddress

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

      TokenID toProtobuf()
      Create the protobuf.
      Returns:
      a 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
      Validate the configured client.
      Parameters:
      client - the configured client
      Throws:
      BadEntityIdException - if entity ID is formatted poorly
    • getChecksum

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

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

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

      public String toStringWithChecksum(Client client)
      Create a string representation with checksum.
      Parameters:
      client - the configured client
      Returns:
      the string representation with 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(TokenId o)
      Specified by:
      compareTo in interface Comparable<TokenId>