npm install runes-sdk
The SDK can be configured with the following options:
interface SDKConfig {
rpcUrl: string; // RPC endpoint URL
wsUrl?: string; // Optional WebSocket URL
redis?: { // Optional Redis configuration
host: string;
port: number;
password?: string;
};
monitoring?: { // Optional monitoring configuration
enabled: boolean;
prometheusPort: number;
labels?: Record<string, string>;
};
}
class RunesSDK {
// Query transaction details
async getTransaction(txid: string): Promise<Transaction>;
// Connect to WebSocket server
connect(): void;
// Disconnect from WebSocket server
disconnect(): void;
}
interface Transaction {
transaction_id: string;
runes: RuneTransfer[];
block_height?: number;
confirmation_count: number;
timestamp: number;
network_type: 'Mainnet' | 'Testnet';
status: 'Pending' | 'Confirmed' | 'Failed';
}
interface RuneTransfer {
rune_id: string;
from_address: string;
to_address: string;
amount: string;
type: 'mint' | 'transfer' | 'burn';
fee?: string;
metadata?: Record<string, any>;
}
The SDK emits the following events:
sdk.on('connect', () => {
// WebSocket connected
});
sdk.on('disconnect', () => {
// WebSocket disconnected
});
sdk.on('transaction', (tx: Transaction) => {
// New transaction received
});
sdk.on('error', (error: Error) => {
// Error occurred
});
The following metrics are available when monitoring is enabled:
-
Transaction Metrics:
runes_transactions_total
: Total number of transactions processedrunes_transaction_errors_total
: Total number of transaction errorsrunes_transaction_processing_time_seconds
: Transaction processing time
-
WebSocket Metrics:
runes_websocket_connections
: Current number of WebSocket connectionsrunes_websocket_messages_total
: Total number of WebSocket messagesrunes_websocket_errors_total
: Total number of WebSocket errors
-
Cache Metrics:
runes_cache_hits_total
: Total number of cache hitsrunes_cache_misses_total
: Total number of cache missesrunes_cache_size_bytes
: Current cache size in bytes
Pre-configured Grafana dashboards are available in the deploy/grafana
directory:
transaction-dashboard.json
: Transaction monitoringwebsocket-dashboard.json
: WebSocket connection monitoringperformance-dashboard.json
: Performance metrics
try {
const tx = await sdk.getTransaction('txid');
} catch (error) {
if (error instanceof RunesError) {
// Handle SDK-specific errors
console.error('SDK Error:', error.message);
console.error('Error Code:', error.code);
} else {
// Handle other errors
console.error('Unexpected error:', error);
}
}
- Always handle WebSocket disconnections
- Implement proper error handling
- Monitor performance metrics
- Use appropriate timeouts
- Clean up resources when done
See the examples/
directory for complete usage examples:
examples/basic/transaction.ts
: Basic transaction queryingexamples/websocket/realtime.ts
: Real-time updatesexamples/monitoring/metrics.ts
: Metrics monitoring