nansen-cli 1.8.0 → 1.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CLAUDE.md DELETED
@@ -1,217 +0,0 @@
1
- # CLAUDE.md
2
-
3
- AI assistant guide for contributing to nansen-cli.
4
-
5
- ## What This Is
6
-
7
- A CLI for the [Nansen API](https://docs.nansen.ai), designed specifically for AI agents. All output is structured JSON. 30 endpoints across Smart Money, Profiler, Token God Mode, and Portfolio.
8
-
9
- ## Quick Start
10
-
11
- ```bash
12
- npm install
13
- npm test # Run mocked tests (no API key needed)
14
- npm run test:live # Run against live API (needs NANSEN_API_KEY)
15
- ```
16
-
17
- ## Project Structure
18
-
19
- ```
20
- src/
21
- ├── index.js # Thin CLI entry point (imports cli.js)
22
- ├── cli.js # CLI logic: parsing, routing, formatting, schema
23
- ├── api.js # NansenAPI class, all HTTP calls, validation
24
- └── __tests__/
25
- ├── unit.test.js # Core logic tests (validation, parsing, formatting)
26
- ├── api.test.js # API method tests with mocked fetch
27
- ├── cli.test.js # CLI integration tests (subprocess)
28
- ├── cli.internal.test.js # CLI unit tests (direct imports for coverage)
29
- └── coverage.test.js # Endpoint coverage verification
30
- ```
31
-
32
- **Three files, clear separation:**
33
- - `index.js` = Entry point (thin wrapper)
34
- - `cli.js` = CLI layer (parsing, routing, output formatting, schema)
35
- - `api.js` = API layer (HTTP, validation, config)
36
-
37
- ## Code Conventions
38
-
39
- - **ES modules** (`import`/`export`, not `require`)
40
- - **Async/await** for all API calls
41
- - **All output is JSON** (for AI agent consumption)
42
- - **No external dependencies** (just Node.js built-ins + vitest for tests)
43
-
44
- ## Adding a New Endpoint
45
-
46
- 1. **Add API method in `src/api.js`:**
47
- ```javascript
48
- async newEndpoint(params = {}) {
49
- const { chain = 'solana', filters = {}, orderBy, pagination } = params;
50
- return this.request('/api/v1/endpoint-path', {
51
- chain,
52
- filters,
53
- order_by: orderBy,
54
- pagination
55
- });
56
- }
57
- ```
58
-
59
- 2. **Add CLI handler in `src/index.js`:**
60
- ```javascript
61
- // In the appropriate command handler (smart-money, profiler, token, portfolio)
62
- 'new-subcommand': () => api.newEndpoint({ chains, filters, orderBy, pagination }),
63
- ```
64
-
65
- 3. **Add tests:**
66
- - `api.test.js` — Mock the fetch, verify request body
67
- - `cli.test.js` — Test CLI invocation
68
- - `coverage.test.js` — Add to `DOCUMENTED_ENDPOINTS`
69
-
70
- 4. **Update `README.md`** with docs
71
-
72
- ## Testing
73
-
74
- ```bash
75
- npm test # All tests, mocked
76
- npm run test:watch # Watch mode
77
- npm run test:coverage # With coverage report
78
- NANSEN_API_KEY=xxx npm run test:live # Live API tests
79
- ```
80
-
81
- **Test philosophy:**
82
- - Unit tests don't need API key (use mocked fetch)
83
- - Live tests are opt-in via `NANSEN_LIVE_TEST=1`
84
- - Coverage test ensures all documented endpoints have implementations
85
-
86
- ## Common Patterns
87
-
88
- ### Address Validation
89
- ```javascript
90
- // Validates EVM (0x...) or Solana (Base58) addresses
91
- const validation = validateAddress(address, chain);
92
- if (!validation.valid) throw new Error(validation.error);
93
- ```
94
-
95
- ### Date Ranges
96
- ```javascript
97
- // Most endpoints accept days param, converted to date range
98
- const to = new Date().toISOString().split('T')[0];
99
- const from = new Date(Date.now() - days * 24 * 60 * 60 * 1000).toISOString().split('T')[0];
100
- ```
101
-
102
- ### Retry Behavior
103
- - **Enabled by default** with 3 attempts
104
- - Retries on: 429, 500, 502, 503, 504, network errors
105
- - Exponential backoff with jitter (1s base, 30s max)
106
- - Respects `retry-after` headers
107
- - Disable with `--no-retry` or `options.retry = false`
108
- - Success responses include `_meta.retriedAttempts` if retried
109
-
110
- ### Response Format
111
- ```javascript
112
- // Success
113
- { "success": true, "data": { ... } }
114
-
115
- // Error
116
- { "success": false, "error": "message", "code": "ERROR_CODE", "status": 401, "details": { ... } }
117
- ```
118
-
119
- ### Schema Discovery
120
- ```bash
121
- nansen schema # Full schema (commands, options, types)
122
- nansen schema smart-money # Schema for specific command
123
- ```
124
- Returns JSON with all commands, subcommands, option types/defaults, return fields, supported chains, and smart money labels. No API key required.
125
-
126
- ### Field Filtering
127
- ```bash
128
- nansen research smart-money netflow --fields token_symbol,net_flow_usd,chain
129
- ```
130
- Reduces response size by including only specified fields. Works with nested data structures.
131
-
132
- ### Error Codes
133
- Structured error codes for programmatic handling:
134
-
135
- | Code | Description |
136
- |------|-------------|
137
- | `UNAUTHORIZED` | Invalid or missing API key (401) |
138
- | `FORBIDDEN` | Valid key but insufficient permissions (403) |
139
- | `CREDITS_EXHAUSTED` | Insufficient API credits (403) — do not retry |
140
- | `RATE_LIMITED` | Too many requests (429) |
141
- | `INVALID_ADDRESS` | Address format validation failed |
142
- | `INVALID_TOKEN` | Token address validation failed |
143
- | `INVALID_CHAIN` | Unsupported or invalid chain |
144
- | `INVALID_PARAMS` | Generic parameter validation error |
145
- | `MISSING_PARAM` | Required parameter not provided |
146
- | `UNSUPPORTED_FILTER` | Filter not supported for this token/chain (400) |
147
- | `NOT_FOUND` | Resource not found (404) |
148
- | `TOKEN_NOT_FOUND` | Token doesn't exist |
149
- | `ADDRESS_NOT_FOUND` | Address has no data |
150
- | `SERVER_ERROR` | Nansen API internal error (500+) |
151
- | `SERVICE_UNAVAILABLE` | API temporarily down (503) |
152
- | `NETWORK_ERROR` | Connection failed |
153
- | `TIMEOUT` | Request timed out |
154
- | `UNKNOWN` | Unclassified error |
155
-
156
- ## API Reference
157
-
158
- ### Chains
159
- `ethereum`, `solana`, `base`, `bnb`, `arbitrum`, `polygon`, `optimism`, `avalanche`, `linea`, `scroll`, `zksync`, `mantle`, `ronin`, `sei`, `plasma`, `sonic`, `unichain`, `monad`, `hyperevm`, `iotaevm`
160
-
161
- ### Smart Money Labels
162
- `Fund`, `Smart Trader`, `30D Smart Trader`, `90D Smart Trader`, `180D Smart Trader`, `Smart HL Perps Trader`
163
-
164
- ### Endpoints by Category
165
-
166
- **Smart Money (6):** netflow, dex-trades, perp-trades, holdings, dcas, historical-holdings
167
-
168
- **Profiler (11):** balance, labels, transactions, pnl, search, historical-balances, related-wallets, counterparties, pnl-summary, perp-positions, perp-trades
169
-
170
- **Token God Mode (12):** screener, holders, flows, dex-trades, pnl, who-bought-sold, flow-intelligence, transfers, jup-dca, perp-trades, perp-positions, perp-pnl-leaderboard
171
-
172
- **Portfolio (1):** defi-holdings
173
-
174
- ## Gotchas
175
-
176
- - **Perp endpoints** work with Hyperliquid (use `--symbol BTC` not `--token`)
177
- - **JUP DCA** is Solana-only
178
- - **Beta endpoints** (`/api/beta/...`) may have different pagination
179
- - **EVM vs Solana addresses** — validation auto-detects based on chain param
180
-
181
- ## Publishing (npm)
182
-
183
- **DO NOT manually run `npm version` or `npm publish`. CI handles everything.**
184
-
185
- 1. **Push to main** — CI runs tests
186
- 2. **CI creates a "Version Packages" PR** — bumps version + updates CHANGELOG
187
- 3. **Merge the Version PR** — CI auto-publishes to npm
188
-
189
- If you mess up: accidentally bumped version manually? `git revert` and add a changeset instead. CI publish failed? Check GitHub Actions logs, likely needs `NPM_TOKEN` secret refresh.
190
-
191
- ## Changesets
192
-
193
- Every PR that changes user-facing behavior **must** include a changeset file. `npm test` will warn if one is missing. The changeset description ends up in CHANGELOG.md (auto-generated by CI), so write it as a user-facing changelog entry.
194
-
195
- **Needs a changeset:** new features, bug fixes, breaking changes, changed CLI output, new/modified commands.
196
-
197
- **Does NOT need a changeset:** docs-only, test-only, refactors with no behavior change, CI/tooling.
198
-
199
- Add a file to `.changeset/` with a descriptive kebab-case name:
200
-
201
- ```markdown
202
- ---
203
- "nansen-cli": minor
204
- ---
205
-
206
- Short description of the change (appears in CHANGELOG)
207
- ```
208
-
209
- Use `patch` for bug fixes, `minor` for new features, `major` for breaking changes.
210
-
211
- ## PR Checklist
212
-
213
- - [ ] Tests pass (`npm test`)
214
- - [ ] New endpoints have tests in all 3 test files
215
- - [ ] README.md updated if adding user-facing features
216
- - [ ] Changeset added for user-facing changes (see above)
217
- - [ ] No new dependencies (keep it lightweight)
package/SKILL.md DELETED
@@ -1,136 +0,0 @@
1
- ---
2
- name: nansen-cli
3
- description: Query the Nansen API for onchain analytics - Smart Money flows, wallet profiling, token analysis, and DeFi portfolio data. Use when analyzing crypto wallets, tracking smart money activity, or researching tokens.
4
- license: MIT
5
- metadata:
6
- author: nansen-ai
7
- version: "1.3.0"
8
- compatibility: Requires Node.js 18+. Needs NANSEN_API_KEY environment variable or run `nansen login`.
9
- ---
10
-
11
- # Nansen CLI
12
-
13
- Command-line interface for the [Nansen API](https://docs.nansen.ai) - onchain analytics for crypto investors and AI agents.
14
-
15
- ## CLI vs Direct API
16
-
17
- If your agent has HTTP access (curl, fetch), you can skip the CLI and hit the [Nansen REST API](https://docs.nansen.ai) directly with `apiKey` header auth. The CLI is most useful for terminal-native agents (Claude Code, Codex, Cursor) that benefit from `--pretty`, `--table`, `--fields`, built-in retries, and schema introspection.
18
-
19
- ## Setup
20
-
21
- ```bash
22
- # Install globally
23
- npm install -g nansen-cli
24
-
25
- # Authenticate — pick the method that works for your context:
26
-
27
- # Option A: Non-interactive (best for agents — no prompts, no wasted credits)
28
- mkdir -p ~/.nansen && echo '{"apiKey":"YOUR_KEY","baseUrl":"https://api.nansen.ai"}' > ~/.nansen/config.json && chmod 600 ~/.nansen/config.json
29
-
30
- # Option B: Environment variable (good for CI/scripts)
31
- export NANSEN_API_KEY=your-api-key
32
-
33
- # Option C: Interactive login (burns 1 credit to validate)
34
- nansen login
35
- ```
36
-
37
- Get your API key at [app.nansen.ai/api](https://app.nansen.ai/api).
38
-
39
- ### Verify Installation
40
-
41
- ```bash
42
- # Free check (no API key needed):
43
- nansen schema | head -1
44
-
45
- # Full check (uses 1 credit):
46
- nansen token screener --chain solana --limit 1
47
- ```
48
-
49
- ## Commands
50
-
51
- ### Smart Money
52
- Track sophisticated market participants:
53
- ```bash
54
- nansen smart-money netflow --chain solana --pretty
55
- nansen smart-money dex-trades --chain solana --labels "Smart Trader"
56
- nansen smart-money holdings --chain solana
57
- ```
58
-
59
- ### Wallet Profiler
60
- Analyze any wallet:
61
- ```bash
62
- nansen profiler balance --address 0x123... --chain ethereum
63
- nansen profiler labels --address 0x123... --chain ethereum
64
- nansen profiler pnl --address 0x123... --chain ethereum
65
- nansen profiler search --query "Vitalik"
66
- ```
67
-
68
- ### Token God Mode
69
- Deep token analytics:
70
- ```bash
71
- nansen token screener --chain solana --timeframe 24h
72
- nansen token holders --token <address> --chain solana --smart-money
73
- nansen token flows --token <address> --chain solana
74
- nansen token pnl --token <address> --chain solana
75
- ```
76
-
77
- ### Portfolio
78
- DeFi holdings analysis:
79
- ```bash
80
- nansen portfolio defi --wallet 0x123...
81
- ```
82
-
83
- ## Output Formats
84
-
85
- - **Default**: JSON (for AI agents)
86
- - `--pretty`: Formatted JSON
87
- - `--table`: Human-readable table
88
- - `--stream`: NDJSON (one record per line)
89
- - `--fields`: Filter specific fields
90
-
91
- ## Key Options
92
-
93
- | Option | Description |
94
- |--------|-------------|
95
- | `--chain` | Blockchain (solana, ethereum, base, etc.) |
96
- | `--chains` | Multiple chains as JSON array |
97
- | `--limit` | Number of results |
98
- | `--days` | Date range in days |
99
- | `--sort` | Sort field (e.g., `value_usd:desc`) |
100
- | `--smart-money` | Filter for Smart Money only |
101
-
102
- ## Supported Chains
103
-
104
- ethereum, solana, base, bnb, arbitrum, polygon, optimism, avalanche, linea, scroll, mantle, ronin, sei, plasma, sonic, monad, hyperevm, iotaevm
105
-
106
- ## Smart Money Labels
107
-
108
- Fund, Smart Trader, 30D Smart Trader, 90D Smart Trader, 180D Smart Trader, Smart HL Perps Trader
109
-
110
- ## Schema Introspection
111
-
112
- Get the full API schema for programmatic use:
113
- ```bash
114
- nansen schema --pretty
115
- nansen schema smart-money --pretty
116
- ```
117
-
118
- ## Troubleshooting
119
-
120
- See [AGENTS.md — Troubleshooting](AGENTS.md#troubleshooting) for the full troubleshooting guide, including error codes, known endpoint quirks, and pagination gotchas.
121
-
122
- ## Examples
123
-
124
- ```bash
125
- # Find trending Solana tokens with Smart Money activity
126
- nansen token screener --chain solana --timeframe 24h --smart-money --pretty
127
-
128
- # Check who's accumulating a specific token
129
- nansen token holders --token So11111111111111111111111111111111111111112 --chain solana --smart-money --limit 20 --pretty
130
-
131
- # Profile a whale wallet
132
- nansen profiler balance --address Gu29tjXrVr9v5n42sX1DNrMiF3BwbrTm379szgB9qXjc --chain solana --pretty
133
-
134
- # Track Smart Money flows into memecoins
135
- nansen smart-money netflow --chain solana --labels "Smart Trader" --pretty
136
- ```
package/TODO.md DELETED
@@ -1,42 +0,0 @@
1
- # TODO
2
-
3
- > **Built by agents, for agents.** We prioritize improvements that create the best possible AI agent experience.
4
-
5
- ## P0 - Trading Agent Support
6
-
7
- ### Wallet Management
8
- - [ ] `nansen wallet create` — generate a local wallet (per chain), store key securely on disk
9
- - [ ] `nansen wallet address` — print the wallet address for funding
10
- - [ ] `nansen wallet balance` — check wallet balance
11
-
12
- ### Trading Execution
13
- - [x] `nansen quote` — get a quote for a DEX swap (chain, tokens, amount)
14
- - [x] `nansen execute` — sign and submit a trade via Nansen API (takes quote-id)
15
- - [ ] ⚠️ EVM transaction signing — requires thorough security review before production use
16
-
17
- > These commands are required for `nansen-trading-agent` — the autonomous trading sub-agent.
18
- > Wallet commands should keep the agent self-contained with zero external dependencies.
19
-
20
- ---
21
-
22
- ## P2 - Nice to Have
23
-
24
- ### Test Coverage Gaps
25
- - [ ] Test config priority chain (ENV > ~/.nansen > local) — needs `loadConfig()` exported
26
- - [ ] Add snapshot tests for `--help` output
27
- - [ ] Document magic test addresses (e.g. Binance hot wallet)
28
- - [ ] Test Bitcoin address validation
29
- - [ ] Test stdin pipe mode for API key input
30
-
31
- ### Shell Completions
32
- - [ ] Bash completions
33
- - [ ] Zsh completions
34
- - [ ] Fish completions
35
-
36
- ### Distribution
37
- - [ ] Homebrew formula (`brew install nansen-cli`)
38
- - [ ] Docker image
39
-
40
- ---
41
-
42
- *Last updated: 2026-02-06*
@@ -1,28 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Non-blocking check: warns if the current branch has no new changeset file
5
- * compared to main. Runs as a pretest hook so agents and humans see a reminder.
6
- * Always exits 0 — this is a nudge, not a gate.
7
- */
8
-
9
- import { execSync } from "child_process";
10
-
11
- try {
12
- const branch = execSync("git rev-parse --abbrev-ref HEAD", { encoding: "utf8" }).trim();
13
- if (branch === "main") process.exit(0);
14
-
15
- const newChangesets = execSync(
16
- "git diff main --name-only --diff-filter=A -- .changeset/*.md",
17
- { encoding: "utf8" }
18
- ).trim();
19
-
20
- if (!newChangesets) {
21
- console.error(
22
- "\x1b[33m[changeset] No new changeset file found on this branch. " +
23
- "If this PR changes user-facing behavior, add one: npx changeset\x1b[0m"
24
- );
25
- }
26
- } catch {
27
- // Not a git repo, main doesn't exist, etc. — skip silently.
28
- }
@@ -1,10 +0,0 @@
1
- import { defineConfig } from 'vitest/config';
2
-
3
- export default defineConfig({
4
- test: {
5
- globals: true,
6
- environment: 'node',
7
- include: ['src/**/*.e2e.test.js'],
8
- testTimeout: 120000,
9
- },
10
- });