Hedera
Search…
Submit a message
A transaction that submits a topic message to the Hedera network. To access the messages submitted to a topic ID, subscribe to the topic via a mirror node. The mirror node will publish the ordered messages to subscribers. Once the transaction is successfully executed, the receipt of the transaction will include the topic's updated sequence number and topic running hash.
Transaction Signing Requirements
  • Anyone can submit a message to a public topic
  • The submitKey is required to sign the transaction for a private topic
HCS message size: 1024 bytes
V2
V1
Constructor
Description
new TopicMessageSubmitTransaction()
Initializes a TopicMessageSubmitTransaction object
1
new TopicMessageSubmitTransaction()
Copied!

Methods

Method
Type
Description
Requirement
setTopicId(<topicId>)
TopicId
The topic ID to submit the message to
Required
setMessage(<message>)
String
The message in a String format
Optional
setMessage(<message>)
byte [ ]
The message in a byte array format
Optional
setMessage(<message>)
ByteString
The message in a ByteString format
Optional
Java
1
//Create the transaction
2
TopicMessageSubmitTransaction transaction = new TopicMessageSubmitTransaction()
3
.setTopicId(newTopicId)
4
.setMessage("hello, HCS! ");
5
​
6
//Sign with the client operator key and submit transaction to a Hedera network, get transaction ID
7
TransactionResponse txResponse = transaction.execute(client);
8
​
9
//Request the receipt of the transaction
10
TransactionReceipt receipt = txResponse.getReceipt(client);
11
​
12
//Get the transaction consensus status
13
Status transactionStatus = receipt.status;
14
​
15
System.out.println("The transaction consensus status is " +transactionStatus);
16
//v2.0.0
Copied!
JavaScript
1
//Create the transaction
2
await new TopicMessageSubmitTransaction({
3
topicId: createReceipt.topicId,
4
message: "Hello World",
5
}).execute(client);
6
​
7
//v2.0.0
Copied!
Go
1
//Create the transaction
2
transaction := hedera.NewTopicSubmitTransaction().
3
SetTopicID(topicID).
4
SetMessage([]byte(content))
5
​
6
//Sign with the client operator private key and submit the transaction to a Hedera network
7
txResponse, err := transaction.Execute(client)
8
if err != nil {
9
panic(err)
10
}
11
​
12
//Request the receipt of the transaction
13
transactionReceipt, err := txResponse.GetReceipt(client)
14
if err != nil {
15
panic(err)
16
}
17
​
18
//Get the transaction consensus status
19
transactionStatus := receipt.Status
20
​
21
fmt.Printf("The transaction consensus status is %v\n", transactionStatus)
22
//v2.0.0
Copied!
Constructor
Description
new ConsensusMessageSubmitTransaction()
Initializes a ConsensusMessageSubmitTransaction object
1
new ConsensusMessageSubmitTransaction()
Copied!

Methods

Method
Type
Description
Requirement
setTopicId(<topicId>)
TopicId
The topic ID to submit the message to
Required
setMessage(<message>)
String
The message in a String format
Optional
setMessage(<message>)
byte [ ]
The message in a byte array format
Optional
setMessage(<message>)
ByteString
The message in a ByteString format
Optional
setMaxChunk(<maxChunks>)
int
The number of chunks to break the message into. Default:10
Optional
setMaxChunkInfo(<initial Transactionid ,totalNumber, number>)
TransactionId, int, int
initialId: TransactionID of the first chunk, gets copied to every subsequent chunk in a fragmented message.
total: total number of chunks
number: The sequence number (from 1 to total) of the current chunk in the message.
Optional
Java
1
//Submits a message to a public topic
2
new ConsensusMessageSubmitTransaction()
3
.setTopicId(topicId)
4
.setMessage("hello, HCS! " + i)
5
.build(client)
6
.execute(client)
7
.getReceipt(client);
8
​
9
//v1.3.2
Copied!
JavaScript
1
//Submits a message to a public topic
2
await new ConsensusMessageSubmitTransaction()
3
.setTopicId(topicId)
4
.setMessage("hello, HCS! " + i)
5
.build(client)
6
.execute(client)
7
.getReceipt(client);
8
​
9
//v1.4.4
Copied!

Get transaction values

V2
Method
Type
Description
getTopicId()
TopicId
The topic ID to submit the message to
getMessage()
ByteString
The message being submitted
getAllTransactionHash()
byte [ ]
The hash for each transaction
Java
1
//Create the transaction
2
TopicMessageSubmitTransaction transaction = new TopicMessageSubmitTransaction()
3
.setTopicId(newTopicId)
4
.setMessage("hello, HCS! ");
5
​
6
//Get the transaction message
7
ByteString getMessage = transaction.getMessage();
8
//v2.0.0
Copied!
JavaScript
1
//Create the transaction
2
const transaction = await new TopicMessageSubmitTransaction()
3
.setTopicId(newTopicId)
4
.setMessage("hello, HCS! ");
5
​
6
//Get the transaction message
7
const getMessage = transaction.getMessage();
8
​
9
//v2.0.0
Copied!
Go
1
//Create the transaction
2
transaction := hedera.NewTopicSubmitTransaction().
3
SetTopicID(topicID).
4
SetMessage([]byte(content))
5
​
6
//Get the transaction message
7
getMessage := transaction.GetMessage()
8
//v2.0.0
Copied!
Last modified 3mo ago
Copy link