Skip to content

Commit 74e4f96

Browse files
authored
Merge pull request #12 from nansen-ai/repo-url-and-x402-handling
Update repo URLs and handle x402 payments
2 parents ee258a5 + 8c1d2d5 commit 74e4f96

File tree

7 files changed

+29
-11
lines changed

7 files changed

+29
-11
lines changed

.changeset/config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
3-
"changelog": ["@changesets/changelog-github", { "repo": "askeluv/nansen-cli" }],
3+
"changelog": ["@changesets/changelog-github", { "repo": "nansen-ai/nansen-cli" }],
44
"commit": false,
55
"fixed": [],
66
"linked": [],
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"nansen-cli": minor
3+
---
4+
5+
Add x402 payment required handling. HTTP 402 responses now return a `PAYMENT_REQUIRED` error code with decoded payment requirements (network, amount, asset, payTo) from the x402 protocol.

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55
### Minor Changes
66

7-
- [`7dd9845`](https://github.com/askeluv/nansen-cli/commit/7dd984581e6d3babd16060aa344cdf8495c866e4) Thanks [@askeluv](https://github.com/askeluv)! - Add missing endpoints to align with Python SDK:
7+
- [`7dd9845`](https://github.com/nansen-ai/nansen-cli/commit/7dd984581e6d3babd16060aa344cdf8495c866e4) Thanks [@askeluv](https://github.com/askeluv)! - Add missing endpoints to align with Python SDK:
88

99
- token info: Get detailed token information
1010
- perp screener: Screen perpetual futures contracts
1111
- perp leaderboard: Perpetual futures PnL leaderboard
1212
- points leaderboard: Nansen Points leaderboard
1313

14-
- [`778fb71`](https://github.com/askeluv/nansen-cli/commit/778fb71ed56cf32c06376e5263af36c57c34a18b) Thanks [@askeluv](https://github.com/askeluv)! - Add subcommand-specific help and command aliases
14+
- [`778fb71`](https://github.com/nansen-ai/nansen-cli/commit/778fb71ed56cf32c06376e5263af36c57c34a18b) Thanks [@askeluv](https://github.com/askeluv)! - Add subcommand-specific help and command aliases
1515

1616
- `nansen <command> <subcommand> --help` now shows detailed help including description, required/optional parameters with defaults, return fields, and working examples
1717
- `nansen <command> --help` lists all available subcommands
1818
- Added command aliases for faster typing: `tgm` (token), `sm` (smart-money), `prof` (profiler), `port` (portfolio)
1919

2020
### Patch Changes
2121

22-
- [#9](https://github.com/askeluv/nansen-cli/pull/9) [`3efc2ce`](https://github.com/askeluv/nansen-cli/commit/3efc2cef3322e192b02a6a4e8955e53f3c7c6ab4) Thanks [@0xlaveen](https://github.com/0xlaveen)! - fix: profiler pnl endpoint, token screener --search, help shows all subcommands
22+
- [#9](https://github.com/nansen-ai/nansen-cli/pull/9) [`3efc2ce`](https://github.com/nansen-ai/nansen-cli/commit/3efc2cef3322e192b02a6a4e8955e53f3c7c6ab4) Thanks [@0xlaveen](https://github.com/0xlaveen)! - fix: profiler pnl endpoint, token screener --search, help shows all subcommands
2323

2424
- `profiler pnl` now uses correct endpoint `/api/v1/profiler/address/pnl` (was using non-existent `/pnl-and-trade-performance`). Now supports `--date` and `--limit`.
2525
- `token screener --search PEPE` now filters results by token symbol/name (client-side, API doesn't support server-side search)
@@ -30,7 +30,7 @@
3030

3131
### Patch Changes
3232

33-
- [`1c3857f`](https://github.com/askeluv/nansen-cli/commit/1c3857fd019703ff1b4620f7feed4152d3234a6a) Thanks [@askeluv](https://github.com/askeluv)! - Fix repository URL in package.json (nansen-ai → askeluv)
33+
- [`1c3857f`](https://github.com/nansen-ai/nansen-cli/commit/1c3857fd019703ff1b4620f7feed4152d3234a6a) Thanks [@askeluv](https://github.com/askeluv)! - Fix repository URL in package.json (nansen-ai → askeluv)
3434

3535
All notable changes to this project will be documented in this file.
3636

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
"license": "MIT",
3535
"repository": {
3636
"type": "git",
37-
"url": "git+https://github.com/askeluv/nansen-cli.git"
37+
"url": "git+https://github.com/nansen-ai/nansen-cli.git"
3838
},
3939
"bugs": {
40-
"url": "https://github.com/askeluv/nansen-cli/issues"
40+
"url": "https://github.com/nansen-ai/nansen-cli/issues"
4141
},
42-
"homepage": "https://github.com/askeluv/nansen-cli#readme",
42+
"homepage": "https://github.com/nansen-ai/nansen-cli#readme",
4343
"engines": {
4444
"node": ">=18.0.0"
4545
},

src/__tests__/cli.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ describe('CLI Smoke Tests', () => {
113113
const output = stdout || stderr;
114114
const result = JSON.parse(output);
115115
expect(result.success).toBe(false);
116-
expect(result.code).toBe('UNAUTHORIZED');
116+
expect(['UNAUTHORIZED', 'PAYMENT_REQUIRED']).toContain(result.code);
117117
});
118118

119119
// =================== Error Handling ===================

src/api.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const ErrorCode = {
1919
UNAUTHORIZED: 'UNAUTHORIZED', // 401 - Invalid or missing API key
2020
FORBIDDEN: 'FORBIDDEN', // 403 - Valid key but insufficient permissions
2121
CREDITS_EXHAUSTED: 'CREDITS_EXHAUSTED', // 403 - Insufficient API credits
22+
PAYMENT_REQUIRED: 'PAYMENT_REQUIRED', // 402 - x402 payment required
2223

2324
// Rate Limiting
2425
RATE_LIMITED: 'RATE_LIMITED', // 429 - Too many requests
@@ -87,6 +88,8 @@ function statusToErrorCode(status, data = {}) {
8788
return ErrorCode.INVALID_PARAMS;
8889
case 401:
8990
return ErrorCode.UNAUTHORIZED;
91+
case 402:
92+
return ErrorCode.PAYMENT_REQUIRED;
9093
case 403:
9194
if (messageLower.includes('credit') || messageLower.includes('insufficient')) return ErrorCode.CREDITS_EXHAUSTED;
9295
return ErrorCode.FORBIDDEN;
@@ -484,6 +487,16 @@ export class NansenAPI {
484487
message = message.replace(/\.+$/, '') + '. This filter is not supported for this token/chain combination. Do not retry.';
485488
} else if (code === ErrorCode.CREDITS_EXHAUSTED) {
486489
message = message.replace(/\.+$/, '') + '. No retry will help. Check your Nansen dashboard for credit balance.';
490+
} else if (code === ErrorCode.PAYMENT_REQUIRED) {
491+
message = 'Payment required (x402). This endpoint requires on-chain payment.';
492+
const paymentHeader = response.headers.get('payment-required');
493+
if (paymentHeader) {
494+
try {
495+
data.paymentRequirements = JSON.parse(atob(paymentHeader));
496+
} catch {
497+
data.paymentRequiredRaw = paymentHeader;
498+
}
499+
}
487500
}
488501

489502
lastError = new NansenError(message, code, response.status, {

0 commit comments

Comments
 (0)