hyra-client
v0.1.2
Published
Official Node.js SDK for the Hyra Network - a decentralized AI inference platform
Downloads
14
Maintainers
Readme
Hyra Node.js SDK
Official Node.js SDK for the Hyra Network - a decentralized AI inference platform powered by zero-knowledge proofs.
Installation
npm install hyra-client
# or
yarn add hyra-client
# or
pnpm add hyra-client
# or
bun add hyra-clientQuick Start
import { HyraClient } from 'hyra-client';
// Initialize the client with your private key
const privateKey = '0x...'; // Your Ethereum private key
const client = new HyraClient(privateKey);
// Claim a task
const task = await client.claimTask();
console.log('Task claimed:', task);
// Submit the task result
const txHash = await client.submitTask(task.taskId, 'Your AI inference result');
console.log('Task submitted:', txHash);API Reference
HyraClient
Main client class for interacting with the Hyra Network.
Constructor
constructor(privateKey: string)privateKey: Your Ethereum private key (must start with0x)
Methods
claimTask()
Claims an available task from the network. If you already have an active task, it returns the current task details.
Returns: Promise resolving to a task object with the following structure:
{
taskId: number;
taskPool: string;
reward: string; // Reward in ETH (formatted)
deadline: string; // ISO 8601 timestamp
assignedTo: string; // Wallet address
requestId: number;
model: {
id: number;
type: string;
url: string;
pricingType: number;
isActive: boolean;
createdAt: string; // ISO 8601 timestamp
tokenPrice: string; // Price in ETH (formatted)
};
inputRawData: string;
inputDecryptedData: string; // Decrypted input data for AI processing
}Example:
const task = await client.claimTask();
console.log('Task ID:', task.taskId);
console.log('Model:', task.model.type);
console.log('Input:', task.inputDecryptedData);submitTask(taskId: number, result: string)
Submits the result of a completed AI inference task. The result is encrypted and includes a zero-knowledge proof.
Parameters:
taskId: The ID of the task to submitresult: The AI inference result as a string
Returns: Promise resolving to the transaction hash (string)
Example:
const task = await client.claimTask();
// ... process the task with your AI model ...
const result = 'Your AI inference result here';
const txHash = await client.submitTask(task.taskId, result);
console.log('Transaction hash:', txHash);currentStatus()
Gets the current status of your active task.
Returns: Promise resolving to user status object:
{
activePool: string;
activeTaskId: bigint;
deadline: bigint;
reward: bigint;
hasActiveTask: boolean;
}Example:
const status = await client.currentStatus();
if (status.hasActiveTask) {
console.log('Active task ID:', status.activeTaskId);
console.log('Deadline:', new Date(Number(status.deadline) * 1000));
}supportedModels()
Get list of supported AI models (coming soon).
Features
- 🔐 Secure: End-to-end encryption for task data
- 🔒 Zero-Knowledge Proofs: ZKP verification for AI inference results
- ⚡ Fast: Optimized for performance
- 📦 TypeScript: Full TypeScript support with type definitions
- 🌐 Blockchain: Built on Ethereum-compatible networks
Requirements
- Node.js 18+ or Bun
- An Ethereum wallet with a private key
- Sufficient balance for gas fees
Network Configuration
The SDK is currently configured for the Hyra testnet:
- RPC URL:
https://rpc-testnet.hyra.network - Chain ID:
34131050525
Error Handling
All methods throw errors that should be caught:
try {
const task = await client.claimTask();
} catch (error) {
console.error('Error claiming task:', error.message);
}Common errors:
"No active task found": No task is currently assigned"Task ID mismatch": The task ID doesn't match your active task"Failed to decrypt input data": Decryption service error"Failed to generate proof": ZKP generation failed
Development
# Install dependencies
bun install
# Build the project
bun run build
# Run in development mode
bun run devLicense
MIT
Support
For issues and questions, please open an issue on the GitHub repository.
