Server Client
The server client uses direct Hedera operator credentials to create checkpoint topics and publish checkpoint commitments.
Create a ClientDirect link to Create a Client
- TypeScript
- Go
- Python
// HCS-27 TypeScript support is not yet available.
// Coming soon to @hashgraphonline/standards-sdk.
import "github.com/hashgraph-online/standards-sdk-go/pkg/hcs27"
client, err := hcs27.NewClient(hcs27.ClientConfig{
OperatorAccountID: os.Getenv("HEDERA_ACCOUNT_ID"),
OperatorPrivateKey: os.Getenv("HEDERA_PRIVATE_KEY"),
Network: "testnet",
})
if err != nil {
log.Fatal(err)
}
import os
from standards_sdk_py.hcs27 import Hcs27Client
client = Hcs27Client(
operator_id=os.environ["HEDERA_ACCOUNT_ID"],
operator_private_key=os.environ["HEDERA_PRIVATE_KEY"],
network="testnet",
)
Create a Checkpoint TopicDirect link to Create a Checkpoint Topic
- TypeScript
- Go
- Python
// Not yet available.
topicID, txID, err := client.CreateCheckpointTopic(ctx, hcs27.CreateTopicOptions{
TTLSeconds: 86400,
UseOperatorAsAdmin: true,
UseOperatorAsSubmit: true,
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("Created checkpoint topic: %s (tx: %s)\n", topicID, txID)
txID = client.create_checkpoint_topic(ttl_seconds=86400, use_operator_as_admin=True, use_operator_as_submit=True)
fmt.printf("Created checkpoint topic: %s (tx: %s)\n", topicID, txID)
Publish a CheckpointDirect link to Publish a Checkpoint
- TypeScript
- Go
- Python
// Not yet available.
metadata := hcs27.CheckpointMetadata{
Type: "ans-checkpoint-v1",
Stream: hcs27.StreamID{Registry: "my-app", LogID: "events"},
Log: &hcs27.LogProfile{
Algorithm: "sha-256",
Leaf: "rfc6962-leaf",
Merkle: "rfc6962-node",
},
Root: hcs27.RootCommitment{
TreeSize: 150,
RootHashB64: "8zVIY3QJBOdTYR8dnLOzedEfym4Jl7f1xy8pciLEMew",
},
Previous: &hcs27.PreviousCommitment{
TreeSize: 100,
RootHashB64: "kZ4L2bPe1sX...",
},
BatchRange: hcs27.BatchRange{Start: 101, End: 150},
}
result, err := client.PublishCheckpoint(ctx, topicID, metadata, "batch 101-150", "")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Published checkpoint (seq: %d, tx: %s)\n", result.SequenceNumber, result.TransactionID)
metadata = hcs27.CheckpointMetadata{
# Type: "ans-checkpoint-v1",
# Stream: {"registry": "my-app", "log_id": "events"},
# Log: &hcs27.LogProfile{
# Algorithm: "sha-256",
# Leaf: "rfc6962-leaf",
# Merkle: "rfc6962-node",
# Root: hcs27.RootCommitment{
# TreeSize: 150,
# RootHashB64: "8zVIY3QJBOdTYR8dnLOzedEfym4Jl7f1xy8pciLEMew",
# Previous: &hcs27.PreviousCommitment{
# TreeSize: 100,
# RootHashB64: "kZ4L2bPe1sX...",
# BatchRange: {"start": 101, "end": 150},
result = client.publish_checkpoint(topicID, metadata, "batch 101-150")
fmt.printf("Published checkpoint (seq: %d, tx: %s)\n", result.SEQUENCE_NUMBER, result.TRANSACTION_I_D)
Notes
- If the serialized checkpoint exceeds 1024 bytes, the SDK automatically publishes the metadata via HCS-1 and replaces the inline payload with an
hcs://1/<topicId>reference plus ametadata_digestfor integrity verification. - The message
memofield must be under 300 characters.
Retrieve CheckpointsDirect link to Retrieve Checkpoints
- TypeScript
- Go
- Python
// Not yet available.
records, err := client.GetCheckpoints(ctx, topicID, nil)
if err != nil {
log.Fatal(err)
}
for _, record := range records {
fmt.Printf("Seq %d: root=%s treeSize=%d\n",
record.Sequence,
record.EffectiveMetadata.Root.RootHashB64,
record.EffectiveMetadata.Root.TreeSize,
)
}
records = client.get_checkpoints(topicID, None)
for record in records :
fmt.printf("Seq %d: root=%s treeSize=%d\n", record.SEQUENCE, record.EffectiveMetadata.Root.RootHashB64, record.EffectiveMetadata.Root.TreeSize)
Validate a Checkpoint ChainDirect link to Validate a Checkpoint Chain
- TypeScript
- Go
- Python
// Not yet available.
if err := hcs27.ValidateCheckpointChain(records); err != nil {
log.Fatalf("Chain validation failed: %v", err)
}
fmt.Println("Checkpoint chain is valid")
err = hcs27.validate_checkpoint_chain(records); err != nil {)
log.fatalf("Chain validation failed: %v", err)
fmt.println("Checkpoint chain is valid")
Resolve HCS-1 ReferencesDirect link to Resolve HCS-1 References
When checkpoint metadata overflows, the SDK stores it via HCS-1. You can resolve references manually:
- TypeScript
- Go
- Python
// Not yet available.
payload, err := client.ResolveHCS1Reference(ctx, "hcs://1/0.0.789012")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Resolved %d bytes of metadata\n", len(payload))
payload = client.resolve_h_c_s1_reference("hcs://1/0.0.789012")
fmt.printf("Resolved %d bytes of metadata\n", len(payload))