@canton-network/core-acs-reader

中文文档
1.25.0发布于 2026/11/06Apache-2.0TypeScriptESM + CJS近 30 天下载 32.1万

Reader for active contract set (ACS) data from the Canton ledger, providing functions to retrieve and process active contract information for specified filters.

原始使用文档
文档目录18 节
  1. Overview
  2. Installation
  3. Quick Start
  4. Core Concepts
  5. ACS Reader
  6. Options
  7. Cache Configuration
  8. Usage Examples
  9. Basic Contract Retrieval
  10. Working with JavaScript Contracts
  11. Paginated Access
  12. Raw Data Access
  13. Continuous Fetching
  14. API Reference
  15. ACSReader
  16. Configuration
  17. Cache Options (not applicable for pagination mode)
  18. Best Practices

@canton-network/core-acs-reader

Overview

The ACS Reader abstracts the complexity of querying and managing active contracts from the Canton ledger. It offers both standard and paginated access patterns, with intelligent caching to minimize network overhead and improve application performance.

Installation

pnpm add @canton-network/core-acs-reader

Quick Start

import { ACSReader } from '@canton-network/core-acs-reader'
import { ledgerProvider } from './your-ledger-setup'

// Initialize the reader
const reader = new ACSReader(ledgerProvider)

// Read active contracts with filtering
const contracts = await reader.read({
    templateIds: ['templateId'],
    parties: ['partyId'],
    offset: 0,
})

// Get JavaScript contract objects (convenience method)
const jsContracts = await reader.readJsContracts({
    templateIds: ['templateId'],
    parties: ['partyId'],
})

Core Concepts

ACS Reader

The ACSReader class is the primary interface for querying active contracts. It maintains an internal cache and provides methods for both raw and processed contract data.

Options

Standard Options (AcsOptions):

  • offset: Ledger offset to query from (automatically resolved if omitted)
  • templateIds: Array of template IDs to filter by
  • interfaceIds: Array of interface IDs to filter by
  • parties: Array of party IDs to filter by
  • filterByParty: Enable party-based filtering
  • limit: Maximum number of results to return
  • continueUntilCompletion: Continue fetching until all data is retrieved

Paginated Options (PaginatedAcsOptions): Same as standard options, plus:

  • pageToken: Token for fetching specific pages
  • maxPageSize: Maximum number of contracts per page

Cache Configuration

Configure cache behavior with ACSCacheCollectionOptions:

const reader = new ACSReader(ledgerProvider, {
    maxEventsBeforePrune: 1000, // Events before compaction
    safeOffsetDeltaForPrune: 100, // Offset window to preserve
})

Usage Examples

Basic Contract Retrieval

const reader = new ACSReader(ledgerProvider)

// Fetch all active contracts
const allContracts = await reader.read({})

// Filter by template ID
const tokenContracts = await reader.read({
    templateIds: ['templateId'],
})

// Filter by multiple parties
const partyContracts = await reader.read({
    parties: ['partyId', 'partyId2'],
    filterByParty: true,
})

Working with JavaScript Contracts

The readJsContracts method returns contract data in a more accessible format:

const jsContracts = await reader.readJsContracts({
    templateIds: ['templateId'],
    parties: ['partyId'],
})

// Each contract includes:
// - All fields from createdEvent
// - synchronizerId
jsContracts.forEach((contract) => {
    console.log(contract.contractId, contract.templateId)
    console.log(contract.createArgument)
})

Paginated Access

For large datasets, use the paginated reader:

const reader = new ACSReader(ledgerProvider)

// Fetch first page
const firstPage = await reader.paginated.read({
    templateIds: ['templateId'],
    maxPageSize: 100,
})

// Fetch next page using token
const nextPage = await reader.paginated.read({
    templateIds: ['templateId'],
    pageToken: firstPage.nextPageToken,
    maxPageSize: 100,
})

// Or fetch all pages at once
const allPages = await reader.paginated.read({
    templateIds: ['templateId'],
    continueUntilCompletion: true,
})

Raw Data Access

Access raw contract responses without caching:

const reader = new ACSReader(ledgerProvider)

// Standard raw access
const rawContracts = await reader.raw.read({
    templateIds: ['templateId'],
})

// Paginated raw access
const rawPage = await reader.paginated.raw.read({
    templateIds: ['templateId'],
    maxPageSize: 100,
})

Continuous Fetching

Fetch all available data in a single call:

const contracts = await reader.read({
    templateIds: ['templateId'],
    continueUntilCompletion: true,
    limit: 200, // Batch size for each query
})

API Reference

ACSReader

Main class for reading active contracts.

Constructor

new ACSReader(
  ledger: AbstractLedgerProvider,
  cacheOptions?: ACSCacheCollectionOptions
)

Configuration

Cache Options (not applicable for pagination mode)

interface ACSCacheCollectionOptions {
    // Compact history after this many events
    maxEventsBeforePrune?: number

    // Preserve events within this offset window
    safeOffsetDeltaForPrune?: number
}
  • Set maxEventsBeforePrune to 0 for immediate compaction (efficient for monotonically increasing offsets)
  • Set safeOffsetDeltaForPrune to 0 to compact everything outside the current window

Best Practices

  1. Reuse Reader Instances: Create one reader instance and reuse it to benefit from caching
  2. Filter Early: Apply template and party filters to reduce data transfer and processing
  3. Use Pagination: For large datasets, use paginated access to control memory usage
  4. Configure Cache: Tune cache settings based on your query patterns
  5. Handle Offsets: Let the reader resolve offsets automatically unless you need specific points in time

版本与发布记录

@canton-network/core-acs-reader 共发布 41 个版本,首次发布于 2026/03/04;过去 12 个月发布了 41 个版本。

版本发布日期距今
1.25.0latest2026/11/063 天前
1.24.02026/10/2910 天前
1.20.2-backport.3bugfix2026/10/2613 天前
1.23.02026/10/2317 天前
1.22.02026/10/1227 天前
1.20.2-backport.12026/10/031 个月前

关于 @canton-network/core-acs-reader 的常见问题

@canton-network/core-acs-reader 是什么?

Reader for active contract set (ACS) data from the Canton ledger, providing functions to retrieve and process active contract information for specified filters.

如何安装 @canton-network/core-acs-reader?

在项目目录运行 npm install @canton-network/core-acs-reader,或使用 pnpm add / yarn add / bun add。

@canton-network/core-acs-reader 支持 TypeScript 吗?

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

@canton-network/core-acs-reader 支持 ESM 还是 CommonJS?

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

@canton-network/core-acs-reader 可以商用吗?

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

@canton-network/core-acs-reader 的下载量有多少?

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

@canton-network/core-acs-reader 还在维护吗?

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