Namespaces
The SDK organizes methods into 14 namespaces matching the API structure.
core
Block heights, gas prices, and gas estimation.
// Block height
await spectrum.core.getBlockHeight('ethereum');
// Block heights for multiple chains (parallel)
await spectrum.core.getBlockHeights(['ethereum', 'polygon', 'solana']);
// Gas comparison across all EVM chains
await spectrum.core.getGasComparison();
// All transactions in a block
await spectrum.core.getBlockTransactions('ethereum', 21000000);
// Gas estimation
await spectrum.core.estimateGas('ethereum', { to: '0xA0b8...' });tokens
Token metadata, balances, and multi-chain queries.
// Native balance
await spectrum.tokens.getBalance('ethereum', '0xd8dA...');
// Native balance pinned to a historical block
await spectrum.tokens.getBalance('ethereum', '0xd8dA...', { blockHeight: 19834521 });
// ERC-20/SPL token balance
await spectrum.tokens.getTokenBalance('ethereum', walletAddr, tokenAddr);
// ERC-20 balance at a historical block
await spectrum.tokens.getTokenBalance('ethereum', walletAddr, tokenAddr, { blockHeight: 19834521 });
// Token metadata (name, symbol, decimals, supply)
await spectrum.tokens.getMetadata('ethereum', '0xA0b8...');
// Native balance across multiple chains (parallel)
await spectrum.tokens.getBalanceMultiChain(
['ethereum', 'polygon', 'arbitrum'],
'0xd8dA...'
);contracts
Read contract state, batch reads via multicall, and simulate transactions.
// Read a contract function
const name = await spectrum.contracts.readContract('ethereum', {
address: '0xA0b8...',
abi: [{ name: 'name', inputs: [], outputs: [{ type: 'string' }], stateMutability: 'view', type: 'function' }],
functionName: 'name',
});
// Multicall: batch multiple reads in one request
const results = await spectrum.contracts.multicall('ethereum', {
calls: [
{ address: '0xA0b8...', abi: erc20Abi, functionName: 'name' },
{ address: '0xA0b8...', abi: erc20Abi, functionName: 'symbol' },
{ address: '0xA0b8...', abi: erc20Abi, functionName: 'decimals' },
],
});
// [{ status: 'success', result: 'USD Coin' }, ...]
// Simulate a transaction
await spectrum.contracts.simulateContract('ethereum', {
address: '0xA0b8...',
abi: [{ name: 'transfer', inputs: [{ type: 'address' }, { type: 'uint256' }], outputs: [{ type: 'bool' }], stateMutability: 'nonpayable', type: 'function' }],
functionName: 'transfer',
args: ['0xRecipient', 1000000n],
from: '0xSender',
});
// Check if address is a contract
await spectrum.contracts.getCode('ethereum', '0xA0b8...');
// Get contract bytecode at a historical block
await spectrum.contracts.getCode('ethereum', '0xA0b8...', { blockHeight: 19834521 });yields
DeFi yield data across lending, vaults, and staking.
// Lending rates (Aave, Compound, Morpho, HyperLend)
await spectrum.yields.getLending({ chain: 'ethereum', protocol: 'aave', pool: 'USDC' });
// Vault yields (Beefy, Yearn, Pendle, Hyperliquid)
await spectrum.yields.getVaults({ chain: 'ethereum', protocol: 'beefy' });
// Best yields ranked by APY
await spectrum.yields.getBest({ token: 'USDC', minTvl: 1_000_000, limit: 10 });
// User balance in a yield pool
await spectrum.yields.getBalance({ chain: 'ethereum', protocol: 'aave', pool: 'USDC', address: '0xd8dA...' });
// Pool token price
await spectrum.yields.getPrice({ chain: 'ethereum', protocol: 'aave', pool: 'USDC' });
// Pendle implied APY
await spectrum.yields.getPendleImpliedApy({ chain: 'ethereum', pool: '0x7d37...', address: '0xd8dA...' });prices
Token prices, historical data, and discovery.
// Current price
await spectrum.prices.getPrice('ETH');
// Price history (default 30 days, max 90)
await spectrum.prices.getPriceHistory('BTC', { days: 60 });
// Batch prices (max 100 symbols)
await spectrum.prices.getBatchPrices(['BTC', 'ETH', 'SOL', 'USDC']);
// Top tokens by market cap
await spectrum.prices.getTopPrices({ limit: 50 });
// Search tokens by name or symbol
await spectrum.prices.searchTokens('usdc', { limit: 20 });
// Get contract addresses for a token across chains
await spectrum.prices.getTokenAddresses('USDC');defi
DeFi protocol interactions: swaps, positions, approvals, and funding rates.
// Uniswap V3 swap quote
await spectrum.defi.getUniswapV3Quote('ethereum', {
tokenIn: '0xA0b8...', tokenOut: '0x6B17...', amount: '1000000', fee: 3000,
});
// V2 and V4 quotes
await spectrum.defi.getUniswapV2Quote('ethereum', { tokenIn, tokenOut, amount });
await spectrum.defi.getUniswapV4Quote('ethereum', { tokenIn, tokenOut, amount, fee: 3000, tickSpacing: 60 });
// Jupiter swap quote (Solana only)
await spectrum.defi.getJupiterQuote({ inputMint: 'So1...', outputMint: 'EPj...', amount: '1000000000' });
// Protocol positions (Aave v3/v2, Compound v3/v2, Morpho, Lido)
await spectrum.defi.getPosition('ethereum', 'aave-v3', '0xd8dA...');
await spectrum.defi.getPosition('ethereum', 'aave-v3', '0xd8dA...', { blockHeight: 19834521 });
// Curve pools and LlamaLend
await spectrum.defi.getCurvePools('ethereum');
await spectrum.defi.getCurveLlamaLendMarkets('ethereum');
await spectrum.defi.getCurveLlamaLendPosition('ethereum', '0xd8dA...');
// Pendle info
await spectrum.defi.getPendleInfo('ethereum');
// DeFi summary across all protocols
await spectrum.defi.getSummary('ethereum', '0xd8dA...');
// Token approvals (optionally at a historical block)
await spectrum.defi.getApprovals('ethereum', '0xd8dA...');
await spectrum.defi.getApprovals('ethereum', '0xd8dA...', { blockHeight: 19834521 });
await spectrum.defi.getRevokeTransaction('ethereum', '0xd8dA...', {
token: '0xA0b8...', spender: '0x68b3...',
});
// Perpetual funding rates
await spectrum.defi.getAllFundingRates();
await spectrum.defi.getHyperliquidFunding({ coin: 'BTC' });
await spectrum.defi.getDydxFunding({ ticker: 'BTC-USD' });nfts
NFT metadata, ownership, and balances.
// Collection info
await spectrum.nfts.getCollection('ethereum', contractAddr);
await spectrum.nfts.getCollection('ethereum', contractAddr, { blockHeight: 19834521 });
// NFT metadata
await spectrum.nfts.getMetadata('ethereum', contractAddr, '1');
await spectrum.nfts.getMetadata('ethereum', contractAddr, '1', { blockHeight: 19834521 });
// NFT owner
await spectrum.nfts.getOwner('ethereum', contractAddr, '1');
// NFT balance (count)
await spectrum.nfts.getBalance('ethereum', contractAddr, walletAddr);
await spectrum.nfts.getBalance('ethereum', contractAddr, walletAddr, { blockHeight: 19834521 });
// List owned token IDs (ERC-721 Enumerable)
await spectrum.nfts.getOwnedTokens('ethereum', contractAddr, walletAddr);
// ERC-1155 balance
await spectrum.nfts.getTokenBalance('ethereum', contractAddr, walletAddr, '1');
// ERC-1155 batch balance (max 100 pairs)
await spectrum.nfts.getBatchBalance('ethereum', contractAddr, { addresses, tokenIds });ens
Ethereum Name Service resolution.
// Forward resolve: name to address
const result = await spectrum.ens.resolve('vitalik.eth');
console.log(result.address); // 0xd8dA6BF...
// Reverse resolve: address to name
const reverse = await spectrum.ens.reverse('0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045');
console.log(reverse.name); // vitalik.ethregistry
Protocol metadata, contract addresses, and ABIs.
// List all protocols (optionally filter by category or chain)
await spectrum.registry.getProtocols({ category: 'lending' });
await spectrum.registry.getProtocols({ chain: 'ethereum' });
// Protocol details
await spectrum.registry.getProtocol('aave-v3');
// Protocol contract ABIs and addresses
await spectrum.registry.getProtocolContracts('aave-v3', { chain: 'ethereum' });
// Resolve a specific contract address
await spectrum.registry.getAddress('aave-v3', 'pool', 'ethereum');
// List all categories and chains
await spectrum.registry.getCategories();
await spectrum.registry.getChains();jsonRpc
Send raw JSON-RPC 2.0 requests directly to the API. Supports both single requests and batches (max 50).
// Single request
const result = await spectrum.jsonRpc({
jsonrpc: '2.0',
method: 'getBlockHeight',
params: { chain: 'ethereum' },
id: 1,
});
// Batch request (max 50)
const [heightResult, balanceResult] = await spectrum.jsonRpc([
{ jsonrpc: '2.0', method: 'getBlockHeight', params: { chain: 'ethereum' }, id: 1 },
{ jsonrpc: '2.0', method: 'getBalance', params: { chain: 'ethereum', address: '0xd8dA...' }, id: 2 },
]) as JsonRpcResponse[];
// Common pattern: fetch heights, then pin a balance to the same block
const ethHeight = await spectrum.core.getBlockHeight('ethereum');
const batch = await spectrum.jsonRpc([
{ jsonrpc: '2.0', method: 'getBlockHeight', params: { chain: 'base' }, id: 1 },
{
jsonrpc: '2.0',
method: 'getBalance',
params: { chain: 'ethereum', address: '0xd8dA...', blockHeight: ethHeight.height },
id: 2,
},
]);solana
Solana-specific convenience methods. These wrap the RPC proxy with typed responses.
// Current slot and block height
await spectrum.solana.getSlot();
await spectrum.solana.getBlockHeight();
// SOL balance (in SOL, not lamports)
await spectrum.solana.getBalance('7xKXtg...');
await spectrum.solana.getBalanceLamports('7xKXtg...');
// Account info
await spectrum.solana.getAccountInfo('7xKXtg...');
// All SPL token accounts for a wallet
const tokens = await spectrum.solana.getTokenAccountsByOwner('7xKXtg...');
for (const t of tokens) {
const info = t.account.data.parsed.info;
console.log(`${info.mint}: ${info.tokenAmount.uiAmountString}`);
}
// Transaction by signature
await spectrum.solana.getTransaction('5j7s8...');
// Recent signatures for an address
await spectrum.solana.getSignaturesForAddress('7xKXtg...', { limit: 10 });
// Latest blockhash
const { blockhash, lastValidBlockHeight } = await spectrum.solana.getLatestBlockhash();
// Rent exemption, epoch info, token supply
await spectrum.solana.getMinimumBalanceForRentExemption(165);
await spectrum.solana.getEpochInfo();
await spectrum.solana.getTokenSupply('EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v');
// Send any Solana RPC method
await spectrum.solana.request({ method: 'getVoteAccounts' });rpc
Raw JSON-RPC passthrough to any chain’s native RPC.
// EVM
await spectrum.rpc.send('ethereum', 'eth_blockNumber', []);
await spectrum.rpc.send('ethereum', 'eth_getBalance', [address, 'latest']);
// Solana
await spectrum.rpc.send('solana', 'getSlot', []);
// Bitcoin
await spectrum.rpc.send('bitcoin', 'getblockchaininfo', []);
data
Logs, transfers, receipts, portfolio, traces, and chain health.
// Event logs with pagination
await spectrum.data.getLogs('ethereum', { address: '0xA0b8...', topic0: '0xddf252ad...' });
// ERC-20 transfers for an address
await spectrum.data.getTransfers('ethereum', '0xd8dA...');
// Transaction receipt
await spectrum.data.getReceipt('ethereum', '0x5c504ed4...');
// Portfolio (native + tokens with USD prices)
await spectrum.data.getPortfolio('ethereum', '0xd8dA...');
await spectrum.data.getPortfolio('ethereum', '0xd8dA...', { blockHeight: 19834521 });
// Chain health
await spectrum.data.getChainHealth('ethereum');
// Transaction trace
await spectrum.data.traceTransaction('ethereum', '0x5c504ed4...');
// Historical balance (requires archive node)
await spectrum.data.getHistoricalBalance('ethereum', '0xd8dA...', 20000000);
// ERC-20 allowance
await spectrum.data.getAllowance('ethereum', '0xA0b8...', { owner: '0xd8dA...', spender: '0x68b3...' });
await spectrum.data.getAllowance('ethereum', '0xA0b8...', { owner: '0xd8dA...', spender: '0x68b3...', blockHeight: 19834521 });Client-level methods
// Execute multiple calls in parallel
const [ethBlock, polyBlock, gas] = await spectrum.parallel(
spectrum.core.getBlockHeight('ethereum'),
spectrum.core.getBlockHeight('polygon'),
spectrum.core.getGasComparison(),
);
// Set/get default chain
spectrum.setChain('ethereum');
console.log(spectrum.getChain()); // 'ethereum'
// SDK performance metrics
const metrics = spectrum.getMetrics();
// { totalRequests, cacheHits, cacheMisses, errors, avgResponseTime }
// Clear response cache
spectrum.clearCache();
// Clean up resources when done
spectrum.destroy();