@dfinity/nns

中文文档
13.0.0发布于 2026/09/22Apache-2.0TypeScriptESM + CJS零依赖构建来源已验证近 30 天下载 3875

A library for interfacing with the Internet Computer's Network Nervous System.

原始使用文档
文档目录4 节
  1. Table of contents
  2. Installation
  3. Usage
  4. Documentation

nns-js

A library for interfacing with the Internet Computer's Network Nervous System.

npm version GitHub license

[!TIP] Still using @dfinity/nns? Upgrade to @icp-sdk/canisters/nns!

Table of contents

Installation

You can use nns-js by installing it in your project.

npm i @dfinity/nns

The bundle needs peer dependencies, be sure that following resources are available in your project as well.

npm i @icp-sdk/core @dfinity/utils

Usage

Most features are provided through the use of classes. For example, querying the list of neurons controlled by the caller with the governance canister:

import { NnsGovernanceCanister } from "@dfinity/nns";
import { createAgent } from "@dfinity/utils";

const agent = await createAgent({
  identity,
  host: HOST,
});

const { listNeurons } = NnsGovernanceCanister.create({
  agent,
  canisterId: MY_GOVERNANCE_CANISTER_ID,
});

const myNeurons = await listNeurons({ certified: false });

To execute this on a local environment, you will need to fetch the root key when initializing the agent. Additionally, you might need to adapt the port. The following snippet also demonstrates how you can inline a canister ID as well.

import { NnsGovernanceCanister } from "@dfinity/nns";
import { Principal } from "@icp-sdk/core/principal";
import { createAgent } from "@dfinity/utils";

const agent = await createAgent({
  identity,
  host: "http://localhost:8000",
  fetchRootKey: true,
});

const { listNeurons } = NnsGovernanceCanister.create({
  agent,
  canisterId: Principal.fromText("rrkah-fqaaa-aaaaa-aaaaq-cai"),
});

const myNeurons = await listNeurons({ certified: false });

Documentation

You can find the API docs here.

版本与发布记录

@dfinity/nns 共发布 1,236 个版本,首次发布于 2022/01/03;过去 12 个月发布了 33 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
13.0.0latest2026/09/221 个月前
12.1.0-next-2026-04-21.1next2026/04/216 个月前
12.1.0-next-2026-04-212026/04/216 个月前
12.1.0-next-2026-04-202026/04/216 个月前
12.1.0-next-2026-02-182026/02/188 个月前
12.1.0-next-2026-02-112026/02/118 个月前

其他发布通道:nightly → 0.7.0-nightly-2022-08-08.1,beta → 12.0.0-beta-2025-12-18,next → 12.1.0-next-2026-04-21.1。

关于 @dfinity/nns 的常见问题

@dfinity/nns 是什么?

A library for interfacing with the Internet Computer's Network Nervous System.

如何安装 @dfinity/nns?

在项目目录运行 npm install @dfinity/nns,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@icp-sdk/canisters(^4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dfinity/nns 支持 TypeScript 吗?

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

@dfinity/nns 支持 ESM 还是 CommonJS?

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

@dfinity/nns 可以商用吗?

@dfinity/nns 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dfinity/nns 的下载量有多少?

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

@dfinity/nns 还在维护吗?

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