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);
Errors
Common errors & fixes
TypeError: AINetworkDAGClient is not a constructor
Using destructured require when default export is used
fixUse `const AINetworkDAGClient = require('ai-network-dag-client')` Error: 14 UNAVAILABLE: Connection refused
Server not running or wrong address
fixStart the gRPC server or check the serverAddress.
TypeError: Cannot read properties of undefined (reading 'cid')
add() or get() returned undefined due to missing return
fixEnsure async/await is used correctly and client is connected.
Audit
Dependencies
@grpc/grpc-jsoptionalRequired to create gRPC credentials for secure connections.