@duneanalytics/client-sdk

中文文档
0.5.3发布于 2026/11/09TypeScriptESM + CJS构建来源已验证近 30 天下载 7.1万

Node Client for Dune Analytics' officially supported API.

原始使用文档
文档目录4 节
  1. Execute Raw SQL
  2. Custom API
  3. Usage API
  4. Contracts API

Styled With Prettier Build

Dune Client TS

This NPM package implements all the basic routes defined in the Dune API Docs. It also introduces a convenience method refresh which combines executeQuery, getExecutionStatus and gettExecutionResults in a way that makes it nearly trivial to fetch query execution results.

Install the package

pnpm add @duneanalytics/client-sdk
import { QueryParameter, DuneClient, RunQueryArgs } from "@duneanalytics/client-sdk";
const { DUNE_API_KEY } = process.env;

const client = new DuneClient(DUNE_API_KEY ?? "");
const queryId = 1215383;
const opts: RunQueryArgs = {
  queryId,
  query_parameters: [
    QueryParameter.text("TextField", "Plain Text"),
    QueryParameter.number("NumberField", 3.1415926535),
    QueryParameter.date("DateField", "2022-05-04 00:00:00"),
    QueryParameter.enum("ListField", "Option 1"),
  ],
};

client
  .runQuery(opts)
  .then((executionResult) => console.log(executionResult.result?.rows));

// should look like
// [
//    {
//      date_field: "2022-05-04 00:00:00.000",
//      list_field: "Option 1",
//      number_field: "3.1415926535",
//      text_field: "Plain Text",
//    },
//  ]

Execute Raw SQL

You can execute raw SQL queries directly using the executeSql method:

const { DUNE_API_KEY } = process.env;

const client = new DuneClient(DUNE_API_KEY ?? "");
const execution = await client.exec.executeSql({
  sql: "SELECT * FROM dex.trades WHERE block_time > now() - interval '1' day LIMIT 10",
  performance: QueryEngine.Medium, // optional
});

const executionId = execution.execution_id;
const status = await client.exec.getExecutionStatus(executionId);
const results = await client.exec.getExecutionResults(executionId);

Custom API

const { DUNE_API_KEY } = process.env;

const client = new DuneClient(DUNE_API_KEY ?? "");
const results = await client.custom.getResults({
  username: "your_username",
  slug: "endpoint-slug"
  // optional arguments: see `GetResultParams`
  limit: 100,
});

Usage API

Get information about your API usage, including credits and storage:

const { DUNE_API_KEY } = process.env;

const client = new DuneClient(DUNE_API_KEY ?? "");
const usage = await client.usage.getUsage();

console.log(`Credits used: ${usage.billing_periods[0].credits_used}`);
console.log(`Private queries: ${usage.private_queries}`);
console.log(`Storage: ${usage.bytes_used} / ${usage.bytes_allowed} bytes`);

Contracts API

Submit contracts for decoding in batches and track their status. Submissions are attributed to the user who created the API key; see the docs for plan requirements.

const { DUNE_API_KEY } = process.env;

const client = new DuneClient(DUNE_API_KEY ?? "");
const { results } = await client.contracts.decode({
  submissions: [
    {
      blockchain_name: "ethereum",
      address: "0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984",
      project_name: "uniswap",
      contract_name: "UniswapToken",
      abi: uniswapTokenAbi, // JSON array, or a string containing it
      idempotency_key: "uniswap-token/ethereum/1", // optional, makes retries safe
    },
  ],
});
// One result per submission, matched by index: { submission_id, status: "pending" } or { error }

const page = await client.contracts.listSubmissions({ status: "pending", limit: 20 });
// Pass page.next_cursor back as `cursor` to fetch the next page

Note also that the client has methods executeQuery, getExecutionStatus, getExecutionResult and cancelExecution

Check out this Demo Project!

版本与发布记录

@duneanalytics/client-sdk 共发布 35 个版本,首次发布于 2024/02/21;过去 12 个月发布了 12 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.3latest2026/11/094 天前
0.5.22026/10/2618 天前
0.5.12026/10/061 个月前
0.5.02026/09/112 个月前
0.4.52026/09/022 个月前
0.4.42026/08/043 个月前

关于 @duneanalytics/client-sdk 的常见问题

@duneanalytics/client-sdk 是什么?

Node Client for Dune Analytics' officially supported API.

如何安装 @duneanalytics/client-sdk?

在项目目录运行 npm install @duneanalytics/client-sdk,或使用 pnpm add / yarn add / bun add。

@duneanalytics/client-sdk 支持 TypeScript 吗?

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

@duneanalytics/client-sdk 支持 ESM 还是 CommonJS?

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

@duneanalytics/client-sdk 可以商用吗?

@duneanalytics/client-sdk 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@duneanalytics/client-sdk 的下载量有多少?

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

@duneanalytics/client-sdk 还在维护吗?

最新版本 0.5.3 发布于 2026/11/09(4 天前);至今共发布 35 个版本,其中过去 12 个月发布了 12 个;首次发布于 2024/02/21。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。