SDK Overview
The Spectrum TypeScript SDK provides a typed, ergonomic client for the Spectrum API.
npm install @spectrum-nodes/sdkimport { Spectrum } from '@spectrum-nodes/sdk';
const spectrum = new Spectrum({ api: 'https://your-endpoint.simplystaking.xyz/YOUR_API_KEY/' });
const block = await spectrum.core.getBlockHeight('ethereum');
const balance = await spectrum.tokens.getBalance('ethereum', '0xd8dA...');
const lending = await spectrum.yields.getLending({ chain: 'ethereum', protocol: 'aave', pool: 'USDC' });Features
- Full TypeScript types for all requests and responses
- Built-in retry with exponential backoff
- Response caching with configurable TTLs
- Request/response hooks for logging and observability
- Zero dependencies: uses native
fetch
Namespaces
| Namespace | Description | Example |
|---|---|---|
spectrum.core | Blocks, gas, balances, health | core.getBlockHeight('ethereum') |
spectrum.tokens | Token metadata, balances, portfolio | tokens.getMetadata('ethereum', addr) |
spectrum.contracts | Read, simulate, and multicall contracts | contracts.readContract('ethereum', opts) |
spectrum.yields | DeFi lending, vault, and staking yields | yields.getLending({ chain, protocol, pool }) |
spectrum.prices | Token prices, history, and discovery | prices.getPrice('ETH') |
spectrum.defi | Swaps, positions, approvals, funding rates | defi.getUniswapV3Quote('ethereum', opts) |
spectrum.nfts | NFT metadata and ownership | nfts.getMetadata('ethereum', addr, id) |
spectrum.ens | ENS forward and reverse resolution | ens.resolve('vitalik.eth') |
spectrum.registry | Protocol metadata and contracts | registry.getProtocols() |
spectrum.jsonRpc() | Raw JSON-RPC 2.0 requests (single or batch, max 50) | spectrum.jsonRpc([{ jsonrpc: '2.0', method: 'getBlockHeight', params: { chain: 'ethereum' }, id: 1 }]) |
spectrum.solana | Solana-specific convenience methods | solana.getBalance('7xKXtg...') |
spectrum.rpc | Raw JSON-RPC passthrough | rpc.send('ethereum', 'eth_blockNumber') |
spectrum.data | Logs, receipts, traces, chain health | data.getLogs('ethereum', filter) |
Requirements
- Node.js >= 18 (uses native
fetch) - Works in browsers that support
fetchandAbortController