@dfinity/ledger-icrc

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

A library for interfacing with ICRC ledgers on the Internet Computer.

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

ledger-icrc-js

A library for interfacing with ICRC ledger on the Internet Computer.

npm version GitHub license

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

Table of contents

Installation

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

npm i @dfinity/ledger-icrc

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

The features are available through the class IcrcLedgerCanister. It has to be instantiated with a canister ID.

e.g. fetching a token metadata.

import { IcrcLedgerCanister } from "@dfinity/ledger-icrc";
import { createAgent } from "@dfinity/utils";

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

const { metadata } = IcrcLedgerCanister.create({
  agent,
  canisterId: MY_LEDGER_CANISTER_ID,
});

const data = await metadata({});

Documentation

You can find the API docs here.

Resources

版本与发布记录

@dfinity/ledger-icrc 共发布 515 个版本,首次发布于 2023/10/03;过去 12 个月发布了 32 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

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

其他发布通道:beta → 7.0.0-beta-2025-12-18,next → 7.1.0-next-2026-04-21.1。

关于 @dfinity/ledger-icrc 的常见问题

@dfinity/ledger-icrc 是什么?

A library for interfacing with ICRC ledgers on the Internet Computer.

如何安装 @dfinity/ledger-icrc?

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

@dfinity/ledger-icrc 支持 TypeScript 吗?

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

@dfinity/ledger-icrc 支持 ESM 还是 CommonJS?

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

@dfinity/ledger-icrc 可以商用吗?

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

@dfinity/ledger-icrc 的下载量有多少?

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

@dfinity/ledger-icrc 还在维护吗?

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