Node SDK (HCS17Client)
The SDK publishes and verifies HCS‑17 state hashes using an operator account. It centralizes topic creation and message submission while delegating all transaction construction to tx.ts / tx.go.
SetupDirect link to Setup
- TypeScript
- Go
import { HCS17Client } from '@hashgraphonline/standards-sdk';
const client = new HCS17Client({
network: 'testnet',
operatorId: process.env.ACCOUNT_ID!,
operatorKey: process.env.PRIVATE_KEY!, // string or PrivateKey
keyType: 'ed25519', // or 'ecdsa' if needed
logLevel: 'info',
});
import (
"os"
"github.com/hashgraph-online/standards-sdk-go/pkg/hcs17"
)
client, err := hcs17.NewClient(hcs17.ClientConfig{
Network: "testnet",
OperatorAccountID: os.Getenv("HEDERA_ACCOUNT_ID"),
OperatorPrivateKey: os.Getenv("HEDERA_PRIVATE_KEY"),
})
Create a State TopicDirect link to Create a State Topic
Topics for HCS‑17 messages must use the numeric memo format hcs-17:<type>:<ttl>.
- TypeScript
- Go
const topicId = await client.createStateTopic({
ttl: 86400,
// adminKey/submitKey can be boolean | string | PublicKey | KeyList
});
topicID, err := client.CreateStateTopic(ctx, hcs17.CreateTopicOptions{
TTLSeconds: 86400,
// AdminKey / SubmitKey can be configured here
})
The client validates memo structure via parseHCS17Memo and exposes validateHCS17Topic(topicId) if you need to verify existing topics.
Submit a MessageDirect link to Submit a Message
If you already have a computed state hash and topic list, build a valid payload and submit:
- TypeScript
- Go
import { StateHashMessage } from '@hashgraphonline/standards-sdk';
const message: StateHashMessage = client.createStateHashMessage(
'abc123…', // stateHash
'0.0.1234', // accountId
['0.0.2001','0.0.2002'],// topics
'optional memo', // m
);
await client.submitMessage(topicId, message);
message := client.CreateStateHashMessage(
"abc123…", // stateHash
"0.0.1234", // accountId
[]string{"0.0.2001", "0.0.2002"}, // topics
"optional memo", // m
nil, // epoch
)
receipt, err := client.SubmitMessage(ctx, topicID, message, "transaction memo")
Compute and PublishDirect link to Compute and Publish
The high‑level helper fetches latest running hashes from Mirror Node, computes the HCS‑17 account state hash, and publishes it to a target topic.
- TypeScript
- Go
const { stateHash, receipt } = await client.computeAndPublish({
accountId: '0.0.1234',
accountPublicKey: '302a30…', // or PublicKey
topics: ['0.0.2001', '0.0.2002'],
publishTopicId: topicId,
memo: 'app context',
});
console.log('Published state hash:', stateHash);
result, err := client.ComputeAndPublish(ctx, hcs17.ComputeAndPublishOptions{
AccountID: "0.0.1234",
AccountPublicKey: "302a30…",
Topics: []string{"0.0.2001", "0.0.2002"},
PublishTopicID: topicID,
Memo: "app context",
})
fmt.Println("Published state hash:", result.StateHash)
Read Latest MessagesDirect link to Read Latest Messages
Mirror‑node helpers return parsed, schema‑validated HCS‑17 envelopes:
- TypeScript
- Go
const recent = await client.getRecentMessages(topicId, { limit: 25, order: 'desc' });
const latest = await client.getLatestMessage(topicId);
recent, err := client.GetRecentMessages(ctx, topicID, 25, "desc")
latest, err := client.GetLatestMessage(ctx, topicID)
NotesDirect link to Notes
- No dynamic imports are used; signing occurs with the configured operator.
- All transaction JSON is constructed in
tx.tsbuilders (buildHcs17CreateTopicTx,buildHcs17MessageTx). - Memos use numeric enums (
HCS17TopicType.STATE = 0).