# @codex-data/sdk 中文文档

规范地址：https://npmcn.com/package/%40codex-data/sdk/

版本：2\.6\.3
npm 元数据更新时间：2026-11-10T02:12:36.365Z
中文译文更新时间：2026-11-10T08:22:28.178Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40codex-data/sdk
原文对照：https://npmcn.com/package/%40codex-data/sdk/?lang=original
项目主页：https://docs.codex.io/
源码仓库：https://github.com/Codex-Data/sdk

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：20.5 MB，39 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- Node.js 要求：\>=17\.5\.0
- 运行依赖：4 个
- peer 依赖：graphql ^16\.0\.0
- 首次发布：2024-08-27T21:01:48.555Z
- 最新版本发布：2026-11-10T02:12:35.993Z
- 近 30 天下载量：206276（2026-10-10 至 2026-11-08，npm 官方下载统计）
- 已发布版本数：121（近 12 个月 74 个）

## 中文简介

JavaScript/Typescript的代码SDK. 它提供了生成的类型和方便的方法来访问图克l api.

## 安装

```sh
npm install @codex-data/sdk
```

也可以使用：`pnpm add @codex-data/sdk`、`yarn add @codex-data/sdk`、`bun add @codex-data/sdk`

## README

# 代码 SDK

类型脚本 SDK [代码 API](https://www.codex.io/) ——实时区块链数据,信使价格,OHLCV图表,钱包余额,以及持有者对包括埃特鲁姆,索拉纳,基地,Arbitrum,BNB,和多边形在内的80+网络的60M+信使的解析.

Codex是Coinbase,TradingView,Uniswap,Rainbow,FOMO,Farcaster等数以百计的团队使用的GraphQL API.

-   **[文档](https://docs.codex.io/)**
-   **[获取 API 密钥](https://dashboard.codex.io/)**
-   **[图QL 浏览器](https://explorer.codex.io/)**

## 安装

```bash
npm install @codex-data/sdk
```

```bash
yarn add @codex-data/sdk
```

```bash
pnpm add @codex-data/sdk
```

## 快速启动

```typescript
import { Codex } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const networks = await sdk.queries.getNetworks({});
console.log(networks.getNetworks); // [{ id: 1, name: "ethereum" }, { id: 1399811149, name: "solana" }, ...]
```

> **提示 :** 内置 `sdk.queries.*` 请求方法 **每个** 可用字段。 他们很擅长探索API,但是我们推荐制作 [写入自定义查询](https://npmcn.com/package/%40codex-data/sdk/#readme-custom-queries-request-only-the-fields-you-need) 只选择您需要的字段.

## 获取托肯价格

获得任何代币的当前美元价格。 每个请求最多支持25个令牌. 在所有有效集合中,价格都按流动性加权.

```typescript
import { Codex } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const prices = await sdk.queries.getTokenPrices({
  inputs: [
    {
      address: "So11111111111111111111111111111111111111112",
      networkId: 1399811149,
    }, // SOL
    { address: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2", networkId: 1 }, // WETH
  ],
});

prices.getTokenPrices?.forEach((price) => {
  console.log(`${price?.address}: $${price?.priceUsd}`);
});
```

为了获得历史代价,通过一个 `timestamp`数字 :

```typescript
const historicalPrice = await sdk.queries.getTokenPrices({
  inputs: [
    {
      address: "So11111111111111111111111111111111111111112",
      networkId: 1399811149,
      timestamp: 1704067200, // Unix timestamp
    },
  ],
});
```

## 获取 OHLCV 图表数据

获取烛台数据 用于任何标志或交易对等。 支持从1秒到7天的决议.

```typescript
import { Codex } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const bars = await sdk.queries.getBars({
  symbol: "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2:1", // WETH on Ethereum
  from: 1704067200,
  to: 1704153600,
  resolution: "60", // 1-hour candles
  removeEmptyBars: true,
});

bars.getBars?.o?.forEach((open, i) => {
  console.log({
    open,
    high: bars.getBars?.h?.[i],
    low: bars.getBars?.l?.[i],
    close: bars.getBars?.c?.[i],
    volume: bars.getBars?.volume?.[i],
    timestamp: bars.getBars?.t?.[i],
  });
});
```

现有决议: `1S`, (中文(简体) ), `5S`, (中文(简体) ), `15S`, (中文(简体) ), `30S`, (中文(简体) ), `1`, (中文(简体) ), `5`, (中文(简体) ), `15`, (中文(简体) ), `30`, (中文(简体) ), `60`, (中文(简体) ), `240`, (中文(简体) ), `720`, (中文(简体) ), `1D`, (中文(简体) ), `7D`

## 发现和过滤键

按价格,量,市场上限,流动性,持有者计数,交易活动等进行搜索和过滤的代币.

```typescript
import {
  Codex,
  TokenRankingAttribute,
  RankingDirection,
} from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const result = await sdk.queries.filterTokens({
  filters: {
    network: [1], // Ethereum
    liquidity: { gte: "100000" }, // $100k+ liquidity
    marketCap: { gte: "1000000" }, // $1M+ market cap
    txnCount24: { gte: "500" }, // 500+ transactions in 24h
  },
  rankings: [
    {
      attribute: TokenRankingAttribute.TrendingScore24,
      direction: RankingDirection.Desc,
    },
  ],
  limit: 20,
});

result.filterTokens?.results?.forEach((token) => {
  console.log(
    `${token?.token?.name} (${token?.token?.symbol}): $${token?.priceUSD}`,
  );
});
```

## 获取钱包余额

获取带有美元值的钱包地址的所有符号余额 .

```typescript
import { Codex } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const balances = await sdk.queries.balances({
  input: {
    walletAddress: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", // vitalik.eth
    networks: [1],
    includeNative: true,
    removeScams: true,
    limit: 50,
  },
});

balances.balances?.items?.forEach((item) => {
  console.log(
    `${item?.token?.symbol}: ${item?.shiftedBalance} ($${item?.balanceUsd})`,
  );
});
```

## 获取托肯控件

获取持有特定符号的钱包列表, 按余额排序 .

```typescript
import { Codex } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const holders = await sdk.queries.holders({
  input: {
    tokenId: "So11111111111111111111111111111111111111112:1399811149", // SOL
    limit: 50,
  },
});

console.log(`Total holders: ${holders.holders?.count}`);
console.log(`Top 10 hold: ${holders.holders?.top10HoldersPercent}%`);

holders.holders?.items?.forEach((holder) => {
  console.log(
    `${holder?.address}: ${holder?.shiftedBalance} ($${holder?.balanceUsd})`,
  );
});
```

## 获取托肯贸易历史

买入 卖出 薄荷 烧掉任何物品.

```typescript
import { Codex } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const events = await sdk.queries.getTokenEvents({
  query: {
    address: "So11111111111111111111111111111111111111112",
    networkId: 1399811149,
    eventDisplayType: ["Buy", "Sell"],
  },
  limit: 25,
});

events.getTokenEvents?.items?.forEach((event) => {
  console.log(
    `${event?.eventDisplayType} by ${event?.maker} — $${event?.token0SwapValueUsd}`,
  );
});
```

## 流出实时价格

> **说明:** WebSocket 订阅需要一个 [付费计划](https://dashboard.codex.io/dashboard/billing)。 。 。 .

通过WebSocket订阅直播价格更新. 每一次连锁互换都会起火.

```typescript
import { Codex } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const unsubscribe = sdk.subscriptions.onPriceUpdated(
  {
    address: "So11111111111111111111111111111111111111112",
    networkId: 1399811149,
  },
  {
    next: (result) => {
      console.log("Price:", result.data?.onPriceUpdated?.priceUsd);
    },
    error: (err) => console.error(err),
    complete: () => console.log("Stream ended"),
  },
);

// Call unsubscribe() to clean up
```

## 流出实时 OHLCV 栏

> **说明:** WebSocket 订阅需要一个 [付费计划](https://dashboard.codex.io/dashboard/billing)。 。 。 .

在所有决议同时获得烛台实时更新.

```typescript
import { Codex, QuoteToken } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const unsubscribe = sdk.subscriptions.onBarsUpdated(
  {
    pairId: "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640:1", // USDC/WETH on Ethereum
    quoteToken: QuoteToken.Token1,
  },
  {
    next: (result) => {
      const bar = result.data?.onBarsUpdated;
      const oneMin = bar?.aggregates?.r1?.usd;
      console.log(
        `1min candle — O: ${oneMin?.o} H: ${oneMin?.h} L: ${oneMin?.l} C: ${oneMin?.c}`,
      );
    },
    error: (err) => console.error(err),
    complete: () => console.log("Stream ended"),
  },
);
```

## 流活贸易

> **说明:** WebSocket 订阅需要一个 [付费计划](https://dashboard.codex.io/dashboard/billing)。 。 。 .

观看任何交易对面发生的买卖事件.

```typescript
import { Codex, QuoteToken } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const unsubscribe = sdk.subscriptions.onEventsCreated(
  {
    id: "0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640:1",
    quoteToken: QuoteToken.Token0,
  },
  {
    next: (result) => {
      result.data?.onEventsCreated?.events?.forEach((event) => {
        console.log(
          `${event?.eventDisplayType} by ${event?.maker} — $${event?.token0SwapValueUsd}`,
        );
      });
    },
    error: (err) => console.error(err),
    complete: () => console.log("Stream ended"),
  },
);
```

## 边际订阅

过 `{ useEdge: true }` 作为生成的订阅方法的第三个参数(或 `sdk.subscribe`)使用区域边缘节点。 索拉纳(签名)`1399811149`至 `wss://fra.edge.codex.io/graphql`;罗宾链(`4663`) 和BNB(英语:`56`路径到 `wss://iad.edge.codex.io/graphql` 内 `us-east-1`。每个端点按需创建连接并重新使用.

```typescript
import { Codex, EventCommitmentLevel } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const unsubscribe = sdk.subscriptions.onTokenEventsCreated(
  {
    input: { tokenAddress: "0x...", networkId: 56 },
    commitmentLevel: [EventCommitmentLevel.Processed],
  },
  {
    next: (result) => console.log(result.data),
    error: (err) => console.error(err),
    complete: () => console.log("Stream ended"),
  },
  { useEdge: true },
);
```

边缘支持 `onEventsCreated`, (中文(简体) ), `onTokenEventsCreated`, (中文(简体) ), `onBarsUpdated`,以及 `onTokenBarsUpdated`承诺水平必须包括: `Processed`,以及 `onBarsUpdated` 需要明确 `quoteToken`。每个订阅必须针对一个支持的链条。 无订阅 `useEdge` 使用主端点.

轻而易举 `withEdge` 助手从 `@codex-data/sdk/edge` 使用相同的路由. 对于一个独立的罗宾汉或BNB连接,通过 `url: ROBINHOOD_EDGE_URL` 或者说 `url: BNB_EDGE_URL` 改为 `createEdgeClient`从 `@codex-data/sdk/edge`. SDK's 。 `apiEdgeUrl` 和助手的 `edgeUrl` 覆盖所有链的路由 .

## 自定义查询: 只请求您需要的字段

内置 `sdk.queries.*` 方法选择每个可用的字段,所以上面的食谱是最昂贵的调用每个端点的方法. 写自己的查询意味着你得到更小,更快的答复.

有两种方法:

### 备选案文1: `sdk.send()` - 快速,零设置

自行写入查询并描述结果类型 :

```typescript
import { Codex } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const result = await sdk.send<{
  getNetworks: Array<{ id: number; name: string }>;
}>(
  `query GetNetworks {
    getNetworks { id name }
  }`,
  {},
);

console.log("Networks:", result.getNetworks);
```

与其手写类型,不如重新使用 SDK 的导出查询类型 `DeepPartial`,使每个字段都可以选择:

```typescript
import { Codex, DeepPartial, FilterTokensQuery } from "@codex-data/sdk";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const result = await sdk.send<DeepPartial<FilterTokensQuery>>(
  `query FilterTokens($limit: Int) {
    filterTokens(limit: $limit) {
      results {
        priceUSD
        volume24
        token { name symbol }
      }
    }
  }`,
  { limit: 10 },
);
```

### 备选案文2:图表QL 代码生成器——准确类型和自动完成

对于生产代码库,我们建议从你自己的查询中生成类型. SDK号在 `@codex-data/sdk/schema.graphql`,所以代码源运行离线 与你安装的精确计划版本.

安装编码工具 :

```bash
npm install -D @graphql-codegen/cli @graphql-codegen/client-preset
```

添加一个 `codegen.ts` 转到您的工程根 :

```typescript
import type { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
  schema: "./node_modules/@codex-data/sdk/schema.graphql",
  documents: "src/**/*.ts",
  generates: {
    "src/gql/": {
      preset: "client",
      presetConfig: { fragmentMasking: false },
    },
  },
};

export default config;
```

运行 `graphql-codegen`,然后用生成的查询写入 `graphql()` 帮手,把他们交给 `sdk.query()`。结果类型是从您选择的字段中推断出来的 :

```typescript
import { Codex } from "@codex-data/sdk";
import { graphql } from "./gql";

const sdk = new Codex(process.env.CODEX_API_KEY!);

const trendingTokens = graphql(`
  query TrendingTokens($limit: Int) {
    filterTokens(limit: $limit) {
      results {
        priceUSD
        volume24
        token {
          name
          symbol
        }
      }
    }
  }
`);

const result = await sdk.query(trendingTokens, { limit: 10 });
// result.filterTokens.results[0].priceUSD — fully typed, only what you asked for
```

见 [代码示例](https://npmcn.com/package/%40codex-data/sdk/examples/codegen) 用于一个完整的工作项目.

## 通用网络标识

| 网络 | 身份证 |
| --- | --- |
| 以利亚 | `1` |
| 英国银行 | `56` |
| 多边形 | `137` |
| 坐标 | `42161` |
| 基础 | `8453` |
| 雪崩 | `43114` |
| 索拉纳 | `1399811149` |

使用 `sdk.queries.getNetworks({})` 为80+支持的网络的完整列表.

## ID 格式公约

Codex API 中的ID 遵循模式 `address:networkId`数字 :

-   **脚本标识 :** `0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2:1` (WETH on Ethereum) (在伊特鲁姆)
-   **标对 :** `0x88e6a0c2ddd26feeb64f039a2c41296fcb3f5640:1` (美国航天中心/Ethereum上的WETH)
-   **钱包标识 :** `0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045:1`

## 所有可用方法

### 查询( E)`sdk.queries.*`(中文(简体) )

| 方法 | 说明 |
| --- | --- |
| [`filterTokens`](https://docs.codex.io/api-reference/queries/filtertokens) | 按价格、数量、市场上限、流动性进行搜索和过滤 |
| [`getTokenPrices`](https://docs.codex.io/api-reference/queries/gettokenprices) | 获得最多25个令牌的当前或历史美元价格 |
| [`getBars`](https://docs.codex.io/api-reference/queries/getbars) | 获取 OHLCV 烛台数据进行交易 |
| [`holders`](https://docs.codex.io/api-reference/queries/holders) | 获得按余额排序的指针持有人列表( Y)[已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`filterPairs`](https://docs.codex.io/api-reference/queries/filterpairs) | 搜索和过滤交易对 |
| [`balances`](https://docs.codex.io/api-reference/queries/balances) | 获取带有美元值的钱包令牌余额( E)[已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`getTokenEvents`](https://docs.codex.io/api-reference/queries/gettokenevents) | 买入/卖出/装入/烧出交易活动 |
| [`pairMetadata`](https://docs.codex.io/api-reference/queries/pairmetadata) | 获取交易对数统计和元数据 |
| [`token`](https://docs.codex.io/api-reference/queries/token) | 获取单个符的元数据 |
| [`listPairsWithMetadataForToken`](https://docs.codex.io/api-reference/queries/listpairswithmetadatafortoken) | 包含完整元数据的列表配对 |
| [`getTokenEventsForMaker`](https://docs.codex.io/api-reference/queries/gettokeneventsformaker) | 获取特定钱包的交易事件 |
| [`getDetailedPairStats`](https://docs.codex.io/api-reference/queries/getdetailedpairstats) | 给一对人打个详细的数据 |
| [`listPairsForToken`](https://docs.codex.io/api-reference/queries/listpairsfortoken) | 列出所有交易对表示符 |
| [`tokenTopTraders`](https://docs.codex.io/api-reference/queries/tokentoptraders) | 找顶级交易员代币 |
| [`tokens`](https://docs.codex.io/api-reference/queries/tokens) | 获取多个符号的元数据 |
| [`top10HoldersPercent`](https://docs.codex.io/api-reference/queries/top10holderspercent) | 获取前十名钱包持有的百分比 |
| [`getDetailedPairsStats`](https://docs.codex.io/api-reference/queries/getdetailedpairsstats) | 获得多个对的详细统计数据 |
| [`filterTokenWallets`](https://docs.codex.io/api-reference/queries/filtertokenwallets) | 获得每册交易统计数据(利润/损失、买卖计数)([已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`liquidityMetadata`](https://docs.codex.io/api-reference/queries/liquiditymetadata) | 获得流动资金池元数据([已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`tokenSparklines`](https://docs.codex.io/api-reference/queries/tokensparklines) | 获取令牌的闪光价格数据 |
| [`filterWallets`](https://docs.codex.io/api-reference/queries/filterwallets) | 通过交易统计过滤钱包( E)[已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`detailedWalletStats`](https://docs.codex.io/api-reference/queries/detailedwalletstats) | 获取全面的钱包分析( E)[已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`getExchanges`](https://docs.codex.io/api-reference/queries/getexchanges) | 获取 DEX 信息 |
| [`getNetworks`](https://docs.codex.io/api-reference/queries/getnetworks) | 列出所有80+支持的网络 |
| [`getTokenBars`](https://docs.codex.io/api-reference/queries/gettokenbars) | 获取 OHLCV 数据, 以获得所有对的符号 |
| [`chartUrls`](https://docs.codex.io/api-reference/queries/charturls) | 获取预发的图表图像 URL([已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`walletChart`](https://docs.codex.io/api-reference/queries/walletchart) | 获取钱包组合图表数据( E)[已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`filterExchanges`](https://docs.codex.io/api-reference/queries/filterexchanges) | 过滤分散交换器 |
| [`liquidityLocks`](https://docs.codex.io/api-reference/queries/liquiditylocks) | 获取流动性锁信息( E)[已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`getNetworkConfigs`](https://docs.codex.io/api-reference/queries/getnetworkconfigs) | 获取网络配置细节 |
| [`getNetworkStats`](https://docs.codex.io/api-reference/queries/getnetworkstats) | 获取网络统计 |
| [`getNetworkStatus`](https://docs.codex.io/api-reference/queries/getnetworkstatus) | 获取网络同步状态 |
| [`tokenLifecycleEvents`](https://docs.codex.io/api-reference/queries/tokenlifecycleevents) | 获取符号创建和迁移事件 |
| [`blocks`](https://docs.codex.io/api-reference/queries/blocks) | 按数字或时间戳获取块数据 |

### 订阅`sdk.subscriptions.*`(b) —— [付费计划](https://dashboard.codex.io/dashboard/billing) 所需经费

| 方法 | 说明 |
| --- | --- |
| [`onPairMetadataUpdated`](https://docs.codex.io/api-reference/subscriptions/onpairmetadataupdated) | 实时对接数据库更新 |
| [`onLaunchpadTokenEventBatch`](https://docs.codex.io/api-reference/subscriptions/onlaunchpadtokeneventbatch) | 挂载发射板事件 |
| [`onBarsUpdated`](https://docs.codex.io/api-reference/subscriptions/onbarsupdated) | 交易对的实时 OHLCV 条 |
| [`onPriceUpdated`](https://docs.codex.io/api-reference/subscriptions/onpriceupdated) | 单一代号的实时价格 |
| [`onHoldersUpdated`](https://docs.codex.io/api-reference/subscriptions/onholdersupdated) | 活体持有人数和平衡变化 |
| [`onDetailedStatsUpdated`](https://docs.codex.io/api-reference/subscriptions/ondetailedstatsupdated) | 实时详细数据更新 |
| [`onDetailedTokenStatsUpdated`](https://docs.codex.io/api-reference/subscriptions/ondetailedtokenstatsupdated) | 实时详细指数数据汇总跨池 |
| [`onEventsCreated`](https://docs.codex.io/api-reference/subscriptions/oneventscreated) | 直播买卖一对事件 |
| [`onPricesUpdated`](https://docs.codex.io/api-reference/subscriptions/onpricesupdated) | 多个令牌的实时价格 |
| [`onUnconfirmedEventsCreated`](https://docs.codex.io/api-reference/subscriptions/onunconfirmedeventscreated) | 未确认的(混合)贸易活动 |
| [`onTokenEventsCreated`](https://docs.codex.io/api-reference/subscriptions/ontokeneventscreated) | 所有游泳池的现场活动 |
| [`onLaunchpadTokenEvent`](https://docs.codex.io/api-reference/subscriptions/onlaunchpadtokenevent) | 个人发射板活动(Pump.fun等) |
| [`onTokenBarsUpdated`](https://docs.codex.io/api-reference/subscriptions/ontokenbarsupdated) | 实时 OHLCV 标记栏 |
| [`onLatestPairUpdated`](https://docs.codex.io/api-reference/subscriptions/onlatestpairupdated) | 新交易配对创建活动 |
| [`onUnconfirmedBarsUpdated`](https://docs.codex.io/api-reference/subscriptions/onunconfirmedbarsupdated) | 未确认的栏更新 |
| [`onEventsCreatedByMaker`](https://docs.codex.io/api-reference/subscriptions/oneventscreatedbymaker) | 特定钱包的直播事件 |
| [`onBalanceUpdated`](https://docs.codex.io/api-reference/subscriptions/onbalanceupdated) | 实时钱包余额更新 |
| [`onTokenLifecycleEventsCreated`](https://docs.codex.io/api-reference/subscriptions/ontokenlifecycleeventscreated) | 接续生命周期事件 |
| [`onLatestTokens`](https://docs.codex.io/api-reference/subscriptions/onlatesttokens) | 新符号创建事件 |
| [`onNftEventsCreated`](https://docs.codex.io/api-reference/subscriptions/onnfteventscreated) | NFT贸易活动 |

### 变化(`sdk.mutations.*`(中文(简体) )

| 方法 | 说明 |
| --- | --- |
| [`createWebhooks`](https://docs.codex.io/api-reference/mutations/createwebhooks) | 创建 Webhook 提醒( R)[已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`deleteWebhooks`](https://docs.codex.io/api-reference/mutations/deletewebhooks) | 删除 Webhook 提醒([已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`backfillWalletAggregates`](https://docs.codex.io/api-reference/mutations/backfillwalletaggregates) | 触发钱包数据回填( E)[已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`createApiTokens`](https://docs.codex.io/api-reference/mutations/createapitokens) | 创建短寿命 API 令牌供客户端使用( S)[已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`deleteApiToken`](https://docs.codex.io/api-reference/mutations/deleteapitoken) | 删除一个 API 令牌([已支付](https://dashboard.codex.io/dashboard/billing)(中文(简体) ) |
| [`refreshBalances`](https://docs.codex.io/api-reference/mutations/refreshbalances) | 刷新钱包余额 |

## 配置

```typescript
import { Codex } from "@codex-data/sdk";

const sdk = new Codex("YOUR_API_KEY", {
  apiUrl: "https://graph.codex.io/graphql", // default
  apiRealtimeUrl: "wss://graph.codex.io/graphql", // default
  ws: true, // enable WebSocket (default: true)
});

// Update config at runtime
sdk.updateConfig({ ws: false });

// Clean up WebSocket connection
sdk.dispose();
```

## 实例

见 [实例](https://npmcn.com/package/%40codex-data/sdk/examples) 完整工作项目的目录 :

-   **[简单](https://npmcn.com/package/%40codex-data/sdk/examples/simple)** 基本查询、过滤和订阅
-   **[代码](https://npmcn.com/package/%40codex-data/sdk/examples/codegen)** —— 使用 GraphQL 代码生成器进行完全输入自定义查询
-   **[下一个.js](https://npmcn.com/package/%40codex-data/sdk/examples/next)** ——全网应用

## 捐款

我们欢迎捐款! 请随意提交拉力请求.

```bash
pnpm install    # Install dependencies
pnpm run build  # Build the SDK
pnpm run test   # Run tests
pnpm run lint   # Lint the codebase
```

## 释放

在树枝上,做你的改变,然后:

-   `pnpm run build`
-   变动 `package.json` 相应版本
-   合并到主机
-   创建 github 发布,其标签与版本相同 `package.json`

## 升级到 v2

见 [更新(md)](https://npmcn.com/package/%40codex-data/sdk/UPGRADING.md) 用于从v1到v2的迁移指令.

## 链接

-   [Codex API 文档](https://docs.codex.io/)
-   [大众端点](https://docs.codex.io/api-reference/popular-endpoints)
-   [图QL 浏览器](https://explorer.codex.io/)
-   [获取 API 密钥](https://dashboard.codex.io/)
-   [代码 MCP 服务器](https://github.com/Codex-Data/codex-mcp)
-   [解析器](https://discord.com/invite/mFpUhT3vAq)
-   [微博](https://x.com/trycodex)

## 许可证

麻省理工学院

## 常见问题

### @codex-data/sdk 是什么？

JavaScript/Typescript的代码SDK\. 它提供了生成的类型和方便的方法来访问图克l api\.

### 如何安装 @codex-data/sdk？

在项目目录运行 npm install @codex-data/sdk，或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖：graphql（^16\.0\.0）。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖，Yarn 需要手动安装。

### @codex-data/sdk 支持 TypeScript 吗？

支持。包内自带 TypeScript 类型声明（package\.json 声明了 types 入口），安装后即可获得类型提示，无需再安装 @types 包。

### @codex-data/sdk 支持 ESM 还是 CommonJS？

同时提供 ES Module 与 CommonJS 入口，import 和 require\(\) 都可以使用，打包工具会自动选择合适的版本。

### @codex-data/sdk 需要什么版本的 Node\.js？

package\.json 的 engines 字段要求 Node\.js \>=17\.5\.0。版本不符时 npm 默认只给出警告，开启 engine-strict 后会拒绝安装。

### @codex-data/sdk 可以商用吗？

@codex-data/sdk 使用 MIT 许可。宽松许可：允许商业使用、修改和再分发，通常只需在分发时保留原版权与许可声明。以上为概括，不构成法律意见，请以许可原文为准。

### @codex-data/sdk 的下载量有多少？

根据 npm 官方下载统计，@codex-data/sdk 在 2026/10/10 – 2026/11/08 这 30 天内被下载 206,276 次，日均约 6,876 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入，适合横向比较热度，不能直接等同于使用人数。

### @codex-data/sdk 还在维护吗？

最新版本 2\.6\.3 发布于 2026/11/10（今天）；至今共发布 121 个版本，其中过去 12 个月发布了 74 个；首次发布于 2024/08/28。发布频率只是参考信号：功能稳定的工具可能很少需要更新，建议结合源码仓库的 issue 和提交记录判断。

