This directory contains example scripts that demonstrate how to use the Glassnode API Node.js client.
Before running the examples:
- Make sure you have an API key from Glassnode
- Create a
.envfile in this directory with your API key:GLASSNODE_API_KEY=your_api_key_here - Install dependencies:
npm install
Demonstrates how to:
- Fetch and validate asset metadata
- Get a list of available metrics
- Fetch metadata for specific metrics (exchange balance example)
- Work with metric parameters
Run with:
npx ts-node ex.metadata.validation.tsShows how to:
- Fetch a list of all available metrics
- Get metadata for each metric
- Call metrics with parameters
- Process and display the results
Run with:
npx ts-node ex.metric.dump.tsDemonstrates the x402 paid API (no API key — you pay per call in USDC on Base):
- Build a payment-capable
fetchfrom a funded Base wallet (createX402Fetch) - Hit the metadata endpoint ($0.01) to confirm the asset + resolution are supported
- Fetch active addresses for the asset (default BTC), last 1 month at
24h($0.05) - Defaults to mainnet; point at a different x402 endpoint by setting
X402_API_URL
Defaults to BTC at 24h (active_count rejects 1h). The metric/asset/resolution are overridable
via env — see the script header; the metadata check skips the paid query if the asset isn't supported.
Set these in .env (see .env.example):
X402_PRIVATE_KEY=0xyour_funded_wallet_private_key
X402_MAX_PAYMENT=0.06 # optional, per-call USDC ceiling
X402_API_URL=https://x402.glassnode.com # x402 endpoint (mainnet); point elsewhere to use another
Wallet safety: use a dedicated, funded-but-limited wallet — never a primary key. On mainnet it spends real USDC; on a testnet endpoint fund the wallet with Base Sepolia test USDC.
X402_MAX_PAYMENTcaps each call, not total spend.
Run with:
npx ts-node ex.x402.active-addresses.tsThe examples use:
dotenv- For loading environment variablests-node- For running TypeScript files directlyzod- For schema validation (used in ex.metadata.validation.ts)@x402/fetch,@x402/evm,viem- For the x402 paid-API example (payment signing on Base)
To add a new example:
- Create a new TypeScript file in this directory
- Import the Glassnode API client:
import { GlassnodeAPI } from '../src' - Set up the client with your API key
- Implement your example code
- Run with
npx ts-node your-example-file.ts