Class ContractId

java.lang.Object
com.hedera.hashgraph.sdk.Key
com.hedera.hashgraph.sdk.ContractId
All Implemented Interfaces:
Comparable<ContractId>
Direct Known Subclasses:
DelegateContractId

public class ContractId extends Key implements Comparable<ContractId>
The ID for a smart contract instance on Hedera.
  • Field Details

    • EVM_ADDRESS_REGEX

      static final Pattern EVM_ADDRESS_REGEX
    • 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
    • evmAddress

      @Nullable public final byte[] evmAddress
      The 20-byte EVM address of the contract to call.
  • Constructor Details

    • ContractId

      @Deprecated public ContractId(@Nonnegative long num)
      Deprecated.
      Assign the num part of the contract 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
    • ContractId

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

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

      ContractId(@Nonnegative long shard, @Nonnegative long realm, byte[] evmAddress)
  • Method Details

    • fromString

      public static ContractId fromString(String id)
      Parse contract id from a string.
      Parameters:
      id - the string containing a contract id
      Returns:
      the contract id object
    • fromSolidityAddress

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

      public static ContractId fromEvmAddress(@Nonnegative long shard, @Nonnegative long realm, String evmAddress)
      Parse contract id from an ethereum address.
      Parameters:
      shard - the desired shard
      realm - the desired realm
      evmAddress - the evm address
      Returns:
      the contract id object
    • fromProtobuf

      static ContractId fromProtobuf(ContractID contractId)
      Extract a contract id from a protobuf.
      Parameters:
      contractId - the protobuf containing a contract id
      Returns:
      the contract id object
    • fromBytes

      public static ContractId fromBytes(byte[] bytes) throws com.google.protobuf.InvalidProtocolBufferException
      Convert a byte array to an account balance object.
      Parameters:
      bytes - the byte array
      Returns:
      the converted contract 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

      ContractID toProtobuf()
      Convert contract id to protobuf.
      Returns:
      the protobuf object
    • populateContractNum

      public ContractId populateContractNum(Client client) throws InterruptedException, ExecutionException
      Gets the actual `num` field of the `ContractId` from the Mirror Node. Should be used after generating `ContractId.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 ContractId instance
      Throws:
      InterruptedException
      ExecutionException
    • populateContractNumAsync

      @Deprecated public CompletableFuture<ContractId> populateContractNumAsync(Client client)
      Deprecated.
      Use 'populateContractNum' instead due to its nearly identical operation.
      Gets the actual `num` field of the `ContractId` from the Mirror Node. Should be used after generating `ContractId.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 ContractId 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 the checksum.
      Parameters:
      client - to validate against
      Throws:
      BadEntityIdException - if entity ID is formatted poorly
    • getChecksum

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

      Key toProtobufKey()
      Description copied from class: Key
      Serialize this key as a protobuf object
      Specified by:
      toProtobufKey in class Key
    • toBytes

      public byte[] toBytes()
      Description copied from class: Key
      Create the byte array.
      Overrides:
      toBytes in class Key
      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(ContractId o)
      Specified by:
      compareTo in interface Comparable<ContractId>