Configuration and Integration
The Standards SDK provides flexible configuration options to integrate with various Hedera infrastructure providers and customize behavior for your specific needs.
Mirror Node Configuration
The SDK supports integration with custom mirror node providers beyond the default Hedera public mirror nodes. This enables enhanced performance, reliability, and access to specialized features.
Default & Custom Providers
Mirror Node Setup
Default
1import { HederaMirrorNode } from '@hashgraphonline/standards-sdk';23// Uses public Hedera mirror nodes4const mirrorNode = new HederaMirrorNode('mainnet', logger);5// Mainnet: https://mainnet-public.mirrornode.hedera.com6// Testnet: https://testnet.mirrornode.hedera.com
Configuration Options
The MirrorNodeConfig interface supports:
interface MirrorNodeConfig {
/** Custom mirror node URL. Can include <API-KEY> placeholder for URL-based API keys */
customUrl?: string;
/** API key for authentication. Used in both Authorization header and URL replacement */
apiKey?: string;
/** Additional custom headers to include with requests */
headers?: Record<string, string>;
}
Dynamic Configuration Updates
Runtime Configuration
Dynamic Switching
1const mirrorNode = new HederaMirrorNode('mainnet', logger);23// Switch to high-performance provider during peak usage4function switchToHighPerformanceMode() {5mirrorNode.configureMirrorNode({6 customUrl: 'https://premium-mirror.example.com/api',7 apiKey: process.env.PREMIUM_API_KEY,8 headers: {9 'X-Priority': 'high'10 }11});12}1314// Revert to standard configuration15function switchToStandardMode() {16mirrorNode.configureMirrorNode({17 customUrl: undefined, // Reverts to default Hedera mirror nodes18 apiKey: undefined,19 headers: {}20});21}
Retry Configuration
Customize retry behavior for network requests to handle transient failures:
Retry Logic
Retry Strategy
1// Configure retry settings2mirrorNode.configureRetry({3maxRetries: 5, // Maximum number of retry attempts4initialDelayMs: 500, // Initial delay between retries5maxDelayMs: 30000, // Maximum delay between retries6backoffFactor: 2 // Exponential backoff multiplier7});
Retry Strategy
The SDK implements intelligent retry logic:
- Automatic Retries: For network errors and 5xx server errors
- No Retry: For client errors (4xx) except rate limiting (429)
- Exponential Backoff: Delays increase exponentially with each retry
- Maximum Delay Cap: Prevents excessive wait times
Integration with HCS Protocols
Custom Mirror Nodes with Inscriptions & HCS-10
Protocol Integration
HCS-1 Inscription
1import { inscribe } from '@hashgraphonline/standards-sdk';23// Configure custom mirror node for inscriptions4const customConfig = {5network: 'mainnet',6mirrorNodeConfig: {7 customUrl: 'https://fast-mirror.example.com',8 apiKey: process.env.MIRROR_API_KEY9}10};1112const result = await inscribe(13{14 type: 'text',15 content: 'High-performance inscription',16 fileName: 'data.txt'17},18{19 ...customConfig,20 accountId: '0.0.123456',21 privateKey: 'your-private-key'22}23);
Environment-Based Configuration
Implement environment-aware configuration:
Environment Setup
Env Aware Factory
1import { HederaMirrorNode, Logger } from '@hashgraphonline/standards-sdk';23function createMirrorNode(network: 'mainnet' | 'testnet'): HederaMirrorNode {4const logger = new Logger({5 module: 'MirrorNode',6 level: process.env.LOG_LEVEL || 'info'7});89// Development environment10if (process.env.NODE_ENV === 'development') {11 return new HederaMirrorNode(network, logger);12}1314// Production environment with custom provider15if (process.env.NODE_ENV === 'production') {16 return new HederaMirrorNode(network, logger, {17 customUrl: process.env.MIRROR_NODE_URL,18 apiKey: process.env.MIRROR_NODE_API_KEY,19 headers: {20 'X-Environment': 'production',21 'X-Application': process.env.APP_NAME || 'standards-sdk-app'22 }23 });24}2526// Test environment with mocked responses27if (process.env.NODE_ENV === 'test') {28 return new HederaMirrorNode(network, logger, {29 customUrl: 'http://localhost:3000/mock-mirror',30 headers: {31 'X-Test-Mode': 'true'32 }33 });34}3536return new HederaMirrorNode(network, logger);37}
Performance Optimization
Connection Pooling & Batching
Optimization
Connection Pool
1// Create a pool of mirror node instances2class MirrorNodePool {3private pool: HederaMirrorNode[] = [];4private currentIndex = 0;56constructor(size: number, network: 'mainnet' | 'testnet', config: MirrorNodeConfig) {7 for (let i = 0; i < size; i++) {8 this.pool.push(new HederaMirrorNode(network, logger, config));9 }10}1112getNext(): HederaMirrorNode {13 const node = this.pool[this.currentIndex];14 this.currentIndex = (this.currentIndex + 1) % this.pool.length;15 return node;16}17}1819// Use the pool for load distribution20const mirrorPool = new MirrorNodePool(5, 'mainnet', {21customUrl: 'https://load-balanced-mirror.com',22apiKey: process.env.API_KEY23});2425// Get next available mirror node instance26const mirrorNode = mirrorPool.getNext();
Security Considerations
API Key Management & Secure Headers
Security
API Managing
1// Never hardcode API keys2const UNSAFE = { apiKey: 'sk_live_abc123...' }; // ❌ Never do this34// Use environment variables5const SAFE = { apiKey: process.env.MIRROR_NODE_API_KEY }; // ✅ Load from environment67// Validate API key presence8if (!process.env.MIRROR_NODE_API_KEY) {9throw new Error('MIRROR_NODE_API_KEY environment variable is required');10}
Monitoring and Debugging
Monitoring
Request Logging
1const logger = new Logger({2module: 'MirrorNode',3level: 'debug', // Enable debug logs4callback: (level, message, meta) => {5 if (meta?.url) {6 console.log(`Mirror Node Request: ${meta.url}`);7 }8}9});1011const mirrorNode = new HederaMirrorNode('testnet', logger, {12customUrl: process.env.DEBUG_MIRROR_URL13});
Next Steps
- Learn about HCS-10 Agent Communication for agent-specific configurations
- Explore Utilities and Services for more helper functions
- View Integration Examples on GitHub