HcsTopicService API Reference
This document provides a detailed API reference for the HcsTopicService
class — a service for managing Hedera Consensus Service (HCS) topics, including creating, updating, deleting topics, and retrieving topic info.
Methods
createTopic
async createTopic(props?: CreateTopicProps): Promise<string>
Creates a new HCS topic.
-
props
(optional): Properties to configure topic creation.
CreateTopicProps
fields:
-
topicMemo
(optional, string): Memo or description for the topic. -
submitKey
(optional, PrivateKey): Private key required to submit messages. -
adminKey
(optional, PrivateKey): Private key required for administrative actions on the topic. -
autoRenewPeriod
(optional, Duration | Long | number): Duration for auto-renewal. -
autoRenewAccountId
(optional, AccountId | string): Account ID responsible for auto-renew payments. -
autoRenewAccountKey
(optional, PrivateKey): Private key of the auto-renew account (required ifautoRenewAccountId
is set). -
waitForChangesVisibility
(optional, boolean): If true, waits until the topic is visible in the mirror node. -
waitForChangesVisibilityTimeoutMs
(optional, number): Timeout in milliseconds to wait for changes visibility.
-
A promise resolving to the created topic ID as a string.
-
Error if
autoRenewAccountId
is provided withoutautoRenewAccountKey
. -
Error if the topic creation transaction fails.
updateTopic
async updateTopic(props: UpdateTopicProps): Promise<void>
Updates an existing HCS topic.
-
props
(required): Properties for updating the topic.
UpdateTopicProps
fields:
-
topicId
(required, string): The ID of the topic to update. -
currentAdminKey
(required, PrivateKey): Current admin key authorizing the update. -
topicMemo
(optional, string): New memo for the topic (set empty string to clear). -
submitKey
(optional, PrivateKey): New submit key. -
adminKey
(optional, PrivateKey): New admin key. -
autoRenewPeriod
(optional, Duration | Long | number): New auto-renewal period (default fallback to 90 days if null). -
autoRenewAccountId
(optional, AccountId | string): New auto-renew account ID. -
autoRenewAccountKey
(optional, PrivateKey): Private key of the auto-renew account (required ifautoRenewAccountId
is provided). -
expirationTime
(optional, Timestamp | Date): New expiration time. -
waitForChangesVisibility
(optional, boolean): If true, wait until updated topic info is visible in mirror node. -
waitForChangesVisibilityTimeoutMs
(optional, number): Timeout in milliseconds for visibility wait.
-
A promise resolving when the topic update completes.
-
Error if
autoRenewAccountId
is set withoutautoRenewAccountKey
. -
Error if the update transaction fails.
deleteTopic
async deleteTopic(props: DeleteTopicProps): Promise<void>
Deletes an HCS topic.
-
props
(required): Properties for deleting the topic.
DeleteTopicProps
fields:
-
topicId
(required, string): ID of the topic to delete. -
currentAdminKey
(required, PrivateKey): Current admin key authorizing the deletion. -
waitForChangesVisibility
(optional, boolean): Wait until deletion is confirmed visible in mirror node. -
waitForChangesVisibilityTimeoutMs
(optional, number): Timeout in milliseconds to wait for visibility.
-
A promise resolving when deletion is complete.
-
Error if the deletion transaction fails.