AngorHub SDK is a comprehensive TypeScript/JavaScript library for interacting with the Angor ecosystem. It provides seamless access to project data, investment information, and Nostr integration with support for both mainnet and testnet networks.
🌐
Multi-Network Support
Works with both mainnet and testnet networks
⚙️
Flexible Configuration
Remote, manual, or default configuration modes
🔗
Nostr Integration
Enhanced project data with Nostr enrichment
⚡
High Performance
Built-in caching and concurrent request handling
🔧
TypeScript Support
Full type safety and IntelliSense support
📱
Universal Compatibility
Works in browsers, Node.js, React, Angular, and more
const sdk = new AngorHubSDK('mainnet', {
configMode: 'default'
});
🎮 Interactive Configuration Demo
Configuration Settings
SDK Status & Output
Ready to initialize...
Click "Initialize SDK" to start...
💡 Usage Examples
Basic SDK Initialization
Node.js / ES Modules
import { AngorHubSDK } from 'angorhub-sdk';
// Initialize SDK for mainnet
const sdk = new AngorHubSDK('mainnet');
// Initialize with custom configuration
const customSdk = new AngorHubSDK('testnet', {
enableNostr: true,
enableCache: true,
cacheTtl: 300000, // 5 minutes
maxRetries: 3,
timeout: 10000
});
Browser / Global Variable
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/angorhub-sdk@latest/dist/browser/angorhub-sdk.bundle.js"></script>
<script>
// SDK is available as AngorHubSDK.AngorHubSDK
const sdk = new AngorHubSDK.AngorHubSDK('mainnet');
</script>
const projectId = 'angor1qe8swvv3xu9dnf3q9q8v6cvc7x60kwums7c5r37';
// Get all investments for a project
const investments = await sdk.getProjectInvestments(projectId, 50, 0);
investments.forEach((investment, index) => {
console.log(`Investment ${index + 1}:`);
console.log(` Investor: ${investment.investorPublicKey}`);
console.log(` Amount: ${investment.totalAmount}`);
console.log(` Transaction: ${investment.transactionId}`);
console.log(` Is Seeder: ${investment.isSeeder}`);
});
Get Specific Investor Investment
const projectId = 'angor1qe8swvv3xu9dnf3q9q8v6cvc7x60kwums7c5r37';
const investorPublicKey = '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798';
try {
const investment = await sdk.getInvestorInvestment(projectId, investorPublicKey);
console.log('Investor investment:', investment);
} catch (error) {
console.log('No investment found for this investor');
}
🎮 Interactive Investments Demo
Enter a project ID and click "Get Investments"...
Nostr Integration
Nostr Enhancement: The SDK automatically enriches project data with Nostr metadata when enabled, providing additional information like project descriptions, founder profiles, and social links.
Enable Nostr Enrichment
const sdk = new AngorHubSDK('mainnet', {
enableNostr: true,
configMode: 'remote' // Uses remote relay configuration
});
// Projects will automatically include Nostr data
const projects = await sdk.getProjects();
projects.forEach(project => {
// Basic project data
console.log('Project ID:', project.projectIdentifier);
console.log('Founder:', project.founderKey);
// Enhanced Nostr data (if available)
if (project.projectInfo) {
console.log('Target Amount:', project.projectInfo.targetAmount);
console.log('Start Date:', new Date(project.projectInfo.startDate * 1000));
console.log('End Date:', new Date(project.projectInfo.endDate * 1000));
}
if (project.metadata) {
console.log('Project Name:', project.metadata.name);
console.log('Description:', project.metadata.about);
console.log('Website:', project.metadata.website);
console.log('Picture:', project.metadata.picture);
}
});
Manual Nostr Enrichment
// Get projects without automatic enrichment
const plainProjects = await sdk.getProjects();
// Manually enrich specific projects
const enrichedProjects = await sdk.enrichProjectsWithNostr(plainProjects.slice(0, 5));
console.log('Enriched projects:', enrichedProjects);
🎮 Interactive Nostr Demo
Click "Test Nostr Enrichment" to see enhanced data...
📚 API Reference
Constructor
new AngorHubSDK(
network: 'mainnet' | 'testnet',
config?: SDKConfig
)
Problem: CORS errors when making requests from the browser.
Solutions:
Use a CORS proxy server
Configure your server to handle CORS headers
For development: use browser extensions to disable CORS temporarily
Use the pre-built bundle that handles CORS better
// Use CDN bundle which handles CORS better
// <script src="https://cdn.jsdelivr.net/npm/angorhub-sdk@latest/dist/browser/angorhub-sdk.bundle.js"></script>
// Or configure a CORS proxy
const sdk = new AngorHubSDK('mainnet', {
configMode: 'manual',
manualIndexers: {
mainnet: ['https://cors-proxy.example.com/https://api.angor.io/']
}
});
2. Network Timeouts & Connection Issues
Problem: Requests timing out or failing intermittently.
Solutions:
// Increase timeout and enable retries
const sdk = new AngorHubSDK('mainnet', {
timeout: 15000, // 15 seconds
maxRetries: 5, // Retry failed requests
retryDelay: 2000, // Wait 2 seconds between retries
concurrentRequests: 5 // Reduce concurrent requests if network is slow
});
// Monitor health status
const health = sdk.getHealthStatus();
console.log('Healthy indexers:', health.healthyCount);
// Handle errors gracefully
try {
const projects = await sdk.getProjects();
} catch (error) {
if (error.message.includes('timeout')) {
console.log('Request timed out, trying with fewer results...');
const projects = await sdk.getProjects(5); // Try with fewer results
}
}
3. Nostr Connection Issues
Problem: Nostr enrichment not working or failing.
Solutions:
// Option 1: Disable Nostr if causing issues
const sdk = new AngorHubSDK('mainnet', {
enableNostr: false
});
// Option 2: Use custom reliable relays
const sdk = new AngorHubSDK('mainnet', {
enableNostr: true,
nostrRelays: [
'wss://relay.damus.io',
'wss://nos.lol',
'wss://relay.nostr.info'
]
});
// Option 3: Handle Nostr failures gracefully
const projects = await sdk.getProjects();
console.log('Projects loaded, Nostr data may be enriched asynchronously');
4. SDK Initialization Issues
Problem: SDK methods fail immediately after initialization or return unexpected results.
Solutions:
// Use proper initialization pattern
async function initializeSDK(network = 'mainnet', config = {}) {
const sdk = new AngorHubSDK(network, config);
// Wait for SDK to be ready by checking health status
let attempts = 0;
while (attempts < 20) {
try {
const health = sdk.getHealthStatus();
if (health.healthyCount > 0) {
return sdk; // SDK is ready
}
} catch (error) {
// Still initializing
}
await new Promise(resolve => setTimeout(resolve, 500));
attempts++;
}
return sdk; // Return anyway after max attempts
}
// Use it
const sdk = await initializeSDK('mainnet');
const projects = await sdk.getProjects();
5. Cache Issues
Problem: Stale data or cache taking too much memory.
Solutions:
// Configure cache settings
const sdk = new AngorHubSDK('mainnet', {
enableCache: true,
cacheTtl: 60000 // 1 minute cache (shorter for fresh data)
});
// Monitor cache size
const stats = sdk.getCacheStats();
console.log('Cache entries:', stats.sdkCache.size);
// Clear cache when needed
if (stats.sdkCache.size > 1000) {
sdk.clearCache();
console.log('Cache cleared due to size');
}
// Disable cache for real-time data
const freshProjects = await sdk.getProjects(10, 0, false); // useCache = false
6. TypeScript Issues
Problem: TypeScript compilation errors.
Solutions:
// Ensure proper imports
import { AngorHubSDK } from 'angorhub-sdk';
import type { AngorProject, AngorProjectDetails, SDKConfig } from 'angorhub-sdk';
// Type the config properly
const config: SDKConfig = {
configMode: 'manual',
manualIndexers: {
mainnet: ['https://api.angor.io/']
},
enableNostr: true,
timeout: 10000
};
const sdk = new AngorHubSDK('mainnet', config);
// Type assertions when needed
const projects = await sdk.getProjects() as AngorProject[];
Debugging Tips
Debug Configuration
// Enable detailed logging and monitoring
const sdk = new AngorHubSDK('mainnet', {
timeout: 10000,
maxRetries: 3,
enableCache: true
});
// Monitor SDK status
setInterval(() => {
const info = sdk.getConfigInfo();
const health = sdk.getHealthStatus();
const cache = sdk.getCacheStats();
console.log('SDK Status:', {
healthyIndexers: `${health.healthyCount}/${health.indexers.length}`,
activeRequests: info.activeRequests,
queuedRequests: info.queuedRequests,
cacheSize: cache.sdkCache.size
});
}, 30000); // Log every 30 seconds
Test Configuration
// Test different configuration modes
async function testConfiguration() {
const configs = [
{ mode: 'remote', name: 'Remote Config' },
{ mode: 'default', name: 'Default Config' }
];
for (const { mode, name } of configs) {
try {
console.log(`Testing ${name}...`);
const sdk = new AngorHubSDK('mainnet', { configMode: mode });
// Wait for initialization
await new Promise(resolve => setTimeout(resolve, 2000));
const projects = await sdk.getProjects(1);
console.log(`${name}: SUCCESS - Got ${projects.length} projects`);
const health = sdk.getHealthStatus();
console.log(`${name}: Healthy indexers: ${health.healthyCount}`);
} catch (error) {
console.error(`${name}: FAILED -`, error.message);
}
}
}
testConfiguration();