Skip to Content
TypeScript SDKConfiguration

Configuration

Basic

const spectrum = new Spectrum({ api: 'https://your-endpoint.simplystaking.xyz/YOUR_API_KEY/', });

Full options

const spectrum = new Spectrum({ api: 'https://your-endpoint.simplystaking.xyz/YOUR_API_KEY/', // full assigned endpoint URL defaultChain: 'ethereum', // optional: used when chain param omitted timeout: 30000, // request timeout in ms (default: 30000) retries: 3, // max retries on transient failure (default: 3) cache: { enabled: true, // default: true ttl: 5000, // default TTL in ms (default: 5000) maxEntries: 1024, // max cached responses (LRU eviction, default: 1024) }, hooks: { onRequest: ({ method, path }) => { console.log(`→ ${method} ${path}`); }, onResponse: ({ status, duration, path }) => { console.log(`← ${status} ${path} (${duration}ms)`); }, onError: ({ message, path }) => { console.error(`✗ ${path}:`, message); }, }, });

Smart cache defaults

The SDK uses intelligent per-endpoint cache TTLs:

Data typeDefault TTLReason
Block height0 (no cache)Changes every ~12s
Gas prices0 (no cache)Real-time pricing
Health checks0 (no cache)Must reflect current state
RPC calls0 (no cache)Arbitrary queries
DeFi yields60sUpdates periodically
Token metadata5 minRarely changes
Token prices60sUpdates periodically

You can override with a global TTL in the cache.ttl config, or disable caching entirely with cache.enabled: false.

Default chain

Set a default chain to avoid passing it on every call:

const spectrum = new Spectrum({ api: 'https://your-endpoint.simplystaking.xyz/YOUR_API_KEY/', defaultChain: 'ethereum', }); // No need to pass 'ethereum': uses default const block = await spectrum.core.getBlockHeight(); // Override per-call const solBlock = await spectrum.core.getBlockHeight('solana');

Change chain at runtime

spectrum.setChain('polygon'); // All subsequent calls use polygon const gas = await spectrum.core.getGasPrice(); console.log(spectrum.getChain()); // 'polygon'

Environment presets

Development

const spectrum = new Spectrum({ api: 'https://your-endpoint.simplystaking.xyz/YOUR_API_KEY/', cache: { enabled: false }, hooks: { onResponse: ({ status, duration, path }) => console.log(`${status} ${path} ${duration}ms`), }, });

Production

const spectrum = new Spectrum({ api: process.env.SPECTRUM_API!, retries: 5, cache: { ttl: 10000, maxEntries: 2048 }, });