HCS‑2 API Reference
Sources
- Module folder: GitHub
- base-client.ts: GitHub
- sdk.ts: GitHub
- browser.ts: GitHub
- tx.ts: GitHub
- types.ts: GitHub
Import PathsDirect link to Import Paths
- TypeScript
- Go
import {
HCS2Client,
BrowserHCS2Client,
HCS2RegistryType,
HCS2Operation,
type HCS2ClientConfig,
type SDKHCS2ClientConfig,
type CreateRegistryOptions,
type RegisterEntryOptions,
type UpdateEntryOptions,
type DeleteEntryOptions,
type MigrateTopicOptions,
type QueryRegistryOptions,
type TopicRegistry,
type RegistryEntry,
buildHcs2CreateRegistryTx,
buildHcs2RegisterTx,
buildHcs2UpdateTx,
buildHcs2DeleteTx,
buildHcs2MigrateTx,
} from '@hashgraphonline/standards-sdk';
import (
"github.com/hashgraph-online/standards-sdk-go/pkg/hcs2"
)
TypesDirect link to Types
- TypeScript
- Go
interface HCS2ClientConfig {
network: 'mainnet' | 'testnet';
logLevel?: 'debug' | 'info' | 'warn' | 'error';
silent?: boolean;
mirrorNodeUrl?: string;
logger?: any;
}
interface SDKHCS2ClientConfig extends HCS2ClientConfig {
operatorId: string | import('@hashgraph/sdk').AccountId;
operatorKey: string | import('@hashgraph/sdk').PrivateKey;
keyType?: 'ed25519' | 'ecdsa';
}
interface TopicRegistry {
topicId: string;
type: HCS2RegistryType;
ttl: number;
entries: RegistryEntry[];
}
interface RegistryEntry {
uid: string; // unique id for indexed registries
topicId: string; // registered topic
metadata?: string; // optional metadata
}
type ClientConfig struct {
OperatorAccountID string
OperatorPrivateKey string
Network string
MirrorBaseURL string
MirrorAPIKey string
}
type TopicRegistry struct {
TopicID string
Type RegistryType
TTL int64
Entries []RegistryEntry
}
type RegistryEntry struct {
UID string
TopicID string
Metadata string
Sequence int64
}
EnumsDirect link to Enums
- TypeScript
- Go
enum HCS2RegistryType { INDEXED = 0, NON_INDEXED = 1 }
enum HCS2Operation { REGISTER = 'register', UPDATE = 'update', DELETE = 'delete', MIGRATE = 'migrate' }
const (
RegistryTypeIndexed RegistryType = "INDEXED"
RegistryTypeNonIndexed RegistryType = "NON_INDEXED"
)
const (
OperationRegister RegistryOperation = "register"
OperationUpdate RegistryOperation = "update"
OperationDelete RegistryOperation = "delete"
OperationMigrate RegistryOperation = "migrate"
)
Message Schema (canonical)Direct link to Message Schema (canonical)
All HCS‑2 registry messages share p: 'hcs-2' and an op from HCS2Operation:
// REGISTER
{ "p": "hcs-2", "op": "register", "t_id": "0.0.123", "metadata": "...", "m": "optional" }
// UPDATE (indexed only)
{ "p": "hcs-2", "op": "update", "uid": "abc123", "t_id": "0.0.456", "metadata": "...", "m": "..." }
// DELETE (indexed only)
{ "p": "hcs-2", "op": "delete", "uid": "abc123", "m": "..." }
// MIGRATE (both types)
{ "p": "hcs-2", "op": "migrate", "t_id": "0.0.789", "metadata": "...", "m": "..." }
Server Client (HCS2Client)Direct link to Server Client (HCS2Client)
- TypeScript
- Go
constructor(config: SDKHCS2ClientConfig)
createRegistry(options?: CreateRegistryOptions): Promise<{ success: boolean; topicId?: string; transactionId?: string; error?: string }>
registerEntry(registryTopicId: string, options: RegisterEntryOptions): Promise<{ success: boolean; receipt?: import('@hashgraph/sdk').TransactionReceipt; sequenceNumber?: number; error?: string }>
updateEntry(registryTopicId: string, options: UpdateEntryOptions): Promise<{ success: boolean; receipt?: import('@hashgraph/sdk').TransactionReceipt; sequenceNumber?: number; error?: string }>
deleteEntry(registryTopicId: string, options: DeleteEntryOptions): Promise<{ success: boolean; receipt?: import('@hashgraph/sdk').TransactionReceipt; sequenceNumber?: number; error?: string }>
migrateRegistry(registryTopicId: string, options: MigrateTopicOptions): Promise<{ success: boolean; receipt?: import('@hashgraph/sdk').TransactionReceipt; sequenceNumber?: number; error?: string }>
getRegistry(topicId: string, options?: QueryRegistryOptions): Promise<TopicRegistry>
func NewClient(config ClientConfig) (*Client, error)
func (c *Client) CreateRegistry(ctx context.Context, options CreateRegistryOptions) (CreateRegistryResult, error)
func (c *Client) RegisterEntry(ctx context.Context, topicID string, options RegisterEntryOptions, protocol string) (OperationResult, error)
func (c *Client) UpdateEntry(ctx context.Context, topicID string, options UpdateEntryOptions) (OperationResult, error)
func (c *Client) DeleteEntry(ctx context.Context, topicID string, options DeleteEntryOptions) (OperationResult, error)
func (c *Client) MigrateRegistry(ctx context.Context, topicID string, options MigrateRegistryOptions) (OperationResult, error)
func (c *Client) GetRegistry(ctx context.Context, topicID string, options shared.QueryOptions) (TopicRegistry, error)
Notes
createRegistrysets the topic memo usingencodeHcs2RegistryMemo(registryType, ttl).adminKey/submitKeyinCreateRegistryOptionsaccept boolean | string | PublicKey | PrivateKey; boolean defaults to the operator key.- Indexed registries support UPDATE/DELETE with
uid; non‑indexed do not.
Browser Client (BrowserHCS2Client)Direct link to Browser Client (BrowserHCS2Client)
Wallet‑signed equivalents of the Node methods; params and results mirror the Node client. Transactions are frozen/executed with the provided signer.
Builders (tx.ts)Direct link to Builders (tx.ts)
- TypeScript
- Go
function buildHcs2CreateRegistryTx(params: {
registryType: HCS2RegistryType;
ttl: number;
adminKey?: import('@hashgraph/sdk').PublicKey;
submitKey?: import('@hashgraph/sdk').PublicKey;
memoOverride?: string;
operatorPublicKey?: import('@hashgraph/sdk').PublicKey;
}): import('@hashgraph/sdk').TopicCreateTransaction;
function buildHcs2RegisterTx(params: { registryTopicId: string; targetTopicId: string; metadata?: string; memo?: string; analyticsMemo?: string }): import('@hashgraph/sdk').TopicMessageSubmitTransaction;
function buildHcs2UpdateTx(params: { registryTopicId: string; uid: string; targetTopicId: string; metadata?: string; memo?: string; analyticsMemo?: string }): import('@hashgraph/sdk').TopicMessageSubmitTransaction;
function buildHcs2DeleteTx(params: { registryTopicId: string; uid: string; memo?: string; analyticsMemo?: string }): import('@hashgraph/sdk').TopicMessageSubmitTransaction;
function buildHcs2MigrateTx(params: { registryTopicId: string; targetTopicId: string; metadata?: string; memo?: string; analyticsMemo?: string }): import('@hashgraph/sdk').TopicMessageSubmitTransaction;
func BuildHCS2CreateRegistryTx(params CreateRegistryTxParams) *hedera.TopicCreateTransaction
func BuildHCS2RegisterTx(params RegisterTxParams) (*hedera.TopicMessageSubmitTransaction, error)
func BuildHCS2UpdateTx(params UpdateTxParams) (*hedera.TopicMessageSubmitTransaction, error)
func BuildHCS2DeleteTx(params DeleteTxParams) (*hedera.TopicMessageSubmitTransaction, error)
func BuildHCS2MigrateTx(params MigrateTxParams) (*hedera.TopicMessageSubmitTransaction, error)
Validation RulesDirect link to Validation Rules
- Registry memo uses
hcs-2:<type>:<ttl>. - Message
pmust behcs-2andopmust be one ofREGISTER|UPDATE|DELETE|MIGRATE. - Indexed registries require unique
uidfor UPDATE/DELETE.
ExampleDirect link to Example
- TypeScript
- Go
const c = new HCS2Client({ network: 'testnet', operatorId, operatorKey });
const created = await c.createRegistry({ registryType: HCS2RegistryType.INDEXED, ttl: 86400 });
await c.registerEntry(created.topicId!, { targetTopicId: '0.0.2001', metadata: 'app=chat' });
const reg = await c.getRegistry(created.topicId!);
client, _ := hcs2.NewClient(hcs2.ClientConfig{
Network: "testnet",
OperatorAccountID: os.Getenv("HEDERA_ACCOUNT_ID"),
OperatorPrivateKey: os.Getenv("HEDERA_PRIVATE_KEY"),
})
created, _ := client.CreateRegistry(context.Background(), hcs2.CreateRegistryOptions{
TTL: 86400,
UseOperatorAsSubmit: true,
})
client.RegisterEntry(context.Background(), created.TopicID, hcs2.RegisterEntryOptions{
TargetTopicID: "0.0.2001",
Metadata: "app=chat",
}, "hcs-2")
reg, _ := client.GetRegistry(context.Background(), created.TopicID, shared.QueryOptions{})