@hashgraphonline/standards-agent-kit
Version:
A modular SDK for building on-chain autonomous agents using Hashgraph Online Standards, including HCS-10 for agent discovery and communication.
79 lines (72 loc) • 2.67 kB
text/typescript
import { z } from 'zod';
import { BaseHCS6TransactionTool } from './base-hcs6-tools';
import { HCS6TransactionToolParams } from './hcs6-tool-params';
import type { TransactionResponse } from 'hedera-agent-kit';
/**
* Schema for registering a dynamic hashinal
*/
const RegisterDynamicHashinalSchema = z.object({
metadata: z.record(z.unknown())
.describe('Metadata object for the hashinal (e.g., name, description, attributes)'),
data: z.object({
base64: z.string().optional().describe('Base64 encoded data for the hashinal'),
url: z.string().optional().describe('URL to fetch data from'),
mimeType: z.string().optional().describe('MIME type of the data'),
}).optional()
.describe('Data to inscribe with the hashinal'),
memo: z.string()
.optional()
.describe('Optional memo for the registration'),
ttl: z.number()
.min(3600)
.default(86400)
.describe('Time-to-live in seconds for the inscription'),
registryTopicId: z.string()
.optional()
.describe('Registry topic ID to use. If not provided, a new registry will be created'),
submitKey: z.string()
.optional()
.describe('Submit key for the registry (required if registry has a submit key)'),
});
export type RegisterDynamicHashinalInput = z.infer<typeof RegisterDynamicHashinalSchema>;
/**
* Tool for registering (creating) dynamic hashinals
*/
export class RegisterDynamicHashinalTool extends BaseHCS6TransactionTool<typeof RegisterDynamicHashinalSchema> {
name = 'registerDynamicHashinal';
description = 'Create and register a new dynamic hashinal that can be updated over time';
schema = RegisterDynamicHashinalSchema;
constructor(params: HCS6TransactionToolParams) {
super(params);
}
protected async _call(
params: RegisterDynamicHashinalInput
): Promise<TransactionResponse> {
try {
const result = await this.hcs6Builder.register({
metadata: params.metadata,
data: params.data,
memo: params.memo,
ttl: params.ttl,
registryTopicId: params.registryTopicId,
submitKey: params.submitKey,
});
if (!result.success || !result.registryTopicId || !result.inscriptionTopicId) {
throw new Error(result.error || 'Failed to register dynamic hashinal');
}
return {
status: 'success',
data: {
registryTopicId: result.registryTopicId,
inscriptionTopicId: result.inscriptionTopicId,
transactionId: result.transactionId,
},
};
} catch (error) {
return {
status: 'error',
message: error instanceof Error ? error.message : 'Unknown error',
};
}
}
}