HederaHcsService API Reference
This document provides a concise API reference for the HederaHcsService
class — a service for working with Hedera Consensus Service (HCS). It enables creation, update, deletion of topics, message submission, and file handling.
Methods
createTopic
async createTopic(props?: CreateTopicProps & NetworkName): Promise<TopicInfo>
Creates a new HCS topic.
-
props
(optional): Properties for creating a topic, combined with a network name.
CreateTopicProps
parameters:
-
topicMemo
(optional, string): Memo associated with the topic. -
submitKey
(optional, PrivateKey): Key used to submit messages. -
adminKey
(optional, PrivateKey): Key to administer (update or delete) the topic. -
autoRenewPeriod
(optional, Duration | Long | number): Auto-renewal period for the topic. -
autoRenewAccountId
(optional, AccountId | string): Account ID responsible for auto-renewal payments. -
autoRenewAccountKey
(optional, PrivateKey): Private key of the auto-renew account. -
waitForChangesVisibility
(optional, boolean): If true, waits for consensus/gossip visibility after creation. -
waitForChangesVisibilityTimeoutMs
(optional, number): Timeout in milliseconds for changes visibility.
-
The created
TopicInfo
.
updateTopic
async updateTopic(props: UpdateTopicProps & NetworkName): Promise<TopicInfo>
Updates an existing HCS topic.
-
props
: Properties for updating a topic, combined with a network name.
UpdateTopicProps
parameters:
-
topicId
(required, string): ID of the topic to update. -
currentAdminKey
(required, PrivateKey): Current admin key authorizing the update. -
expirationTime
(optional, Timestamp | Date): New expiration time to set. -
All properties from
CreateTopicProps
are also available for update (e.g., topicMemo, submitKey, adminKey, etc.).
-
The updated
TopicInfo
.
deleteTopic
async deleteTopic(props: DeleteTopicProps & NetworkName): Promise<boolean>
Deletes a topic.
-
props
: Properties for deleting a topic, combined with a network name.
DeleteTopicProps
parameters:
-
topicId
(required, string): ID of the topic to delete. -
currentAdminKey
(required, PrivateKey): Current admin key authorizing the deletion. -
waitForChangesVisibility
(optional, boolean): Waits for deletion visibility confirmation if true. -
waitForChangesVisibilityTimeoutMs
(optional, number): Timeout in milliseconds during which to wait for visibility.
-
true
if deletion was successful.
getTopicInfo
async getTopicInfo(props: GetTopicInfoProps & NetworkName): Promise<TopicInfo>
Retrieves information about a topic.
-
props
: Properties for topic info request, combined with a network name.
submitMessage
async submitMessage(props: SubmitMessageProps & NetworkName): Promise<SubmitMessageResult>
Submits a message to a topic.
-
props
: Properties for message submission, combined with a network name.
SubmitMessageProps
parameters:
-
topicId
(required, string): The topic ID to submit the message. -
message
(required, string): Message content. -
submitKey
(optional, PrivateKey): Authorized key for message submission. -
waitForChangesVisibility
(optional, boolean): Wait for consensus/gossip visibility if true. -
waitForChangesVisibilityTimeoutMs
(optional, number): Timeout in milliseconds to wait for visibility.
-
SubmitMessageResult
containing nodeId, transactionId, and transactionHash.
getTopicMessages
async getTopicMessages(props: GetTopicMessagesProps & NetworkName): Promise<TopicMessageData[]>
Retrieves messages from a topic.
-
props
: Parameters to query topic messages, combined with a network name.
GetTopicMessagesProps
parameters:
-
topicId
(required, string): The topic ID to fetch messages from. -
maxWaitSeconds
(optional, number): Max seconds to wait when polling for new messages. -
toDate
(optional, Date): Upper time boundary for fetching messages. -
limit
(optional, number): Maximum number of messages to retrieve.
-
An array of
TopicMessageData
.
submitFile
async submitFile(props: SubmitFileProps & NetworkName): Promise<string>
Submits a file split into topic messages.
-
props
: File submission parameters combined with a network name.
SubmitFileProps
parameters:
-
payload
(required, Buffer): Binary content of the file. -
submitKey
(required, PrivateKey): Key to sign each chunk submission transaction. -
waitForChangesVisibility
(optional, boolean): Wait for consensus/gossip visibility if true. -
waitForChangesVisibilityTimeoutMs
(optional, number): Timeout in milliseconds to wait for visibility.
-
Topic ID created for the file.