Try it now in Val Town
Interactive playground to test Nansen API calls
Click “Remix” to fork the playground, add your PAYER_KEYPAIR as an environment secret, and run live API calls.
Setup
First, set up your payment handler and wallet for Solana mainnet:
import {
  clusterApiUrl,
  Connection,
  Keypair,
  PublicKey,
} from "@solana/web3.js";
import { createLocalWallet } from "@faremeter/wallet-solana";
import { lookupKnownSPLToken } from "@faremeter/info/solana";
import {
  createPaymentHandler,
  lookupX402Network,
} from "@faremeter/payment-solana/exact";
import { wrap as wrapFetch } from "@faremeter/fetch";
// Load keypair from environment
const { PAYER_KEYPAIR } = process.env;
if (!PAYER_KEYPAIR) throw new Error("PAYER_KEYPAIR must be set");
const network = "mainnet-beta";
const x402Network = lookupX402Network(network);
// Lookup USDC mint address automatically
const usdcInfo = lookupKnownSPLToken(network, "USDC");
if (!usdcInfo) throw new Error("Could not find USDC mint");
const keypair = Keypair.fromSecretKey(
  Uint8Array.from(JSON.parse(PAYER_KEYPAIR)),
);
const connection = new Connection(clusterApiUrl(network));
const mint = new PublicKey(usdcInfo.address);
const wallet = await createLocalWallet(x402Network, keypair);
const fetchWithPayer = wrapFetch(fetch, {
  handlers: [createPaymentHandler(wallet, mint, connection)],
});
Example: Smart Money Net Flow
Query net flow data for smart money across multiple chains:
const url = "https://nansen.api.corbits.dev/api/v1/smart-money/netflow";
const payload = {
  chains: [
    "ethereum",
    "solana"
  ],
  filters: {
    exclude_smart_money_labels: [
      "30D Smart Trader"
    ],
    include_native_tokens: false,
    include_smart_money_labels: [
      "Fund",
      "Smart Trader"
    ],
    include_stablecoins: false
  },
  pagination: {
    page: 1,
    per_page: 10
  },
  order_by: [
    {
      field: "chain",
      direction: "ASC"
    }
  ]
};
const response = await fetchWithPayer(url, {
  method: "POST",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
  },
  body: JSON.stringify(payload),
});
if (!response.ok) {
  const text = await response.text().catch(() => "");
  throw new Error(`HTTP ${response.status} ${response.statusText} ${text}`);
}
const data = await response.json();
console.log("Smart Money Net Flow:", JSON.stringify(data, null, 2));
{
  "chains": ["ethereum", "solana"],
  "filters": {
    "exclude_smart_money_labels": ["30D Smart Trader"],
    "include_native_tokens": false,
    "include_smart_money_labels": ["Fund", "Smart Trader"],
    "include_stablecoins": false
  },
  "pagination": {
    "page": 1,
    "per_page": 10
  },
  "order_by": [
    {
      "field": "chain",
      "direction": "ASC"
    }
  ]
}
{
  "data": [
    {
      "token_address": "0x292fcdd1b104de5a00250febba9bc6a5092a0076",
      "token_symbol": "HASHAI",
      "net_flow_24h_usd": 0,
      "net_flow_7d_usd": 0,
      "net_flow_30d_usd": -664.0769939241275,
      "chain": "ethereum",
      "token_sectors": [
        "Artificial Intelligence"
      ],
      "trader_count": 1,
      "token_age_days": 546,
      "market_cap_usd": 25066236
    },
    {
      "token_address": "0x02e7f808990638e9e67e1f00313037ede2362361",
      "token_symbol": "KIBSHI",
      "net_flow_24h_usd": -1138.9147379448946,
      "net_flow_7d_usd": -1138.9147379448946,
      "net_flow_30d_usd": -5756.819664832803,
      "chain": "ethereum",
      "token_sectors": [
        "Memecoins",
        "AI Meme"
      ],
      "trader_count": 3,
      "token_age_days": 1027,
      "market_cap_usd": 7866435
    }
  ],
  "pagination": {
    "page": 1,
    "per_page": 10,
    "is_last_page": false
  }
}
Complete Example
import {
  clusterApiUrl,
  Connection,
  Keypair,
  PublicKey,
} from "@solana/web3.js";
import { createLocalWallet } from "@faremeter/wallet-solana";
import { lookupKnownSPLToken } from "@faremeter/info/solana";
import {
  createPaymentHandler,
  lookupX402Network,
} from "@faremeter/payment-solana/exact";
import { wrap as wrapFetch } from "@faremeter/fetch";
const { PAYER_KEYPAIR } = process.env;
if (!PAYER_KEYPAIR) throw new Error("PAYER_KEYPAIR must be set");
const network = "mainnet-beta";
const x402Network = lookupX402Network(network);
const usdcInfo = lookupKnownSPLToken(network, "USDC");
if (!usdcInfo) throw new Error("Could not find USDC mint");
const keypair = Keypair.fromSecretKey(
  Uint8Array.from(JSON.parse(PAYER_KEYPAIR)),
);
const connection = new Connection(clusterApiUrl(network));
const mint = new PublicKey(usdcInfo.address);
const wallet = await createLocalWallet(x402Network, keypair);
const fetchWithPayer = wrapFetch(fetch, {
  handlers: [createPaymentHandler(wallet, mint, connection)],
});
const url = "https://nansen.api.corbits.dev/api/v1/smart-money/netflow";
const payload = {
  chains: ["ethereum", "solana"],
  filters: {
    exclude_smart_money_labels: ["30D Smart Trader"],
    include_native_tokens: false,
    include_smart_money_labels: ["Fund", "Smart Trader"],
    include_stablecoins: false
  },
  pagination: { page: 1, per_page: 10 },
  order_by: [{ field: "chain", direction: "ASC" }]
};
const response = await fetchWithPayer(url, {
  method: "POST",
  headers: {
    Accept: "application/json",
    "Content-Type": "application/json",
  },
  body: JSON.stringify(payload),
});
if (!response.ok) {
  const text = await response.text().catch(() => "");
  throw new Error(`HTTP ${response.status} ${response.statusText} ${text}`);
}
const data = await response.json();
console.log("Smart Money Net Flow:", JSON.stringify(data, null, 2));
Available Filters
Smart Money Labels
Common labels you can include/exclude:
- "Fund"- Institutional investors
- "Smart Trader"- Successful traders
- "30D Smart Trader"- Recently active traders
- And more…
Filter Options
- include_smart_money_labels- Only show these labels
- exclude_smart_money_labels- Hide these labels
- include_native_tokens- Include native chain tokens (ETH, SOL)
- include_stablecoins- Include stablecoin data
Control response size:{
  "pagination": {
    "page": 1,
    "per_page": 10
  }
}
Sorting
Order results by field:
{
  "order_by": [
    {
      "field": "chain",
      "direction": "ASC"
    }
  ]
}
Payment Flow
When you make a request:
- Initial Request: Client sends API request
- 402 Response: Proxy returns payment requirements
{
  "accepts": [{
    "network": "solana-mainnet-beta",
    "maxAmountRequired": 1000,
    "asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "payTo": "corzHctjX9Wtcrkfxz3Se8zdXqJYCaamWcQA7vwKF7Q"
  }]
}
- Payment: Payment handler transfers 0.001 USDC on Solana
- Success: Proxy forwards request to Nansen with API key
All handled automatically byfetchWithPayer!
External Resources