hcs_write_record
Write tamper-evident compliance records to the Hedera blockchain for transactions, approvals, or audit events, providing record IDs and transaction proofs.
Instructions
Write a tamper-evident compliance record to the Hedera blockchain. Returns a record ID and transaction proof. If no topic_id is provided, writes to the shared HederaIntel platform topic. Costs 2 HBAR.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| api_key | Yes | Your HederaIntel API key | |
| record_type | Yes | Type of compliance record (e.g. transaction, approval, audit_event) | |
| entity_id | Yes | ID of the entity this record relates to | |
| data | Yes | The compliance data to record (any JSON object) | |
| topic_id | No | HCS topic ID to write the record to. Defaults to the HederaIntel platform topic. |
Implementation Reference
- src/modules/compliance/tools.js:80-121 (handler)The handler for hcs_write_record which creates a record object, computes its SHA-256 hash, submits it to a Hedera HCS topic, and returns the result.
if (name === "hcs_write_record") { const payment = chargeForTool("hcs_write_record", args.api_key); const client = getClient(); const topicId = args.topic_id || PLATFORM_TOPIC; const record = { record_id: crypto.randomUUID(), record_type: args.record_type, entity_id: args.entity_id, data: args.data, written_at: new Date().toISOString(), written_by: process.env.HEDERA_ACCOUNT_ID, }; const hash = crypto .createHash("sha256") .update(JSON.stringify(record)) .digest("hex"); record.hash = hash; const tx = await new TopicMessageSubmitTransaction() .setTopicId(topicId) .setMessage(JSON.stringify(record)) .execute(client); const receipt = await tx.getReceipt(client); return { success: true, record_id: record.record_id, topic_id: topicId, entity_id: args.entity_id, record_type: args.record_type, hash, transaction_id: tx.transactionId.toString(), written_at: record.written_at, verification_note: "This record is permanently stored on the Hedera blockchain and cannot be altered.", payment, timestamp: new Date().toISOString(), }; } - The schema definition for hcs_write_record.
{ name: "hcs_write_record", description: "Write a tamper-evident compliance record to the Hedera blockchain. Returns a record ID and transaction proof. If no topic_id is provided, writes to the shared HederaToolbox platform topic. Sends a webhook notification on every write. Costs 5 HBAR.", inputSchema: { type: "object", properties: { topic_id: { type: "string", description: "HCS topic ID to write the record to. Defaults to the HederaIntel platform topic." }, record_type: { type: "string", description: "Type of compliance record (e.g. transaction, approval, audit_event)" }, entity_id: { type: "string", description: "ID of the entity this record relates to" }, data: { type: "object", description: "The compliance data to record (any JSON object)" }, api_key: { type: "string", description: "Your HederaIntel API key" }, }, required: ["record_type", "entity_id", "data", "api_key"], }, },