Registry / storage / ai-network-dag-client

ai-network-dag-client

JSON →
library1.2.5jsnpmunverified

JavaScript SDK for interacting with the AINetwork MerkleDAG gRPC service version 1.2.5. This package offers a promise-based API to add and retrieve content from a Merkle DAG, publish/subscribe to topics, and handle file uploads. Released as stable, it ships TypeScript types and supports Node.js >=14. Differentiators include simple API design, built-in event-based subscription handling, and file handling utilities.

npm install ai-network-dag-client
INSTALL
IMPORT
SIG · AI-NETWORK-DAG-CLI
A
ai-network-dag-client
storagejavascriptv1.2.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AINetworkDAGClient
import AINetworkDAGClient from 'ai-network-dag-client'
const { AINetworkDAGClient } = require('ai-network-dag-client')
Default export; named export not available in CommonJS require destructuring.
AINetworkDAGClient
import AINetworkDAGClient from 'ai-network-dag-client'
const AINetworkDAGClient = require('ai-network-dag-client').default
Default export; no .default property needed with ESM import.
AINetworkDAGClient
const AINetworkDAGClient = require('ai-network-dag-client')
CJS require returns the default export directly.

Demonstrates client instantiation, adding content, retrieving content, publishing, subscribing, and cleanup.

const AINetworkDAGClient = require('ai-network-dag-client'); async function main() { const client = new AINetworkDAGClient('localhost:50051'); // Add content const addRes = await client.add({ message: 'Hello, AINetwork DAG!', data: Buffer.from('Some data'), children: [] }); console.log('Added CID:', addRes.cid); // Get content const content = await client.get(addRes.cid); console.log('Retrieved message:', content.message); // Publish to a topic const pubRes = await client.publish('my-topic', 'Hello subscribers!'); console.log('Published:', pubRes.success); // Subscribe (example with event handling) const nodePk = 'your-public-key'; const subId = client.subscribe('my-topic', nodePk); client.on('publication', (data) => { console.log('Publication:', data); }); // Cleanup setTimeout(() => { client.unsubscribe(subId); client.close(); }, 60000); } main().catch(console.error);
Debug
Known issues
deprecatedThe package may not support Webpack or bundlers; designed for Node.js gRPC.
fix
Use only in Node.js environments; avoid bundlers.
affects: >=0.0.0
breakingConstructor expects serverAddress and optional credentials, but default credentials may change.
fix
Always pass credentials explicitly if requiring security.
affects: >=1.0.0
gotchaThe subscribe method requires nodePk (public key) but does not validate it.
fix
Ensure nodePk is a valid public key string; otherwise subscription may fail silently.
affects: >=1.0.0
gotchaEvent listeners ('publication', 'error', 'end') must be set before subscribe calls, or events may be missed.
fix
Attach event listeners before calling subscribe.
affects: >=1.0.0
deprecatedThe addFile method uses synchronous file reading; may block event loop.
fix
Use add with a Buffer to avoid blocking.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: AINetworkDAGClient is not a constructor
Using destructured require when default export is used
fix
Use `const AINetworkDAGClient = require('ai-network-dag-client')`
Error: 14 UNAVAILABLE: Connection refused
Server not running or wrong address
fix
Start the gRPC server or check the serverAddress.
TypeError: Cannot read properties of undefined (reading 'cid')
add() or get() returned undefined due to missing return
fix
Ensure async/await is used correctly and client is connected.
Upgrade
Version history
1.2.5latest on npm
Audit
Dependencies
@grpc/grpc-jsoptionalRequired to create gRPC credentials for secure connections.
Agent activity
42 hits · last 30 days
node
34
OpenAI (training)
1
Resources
ai-network-dag-client — npm install ai-network-dag-client · libregistry