Class AccountId

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

public final class AccountId extends Object implements Comparable<AccountId>
The ID for a cryptocurrency account on Hedera.
  • 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
    • aliasKey

      @Nullable public final PublicKey aliasKey
      The public key bytes to be used as the account's alias
    • evmAddress

      @Nullable public final EvmAddress evmAddress
      The ethereum account 20-byte EVM address to be used initially in place of the public key bytes
  • Constructor Details

    • AccountId

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

      public AccountId(@Nonnegative long shard, @Nonnegative long realm, @Nonnegative long num)
      Assign all parts of the account id.
      Parameters:
      shard - the shard part of the account id
      realm - the realm part of the account id
      num - the num part of the account id
    • AccountId

      AccountId(@Nonnegative long shard, @Nonnegative long realm, @Nonnegative long num, @Nullable String checksum)
      Assign all parts of the account id.
      Parameters:
      shard - the shard part of the account id
      realm - the realm part of the account id
      num - the num part of the account id
    • AccountId

      AccountId(@Nonnegative long shard, @Nonnegative long realm, @Nonnegative long num, @Nullable String checksum, @Nullable PublicKey aliasKey, @Nullable EvmAddress evmAddress)
      Assign all parts of the account id.
      Parameters:
      shard - the shard part of the account id
      realm - the realm part of the account id
      num - the num part of the account id
  • Method Details

    • fromString

      public static AccountId fromString(String id)
      Retrieve the account id from a string.
      Parameters:
      id - a string representing a valid account id
      Returns:
      the account id object
      Throws:
      IllegalArgumentException - when the account id and checksum are invalid
    • fromEvmAddress

      @Deprecated public static AccountId fromEvmAddress(String evmAddress)
      Deprecated.
      Retrieve the account id from an EVM address.
      Parameters:
      evmAddress - a string representing the EVM address
      Returns:
      the account id object Constructor that uses shard, realm and num should be used instead as shard and realm should not assume 0 value
    • fromEvmAddress

      public static AccountId fromEvmAddress(String evmAddress, @Nonnegative long shard, @Nonnegative long realm)
      Retrieve the account id from an EVM address.
      Parameters:
      evmAddress - a string representing the EVM address
      shard - the shard part of the account id
      realm - the shard realm of the account id
      Returns:
      the account id object In case shard and realm are unknown, they should be set to zero
    • fromEvmAddress

      @Deprecated public static AccountId fromEvmAddress(EvmAddress evmAddress)
      Deprecated.
      Retrieve the account id from an EVM address.
      Parameters:
      evmAddress - an EvmAddress instance
      Returns:
      the account id object Constructor that uses shard, realm and num should be used instead as shard and realm should not assume 0 value
    • fromEvmAddress

      public static AccountId fromEvmAddress(EvmAddress evmAddress, @Nonnegative long shard, @Nonnegative long realm)
      Retrieve the account id from an EVM address.
      Parameters:
      evmAddress - an EvmAddress instance
      shard - the shard part of the account id
      realm - the shard realm of the account id
      Returns:
      the account id object In case shard and realm are unknown, they should be set to zero
    • fromSolidityAddress

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

      static AccountId fromProtobuf(AccountID accountId)
      Retrieve the account id from a protobuf.
      Parameters:
      accountId - the protobuf
      Returns:
      the account id object
    • fromBytes

      public static AccountId fromBytes(byte[] bytes) throws com.google.protobuf.InvalidProtocolBufferException
      Retrieve the account id from a protobuf byte array.
      Parameters:
      bytes - a byte array representation of the protobuf
      Returns:
      the account id object
      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
    • toEvmAddress

      public String toEvmAddress()
      toEvmAddress returns EVM-compatible address representation of the entity
      Returns:
    • toProtobuf

      AccountID toProtobuf()
      Extract the account id protobuf.
      Returns:
      the account id builder
    • populateAccountNum

      public AccountId populateAccountNum(Client client) throws InterruptedException, ExecutionException
      Gets the actual `num` field of the `AccountId` from the Mirror Node. Should be used after generating `AccountId.fromEvmAddress()` because it sets the `num` field to `0` automatically since there is no connection between the `num` and the `evmAddress` Sync version
      Parameters:
      client -
      Returns:
      populated AccountId instance
      Throws:
      InterruptedException
      ExecutionException
    • populateAccountNumAsync

      @Deprecated public CompletableFuture<AccountId> populateAccountNumAsync(Client client)
      Deprecated.
      Use 'populateAccountNum' instead due to its nearly identical operation.
      Gets the actual `num` field of the `AccountId` from the Mirror Node. Should be used after generating `AccountId.fromEvmAddress()` because it sets the `num` field to `0` automatically since there is no connection between the `num` and the `evmAddress` Async version
      Parameters:
      client -
      Returns:
      populated AccountId instance
    • populateAccountEvmAddress

      public AccountId populateAccountEvmAddress(Client client) throws ExecutionException, InterruptedException
      Populates `evmAddress` field of the `AccountId` extracted from the Mirror Node. Sync version
      Parameters:
      client -
      Returns:
      populated AccountId instance
      Throws:
      ExecutionException
      InterruptedException
    • populateAccountEvmAddressAsync

      @Deprecated public CompletableFuture<AccountId> populateAccountEvmAddressAsync(Client client)
      Deprecated.
      Use 'populateAccountEvmAddress' instead due to its nearly identical operation.
      Populates `evmAddress` field of the `AccountId` extracted from the Mirror Node. Async version
      Parameters:
      client -
      Returns:
      populated AccountId instance
    • 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 - when the account id and checksum are invalid
    • getChecksum

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

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

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

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