/** * Core — Block heights and gas fees. * * Run: npx tsx examples/02-core.ts */ import { Spectrum } from '@spectrumnodes/sdk'; const spectrum = new Spectrum({ api: process.env.SPECTRUM_API! }); async function main() { // --- getBlockHeight --- const eth = await spectrum.core.getBlockHeight('ethereum'); console.log(`Ethereum block: ${eth.height}`); // --- getGasComparison --- const gas = await spectrum.core.getGasComparison(); console.log('\nGas comparison across EVM chains:'); for (const g of gas.results) { console.log(` ${g.chain}: ${g.baseFeeGwei} gwei, ~$${g.estimatedTxCostUsd} per tx`); } // --- getBlockTransactions --- const block = await spectrum.core.getBlockTransactions('ethereum', 21000000); console.log(`\nBlock 21M: ${block.transactionCount} transactions`); for (const tx of block.transactions.slice(0, 3)) { console.log(` ${tx.hash.slice(0, 20)}... from ${tx.from.slice(0, 12)}...`); } // --- estimateGas --- // Plain ETH transfer between EOAs. Pointing `to` at a contract without `data` // usually reverts (most contracts have no payable fallback). const VITALIK = '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045'; const estimate = await spectrum.core.estimateGas('ethereum', { to: VITALIK, from: VITALIK, value: '0x0', }); console.log(`\nGas estimate for simple call: ${estimate.gasEstimate}`); } main().catch(console.error);