HcsMessageService API Reference
This document provides a detailed API reference for the HcsMessageService
class — a service for submitting and querying messages in Hedera Consensus Service (HCS) topics.
Constructor
constructor
constructor(client: Client, cache?: CacheConfig | Cache | HcsCacheService)
Creates a new instance of HcsMessageService
.
-
client
(required): Hedera SDK client instance used for HCS operations. -
cache
(optional): Cache configuration, cache instance, or an existingHcsCacheService
.
Methods
submitMessage
async submitMessage(props: SubmitMessageProps): Promise<SubmitMessageResult>
Submits a message to an HCS topic.
-
props
(required): Properties for submitting the message.
SubmitMessageProps
fields:
-
topicId
(string, required): The ID of the topic to which the message will be submitted. -
message
(string, required): The message content to submit. -
submitKey
(PrivateKey, optional): Private key used to sign the submission transaction. -
waitForChangesVisibility
(boolean, optional): If true, waits until the message becomes visible/confirmed in the topic. -
waitForChangesVisibilityTimeoutMs
(number, optional): Timeout in milliseconds to wait for visibility confirmation.
-
A promise resolving to a
SubmitMessageResult
object.
getTopicMessages
async getTopicMessages(props: GetTopicMessagesProps): Promise<TopicMessageData[]>
Retrieves messages from an HCS topic.
-
props
(required): Properties to configure the message retrieval.
GetTopicMessagesProps
fields:
-
topicId
(string, required): The ID of the topic to fetch messages from. -
maxWaitSeconds
(number, optional): Maximum number of seconds to wait for new messages during polling. -
toDate
(Date, optional): Upper time bound (inclusive) for message retrieval. -
limit
(number, optional): Maximum number of messages to retrieve.
-
A promise resolving to an array of
TopicMessageData
.