Portal Community
What is HCS? The Hedera Consensus Service gives you a totally-ordered, timestamped message log — useful as an audit trail, an event bus between systems, or a tamper-evident record of anything you submit to it.

getMessages

Returns messages published to a topic, in consensus sequence order.

FieldTypeRequiredDescription
topicIdtext✓ YesHCS topic ID, e.g. 0.0.55555
limitnumberNo1–100, default 25
sequenceFromnumberNoOnly return messages with sequence number ≥ this value — use for pagination/polling.
decodeUtf8booleanNoDefault true. Decodes message content from base64 to a UTF-8 string; set false to receive raw base64.
networkselectNoSee Networks.
{
  "topicId": "0.0.55555",
  "messages": [
    {
      "sequenceNumber": 41,
      "consensusTimestamp": "1690000012.345678900",
      "message": "{\"event\":\"order-placed\",\"orderId\":\"A-1042\"}",
      "runningHash": "9f2a...e711"
    },
    {
      "sequenceNumber": 42,
      "consensusTimestamp": "1690000019.001122300",
      "message": "{\"event\":\"order-shipped\",\"orderId\":\"A-1042\"}",
      "runningHash": "1cd0...aa42"
    }
  ]
}

Pagination / Polling Pattern

To poll a topic for new messages as a workflow trigger, remember the highest sequenceNumber you've already processed, then call again with sequenceFrom set to that number + 1:

  1. Call topic.getMessages with no sequenceFrom the first time (or start at 1).
  2. Record the last sequenceNumber seen.
  3. On the next poll, set sequenceFrom to lastSeen + 1 — only new messages come back.

See Examples for a full worked polling workflow.

decodeUtf8 and binary payloads: If a topic carries binary (non-text) message data, set decodeUtf8 to false and decode it yourself downstream — forcing UTF-8 decoding on binary content can corrupt or garble the payload.