Explore our growing ecosystem of DeAI applications in the awesome-aiforge repository.
Seamlessly integrate 0G Network's high-performance decentralized storage into your AI agents. Store models, persist state, and manage data with enterprise-grade reliability and performance.
Install the 0G Storage SDK and dependencies
npm install @0g/storage-sdk @aiforge/sdk
# Or with yarn
yarn add @0g/storage-sdk @aiforge/sdk
Set up the storage client with your credentials
import { ZeroGStorage } from '@0g/storage-sdk'
const storage = new ZeroGStorage({
apiKey: process.env.ZEROG_API_KEY,
network: '0g-mainnet', // or '0g-testnet'
endpoint: 'https://storage.0g.ai'
})
Connect storage to your AI agent
import { AIForge } from '@aiforge/sdk'
const agent = await AIForge.createAgent({
name: 'Storage-Enabled Agent',
storage: storage, // Pass storage instance
config: {
persistState: true,
modelVersioning: true,
backupInterval: 3600 // 1 hour
}
})
Upload and version your AI models
// Store AI model with metadata
const modelHash = await storage.uploadModel({
file: './my-model.bin',
metadata: {
name: 'Trading Bot v2.1',
type: 'neural-network',
accuracy: 0.95,
trainingData: 'crypto-prices-2024',
description: 'Advanced DeFi trading model'
},
tags: ['trading', 'defi', 'arbitrage']
})
console.log('Model stored with hash:', modelHash)
Retrieve and load your AI models
// Load model by hash
const model = await storage.loadModel(modelHash)
// Load latest version by name
const latestModel = await storage.loadLatestModel('Trading Bot')
// Initialize agent with stored model
agent.loadModel(model)
Save and restore agent state
// Save agent state
await agent.saveState({
portfolio: { USDC: 1000, ETH: 0.5 },
positions: [...currentPositions],
performance: { totalReturn: 0.15, sharpeRatio: 1.2 }
})
// Restore state on restart
const savedState = await agent.loadState()
agent.restoreState(savedState)
Store and query historical data
// Store trading data
await storage.storeAnalytics({
timestamp: Date.now(),
type: 'trade_executed',
data: {
pair: 'ETH/USDC',
amount: 0.5,
price: 2500,
profit: 12.50
}
})
// Query historical performance
const performance = await storage.queryAnalytics({
timeRange: '30d',
metrics: ['profit', 'trades', 'success_rate']
})
Track model versions with automatic metadata
Distributed storage with 99.9% uptime guarantee
Fast retrieval with global edge caching
Simple APIs with comprehensive documentation