API Reference
Complete reference for all supported RPC methods and SDK features.
Supported Providers
runicRPC currently supports the following RPC providers with built-in configuration:
| Provider | HTTP | WebSocket | Auto-Config | Enhanced APIs | Status |
|---|---|---|---|---|---|
| Helius | Yes | Yes | API Key | DAS, Priority Fees | Fully Supported |
| Alchemy | Yes | Yes | API Key | Enhanced | Fully Supported |
| QuickNode | Yes | Yes | Custom URL | - | Fully Supported |
| Solana Public | Yes | Yes | None | - | Fully Supported |
| Triton | Yes | Yes | API Key | - | Fully Supported |
| GenesysGo | Yes | Yes | Custom URL | - | Fully Supported |
Supported RPC Methods
The SDK acts as a pass-through proxy for all standard Solana JSON-RPC methods. Below are the commonly used methods:
Auto-Cached Methods
These methods are automatically cached by runicRPC with configurable TTL:
const DEFAULT_CACHEABLE_METHODS = [
'getSlot',
'getBalance',
'getAccountInfo',
'getBlockHeight',
'getEpochInfo',
'getHealth',
'getVersion',
'getGenesisHash',
];
You can customize which methods are cached using the cacheableMethods config option:
const rpc = RunicRPC.create({
cache: {
enabled: true,
cacheableMethods: ['getSlot', 'getBalance', 'getBlockHeight'] // custom list
}
});
Account Methods
| Method | Description | Cached |
|---|---|---|
getBalance | Returns the balance of an account | Yes |
getAccountInfo | Returns all information associated with an account | Yes |
getTokenAccountsByOwner | Returns all SPL Token accounts by owner | No |
getProgramAccounts | Returns all accounts owned by a program | No |
getMultipleAccounts | Returns info for multiple accounts | No |
Block and Slot Methods
| Method | Description | Cached |
|---|---|---|
getSlot | Returns the slot that has reached the given commitment | Yes |
getBlockHeight | Returns the current block height | Yes |
getBlock | Returns identity and transaction info for a confirmed block | No |
getBlockTime | Returns the estimated production time of a block | No |
getBlocks | Returns a list of confirmed blocks between two slots | No |
Network Methods
| Method | Description | Cached |
|---|---|---|
getHealth | Returns the current health of the node | Yes |
getVersion | Returns the current Solana version | Yes |
getEpochInfo | Returns information about the current epoch | Yes |
getGenesisHash | Returns the genesis hash | Yes |
getClusterNodes | Returns information about cluster nodes | No |
getLeaderSchedule | Returns the leader schedule for an epoch | No |
Transaction Methods
| Method | Description | Cached |
|---|---|---|
getTransaction | Returns transaction details for a confirmed transaction | No |
getSignaturesForAddress | Returns signatures for confirmed transactions | No |
getLatestBlockhash | Returns the latest blockhash | No |
sendTransaction | Submits a signed transaction | No |
simulateTransaction | Simulates sending a transaction | No |
WebSocket Subscriptions
| Method | Description |
|---|---|
accountSubscribe | Subscribe to account changes |
logsSubscribe | Subscribe to transaction logs |
programSubscribe | Subscribe to program account changes |
signatureSubscribe | Subscribe to signature status changes |
slotSubscribe | Subscribe to slot changes |
rootSubscribe | Subscribe to root changes |
SDK API
RunicRPC Class
import { RunicRPC } from '@runic-rpc/sdk';
// Create instance
const rpc = RunicRPC.create(config?, options?);
// Make requests
const result = await rpc.request<T>(method: string, params?: unknown[]): Promise<T>;
// Batch requests (JSON-RPC 2.0)
const results = await rpc.batchRequest<T>(requests: BatchRequest[]): Promise<T[]>;
// Request to specific provider (for provider-specific APIs)
const result = await rpc.requestToProvider<T>(
provider: string,
method: string,
params?: unknown[]
): Promise<T>;
// Select endpoint for method (provider-specific routing)
const endpoint = rpc.selectEndpointForMethod(method: string): Endpoint;
// Subscribe (WebSocket)
const subId = await rpc.subscribe(method: string, params: unknown[], callback: (data: unknown) => void): Promise<number>;
// Unsubscribe
await rpc.unsubscribe(subscriptionId: number): Promise<void>;
// Get statistics
const stats = rpc.getStats(): GlobalStats;
// Export Prometheus metrics
const metrics = rpc.exportPrometheusMetrics(): string;
// Event listeners
rpc.on(event: string, listener: (data: unknown) => void): void;
rpc.off(event: string, listener: (data: unknown) => void): void;
// Cleanup
await rpc.close(): Promise<void>;
Batch Requests
Send multiple RPC calls in a single HTTP request:
interface BatchRequest {
method: string;
params?: unknown[];
}
const results = await rpc.batchRequest([
{ method: 'getSlot' },
{ method: 'getBalance', params: [publicKey] },
{ method: 'getBlockHeight' },
]);
// Results are returned in the same order as requests
const [slot, balance, blockHeight] = results;
Provider-Specific Routing
Route requests to specific providers for their enhanced APIs:
// Route Helius DAS calls to Helius
const assets = await rpc.requestToProvider('helius', 'getAssetsByOwner', [
{ ownerAddress: 'wallet-address' }
]);
// The SDK automatically routes known provider-specific methods
// Helius: getAssetsByOwner, getAsset, searchAssets, getPriorityFeeEstimate
// Alchemy: getTokenBalances, getTokenMetadata
Configuration Interface
interface RunicRPCConfig {
// Provider configurations
providers?: {
helius?: { apiKey: string };
alchemy?: { apiKey: string };
quicknode?: { rpcUrl: string; wsUrl?: string };
};
// Custom endpoints
endpoints?: EndpointConfig[];
// Routing strategy
strategy?: 'round-robin' | 'latency-based' | 'weighted' | 'random';
// Cache settings
cache?: {
enabled?: boolean;
ttl?: number; // milliseconds
maxSize?: number; // max entries
cacheableMethods?: string[]; // custom cacheable methods
};
// Retry settings
retry?: {
maxAttempts?: number;
initialDelay?: number;
maxDelay?: number;
backoffMultiplier?: number;
};
// Circuit breaker settings
circuitBreaker?: {
failureThreshold?: number;
successThreshold?: number;
timeout?: number;
};
// Health check settings
healthCheck?: {
enabled?: boolean;
interval?: number;
timeout?: number;
unhealthyThreshold?: number;
healthyThreshold?: number;
probeMethod?: string; // primary health check method (default: 'getHealth')
probeFallback?: string; // fallback method (default: 'getSlot')
};
// Middleware hooks
middleware?: {
beforeRequest?: (method: string, params?: unknown[]) => Promise<unknown[]>;
afterResponse?: <T>(method: string, result: T) => Promise<T>;
onError?: (method: string, error: Error) => Promise<void>;
};
// Rate limiting
rateLimit?: number; // requests per second
// Logging
logLevel?: 'debug' | 'info' | 'warn' | 'error';
}
Event Types
type RunicRPCEvent =
| { type: 'endpoint:healthy'; endpoint: string }
| { type: 'endpoint:unhealthy'; endpoint: string; reason: string }
| { type: 'endpoint:selected'; endpoint: string; method: string }
| { type: 'request:start'; method: string; params?: unknown[] }
| { type: 'request:success'; method: string; duration: number; endpoint: string }
| { type: 'request:error'; method: string; error: Error; endpoint: string }
| { type: 'request:retry'; method: string; attempt: number; endpoint: string }
| { type: 'request:deduplicated'; method: string }
| { type: 'cache:hit'; method: string }
| { type: 'cache:miss'; method: string }
| { type: 'circuit:open'; endpoint: string }
| { type: 'circuit:halfOpen'; endpoint: string }
| { type: 'circuit:closed'; endpoint: string }
| { type: 'ws:reconnect'; endpoint: string; attempt: number }
| { type: 'batch:start'; count: number }
| { type: 'batch:complete'; count: number; duration: number };
Error Classes
import {
RunicRpcError,
RpcRequestError,
CircuitBreakerOpenError,
HealthCheckError,
RateLimitError,
NoHealthyEndpointsError,
BatchRequestError,
ProviderNotFoundError,
} from '@runic-rpc/sdk';
Provider Helper Functions
import {
createHeliusEndpoint,
createAlchemyEndpoint,
createQuicknodeEndpoint,
createPublicEndpoint,
} from '@runic-rpc/sdk';
// Helius
const helius = createHeliusEndpoint('your-api-key');
// Alchemy
const alchemy = createAlchemyEndpoint('your-api-key');
// QuickNode
const quicknode = createQuicknodeEndpoint(
'https://your-endpoint.quiknode.pro/token/',
'wss://your-endpoint.quiknode.pro/token/'
);
// Public (rate limited)
const publicRpc = createPublicEndpoint();
Next Steps
- Try the API Playground to test methods interactively
- Configure routing strategies
- Set up WebSocket subscriptions