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(required, string): The ID of the topic to which the message will be submitted. -
message(required, string): The message content to submit. -
submitKeySigner(optional, Signer): Signer for a key that must sign any message submitted to the topic (access control). -
waitForChangesVisibility(optional, boolean): If true, waits until the message becomes visible/confirmed in the topic. -
waitForChangesVisibilityTimeoutMs(optional, number): Timeout in milliseconds to wait for visibility confirmation.
-
A promise resolving to a
SubmitMessageResultobject.
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.