Package Exports
- @hashgraphonline/standards-sdk
Readme
Hashgraph Consensus Standards SDK
This SDK provides reference implementations for Hashgraph Consensus Standards (HCS) created by Hashgraph Online.
Supported Standards
Standard | Description | Environments |
---|---|---|
HCS-3 | Recursion for Inscribed Files | Browser (WebAssembly, HTML5) |
HCS-7 | Dynamic, Programmable, and 100% on-graph assets | Node.js, Browser (EVM, WebAssembly) |
HCS-10 | Trustless, peer to peer communication for AI Agents | Node.js, Browser |
Installation
npm install @hashgraphonline/standards-sdk
Running Demos
The SDK includes demo implementations showcasing various features. To run the demos:
- Clone the repository
- Install dependencies:
npm install
- Set up your environment variables:
cp .env.example .env
- Edit
.env
with your credentials:
API_KEY=your_api_key_here
ACCOUNT_ID=0.0.12345
PRIVATE_KEY=your_private_key_here
NETWORK=testnet
- Run the demos:
# Run the Inscribe Demo
npm run demo
# Run the HCS-10 Demo
npm run demo:hcs-10
Available Demos
Inscribe Demo (
demo/inscribe-demo.ts
): Demonstrates file inscription capabilities- Text inscription
- URL inscription
- Buffer inscription
- Hashinal NFT creation (from URL, buffer, and text)
- Manual inscription retrieval
HCS-10 Demo (
demo/hcs-10/index.ts
): Demonstrates AI agent communication- Agent setup and registration
- Connection establishment between agents
- Message exchange
- Request monitoring
- Agent metadata management
Usage
Inscribing Files
import { inscribe } from '@hashgraphonline/standards-sdk';
// Inscribe from URL
const urlResult = await inscribe(
{
type: 'url',
url: 'https://example.com/file.json',
},
{
network: 'mainnet',
accountId: '0.0.123456',
privateKey: 'your-private-key',
},
{
mode: 'file',
metadata: {
name: 'My File',
description: 'A JSON file',
},
}
);
// Inscribe from local file
const fileResult = await inscribe(
{
type: 'file',
path: './path/to/file.json',
},
{
network: 'mainnet',
accountId: '0.0.123456',
privateKey: 'your-private-key',
},
{
mode: 'file',
}
);
// Inscribe from buffer
const bufferResult = await inscribe(
{
type: 'buffer',
buffer: fileBuffer,
fileName: 'file.json',
mimeType: 'application/json',
},
{
network: 'mainnet',
accountId: '0.0.123456',
privateKey: 'your-private-key',
},
{
mode: 'file',
}
);
HCS-7: Smart Contract State Processing
import { HCS7 } from '@hashgraphonline/standards-sdk';
// Initialize EVM Bridge to read smart contract state
const evmBridge = new HCS7.EVMBridge('mainnet-public');
// Read state from a smart contract
const contractState = await evmBridge.executeCommand({
p: 'evm',
op: 'read',
m: 'latestRoundData',
c: {
contractAddress: '0x...', // Your contract address
abi: {
name: 'latestRoundData',
inputs: [],
outputs: [
{ name: 'roundId', type: 'uint80' },
{ name: 'answer', type: 'int256' },
{ name: 'startedAt', type: 'uint256' },
{ name: 'updatedAt', type: 'uint256' },
{ name: 'answeredInRound', type: 'uint80' },
],
stateMutability: 'view',
type: 'function',
},
},
});
// Process state using WASM
const wasmBridge = new HCS7.WasmBridge();
await wasmBridge.initWasm(wasmBytes);
const result = await wasmBridge.executeCommand({
p: 'wasm',
op: 'process',
m: 'process_state',
c: {
wasmTopicId: '0.0.123456',
inputType: {
stateData: contractState,
},
outputType: {
type: 'json',
format: 'string',
},
},
});
HCS-3: Recursive Content Loading
import { HCS3 } from '@hashgraphonline/standards-sdk';
// Initialize HCS-3 with configuration
const hcs = new HCS3.HCS({
cdnUrl: 'https://kiloscribe.com/api/inscription-cdn/',
network: 'mainnet',
retryAttempts: 3,
retryBackoff: 300,
debug: false,
});
// Load specific content types
await hcs.loadScript('hcs://1/0.0.123456');
await hcs.loadImage('hcs://1/0.0.123456');
await hcs.loadVideo('hcs://1/0.0.123456');
await hcs.loadAudio('hcs://1/0.0.123456');
await hcs.loadGLB('hcs://1/0.0.123456');
HCS-10: AI Agent Communication
import { HCS10 } from '@hashgraphonline/standards-sdk';
// Initialize HCS-10 SDK
const sdk = new HCS10.SDK({
network: 'mainnet',
topicId: '0.0.123456',
});
// Send message to AI agent
await sdk.sendMessage({
type: 'command',
content: 'Process this data',
metadata: {
agentId: 'agent-123',
timestamp: Date.now(),
},
});
Contributing
- Fork the repository.
- Create a new feature branch.
- Implement your changes.
- Submit a pull request.
Resources
License
Apache-2.0