This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
npm run build # Build with tsup (ESM output to dist/)
npm run dev # Watch mode build
npm test # Run tests (vitest)
npm run test:watch # Watch mode tests
npm run lint # Type-check without emit (tsc --noEmit)
npx vitest run src/__tests__/config.test.ts # Run a single test fileAfter building, test the CLI directly: node dist/index.js --help
This is a TypeScript ESM CLI wrapping the Chainbase Web3 API. Output is JSON by default (for AI agent consumption), with --pretty for human-readable format.
src/index.ts— Entry point. Registers all command groups on a Commander program with global options (--chain,--pretty,--page,--limit). Wraps execution in async error handler.src/client.ts—ChainbaseClientclass wrapping axios. Dual base URL routing: paths starting with/query/or/execution/go tohttps://api.chainbase.com/api/v1(SQL API), everything else goes tohttps://api.chainbase.online(Web3 API).createClient(opts)factory resolves API key and chain ID from config/env.src/config.ts— Config file management at~/.chainbase/config.json. Priority:CHAINBASE_API_KEYenv var > config file. Testable viaCHAINBASE_CONFIG_DIRenv var override.src/output.ts—formatOutput(data, pretty)writes JSON to stdout.formatError(msg, pretty)writes to stderr.src/types.ts— TypeScript interfaces for all API responses.
Each file in src/commands/ exports a createXxxCommand() function returning a Commander Command. Every command action:
- Gets global opts via
cmd.parent!.opts() - Calls
createClient(opts)to get an authenticated client + resolved chain ID - Calls
client.get()orclient.post()with the API path - Outputs via
formatOutput(result, opts.pretty)
| Group | File | Subcommands |
|---|---|---|
| config | commands/config.ts |
set, get, list |
| block | commands/block.ts |
latest, detail |
| tx | commands/tx.ts |
detail, list |
| contract | commands/contract.ts |
call |
| address | commands/address.ts |
labels |
| token | commands/token.ts |
metadata, transfers, holders, top-holders, price, price-history |
| nft | commands/nft.ts |
metadata, collection, collection-items, search, transfers, owner, owners, owner-history, floor-price, price-history, trending, rarity |
| balance | commands/balance.ts |
native, tokens, portfolios, nfts |
| domain | commands/domain.ts |
ens, ens-resolve, ens-reverse, spaceid-resolve, spaceid-reverse |
| sql | commands/sql.ts |
query, execute, status, results |
- Create
src/commands/yourgroup.tsexportingcreateYourGroupCommand() - Follow the pattern: import
createClient+formatOutput, define subcommands on anew Command('yourgroup') - Register in
src/index.tswithprogram.addCommand(createYourGroupCommand()) - API paths starting with
/query/or/execution/auto-route to the SQL base URL; all others go to Web3 base URL
- Auth:
x-api-keyheader on all requests - Chain IDs: 1 (Ethereum), 56 (BSC), 137 (Polygon), 42161 (Arbitrum), 10 (Optimism), 8453 (Base), 43114 (Avalanche), 324 (zkSync)
- Pagination: most list endpoints accept
page(default 1) andlimit(1-100, default 20) - SQL API classic (
/v1/dw/query) returns max 100k rows, 1k per page, task_id valid for 1 hour - SQL API alpha (
/query/execute) is async: execute → poll status → get results