Summary
In the previous tutorial, “Submit Your First Message,” you have learned how to submit a message to a public topic. It means anyone can send a message to the topic you created because you didn’t set a Submit Key. When setting a Submit Key, your topic becomes a private topic because each message needs to be signed by the Submit Key. Therefore, you can control who can submit messages to your topic. Of course, the data is still public, as is all data on a public ledger, but we say the topic is private because the topic is restricted by who can submit messages to it.Prerequisites
We recommend you complete the “Submit Your First Message” tutorial here to get a basic understanding of the Hedera Consensus Service. This example does not build upon the previous examples. ✅ You can find a full code check for this tutorial at the bottom of this page.Table of Contents
1. Create a private topic
To create a private topic, you will usesetSubmitKey() to set a Submit Key. This key needs to sign all messages someone sends to the topic. A message will be rejected if you don’t sign the message or sign with an incorrect key. The cost of creating a private topic is the same as a public topic: $0.01.
2. Subscribe to a topic
The code used to subscribe to a public or private topic doesn’t change. Anyone can listen to the messages you send to your private topic. You need to provide theTopicMessageQuery() with your topic ID to subscribe to it.
3. Submit a message
Now you are ready to submit a message to your private topic. To do this, you will useTopicMessageSubmitTransaction(). However, you need to sign this transaction with your Submit Key. The cost for sending a message to a private topic is the same as a public topic: $0.0001.
⚠️ Upcoming Price Change – ConsensusSubmitMessageStarting January 2026, the price for the ConsensusSubmitMessage transaction will increase from
$0.0001 to $0.0008 USD. This change will take effect with the v0.69 mainnet release and applies only to ConsensusSubmitMessage transactions. This update improves the long-term economic sustainability of the Hedera network while preserving predictable and USD-fixed pricing for developers. Read this blog article for more information.Code Check ✅
Java
Java
JavaScript
JavaScript
Go
Go
Have a question? Ask it on StackOverflow