@argonprotocol/mainchain

中文文档
1.6.0发布于 2026/11/15MITTypeScriptESM + CJS构建来源已验证近 30 天下载 6.9万

A client for accessing the Argon mainchain apis.

原始使用文档
文档目录5 节
  1. Installation
  2. Client Usage
  3. Wage Protector
  4. Ethereum Beacon Sync
  5. Gateway Activity Proof Flow

This is a Node.js client for the Argon Protocol (https://argonprotocol.org). It has the following core features:

  1. A typescript generated RPC client for the Argon Protocol.
  2. A "Wage Protector" class that can be used to protect wages against inflation or deflation of the Argon.

Installation

npm install @argonprotocol/mainchain

Client Usage

To create a client, you can use the getClient(host) function in the main module. This will return a client object that is typed to the argon apis.

Wage Protector

If you want to protect wages against inflation or deflation of the Argon, there is a WageProtector class that can be used. You can use it a single time:

const { WageProtector } = require('@argonprotocol/mainchain');
const basePrice = 1_000_000n; // 1 Argon
const protector = await WageProtector.create(client);
const protectedPrice = protector.getProtectedWage(basePrice);

Or you can subscribe to changes (for instance, to track a series of valid cpi adjustments):

const { WageProtector } = require('@argonprotocol/mainchain');
const basePrice = 1_000_000n; // 1 Argon
const { unsubscribe } = await WageProtector.subscribe(client, protectedPrice => {
  console.log(`Protected price: ${protectedPrice.getProtectedWage(basePrice)}`);
});

Each WageProtector instance has the details of the Argon Target Price and USD price at the time of creation.

interface IArgonCpiSnapshot {
  // The target price of the argon as a fixed point number (18 decimals)
  argonUsdTargetPrice: bigint;
  // The current price of the argon as a fixed point number (18 decimals)
  argonUsdPrice: bigint;
  // The block hash in which the cpi was finalized
  finalizedBlock: Uint8Array;
  // The tick that the cpi applies to
  tick: bigint;
}

Ethereum Beacon Sync

Pass an execution source when building beacon sync or bootstrap transactions:

const transactions = await getNextEthereumBeaconSyncTxs(client, beaconApiUrl, {
  executionRpcUrl,
});

Gloas light-client headers contain an execution block hash rather than a payload header. The execution RPC supplies the matching header bytes, which the client checks against that hash. Original pre-Gloas payload-header responses can omit the execution source. Historical headers upgraded to the hash-only format also need it. getEthereumBeaconSyncBootstrapTx accepts the same third argument.

Existing verifier state migrates with Gloas disabled. Once its version and epoch are known, governance can call setGloasFork as root without resetting the checkpoint, committees, or anchors. That call preserves earlier forks and rejects changes to finalized Gloas history.

Gateway Activity Proof Flow

Discovery, storage-witness capture, and relay preparation are separate operations. Apps own caching, scheduling, RPC fallback, and submission:

  1. Call discoverMissingGatewayActivityLocators(...) with a finalized execution block number plus the minimum gateway activity nonce you care about. If you already cache finalized locators, pass afterLocatorIndex to fetch only the new suffix.
  2. Cache those finalized locator blocks in the app as you collect them.
  3. If supportsGatewayActivityStorageProofs(client) is true, call captureGatewayActivityStorageProofs(...) against a recent, mined execution block while the RPC still has its state. This operation needs no Argon client or retained anchor. It captures the selected slots in one eth_getProof request and verifies them against that block's state root.
  4. Cache the returned enriched locator records in the app. Their witness block may not be finalized yet; keep the finalized locator records separately so a witness can be replaced after a reorg.
  5. Call buildGatewayActivityProof(...) with cached captures for storage runtimes, or plain discovered locators for receipt-only runtimes. It prefers storage when supported, selects the closest retained anchor, and attaches the bounded ancestry path. Storage relay preparation does not refetch witnesses, logs, or contract state. Each payload proves one complete locator.
  6. Submit receipt payloads to proveGatewayActivity(...) and storage payloads (identified by locatorIndex in payload.proof) to proveGatewayActivityStorage(...). Keep any deferredLocators for a later attempt. Replace captures listed in recaptureLocators using a newer execution block: they are orphaned or outside the retained anchor's ancestry bound.

For explicit proof selection, use buildGatewayActivityReceiptProofPayloads(...) with discovered locators or buildGatewayActivityStorageProofs(...) with captured locators. Capabilities are independent; a runtime may accept either format.

const captures = await captureGatewayActivityStorageProofs({
  executionClient,
  executionBlock: await executionClient.getBlock({ blockTag: 'latest' }),
  gatewayAddress,
  locators,
});
// Persist captures in the app, then prepare relay transactions when anchors become available.
const result = await buildGatewayActivityProof(client, {
  executionClient,
  gatewayAddress,
  locators: captures,
});

Storage proofs include the full locator's activity logs and its activityRootSeed, even when the last proven nonce falls inside that locator. Only payload.activities and payload.gatewayActivityNonceRange describe the newly applied suffix. No bootstrap call or stored last-locator hash is needed.

Receipt inclusion alone does not make a log the next gateway activity. Undecodable or unrelated gateway logs are rejected without pausing synchronization; decoded activities must have the next contiguous nonce. A valid next activity that conflicts with local business state can pause syncing. After repairing that state, an operator can unpause and rebuild from the current nonce. Storage proofs still authenticate the full locator, but do not apply its already-consumed prefix again. If expiry cleanup failed after the final activity was committed, unpause alone does not retry it: the next successfully processed activity block retries cleanup at its authenticated block boundary.

Deferred locators are waiting for missing predecessors or an execution anchor. A locator that exceeds the runtime's proof capacity is a configuration/support error, not deferred work: waiting cannot make it fit. This flow targets the contract with its 128-activity per-block cap. The pallet's integrity checks cover that hard cap, maximum-size events, encoded proof bytes, and provider weights.

The client library does not keep a long-lived locator or witness cache. App-side code should own it, scoped to the range between the last proven gateway locator and the latest collected finalized Ethereum block. Keep locators whose blocks are not yet anchored on Argon, and pass the cached locators into both gateway proof building and execution-header backfill planning.

版本与发布记录

@argonprotocol/mainchain 共发布 297 个版本,首次发布于 2024/08/28;过去 12 个月发布了 220 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.6.0latest2026/11/151 天前
1.5.2-dev.96d18beedev2026/11/133 天前
1.5.2-dev.4f5b015c2026/11/124 天前
1.5.2-dev.085c3add2026/11/115 天前
1.5.2-dev.c911d6132026/11/115 天前
1.5.2-dev.247195a52026/11/105 天前

关于 @argonprotocol/mainchain 的常见问题

@argonprotocol/mainchain 是什么?

A client for accessing the Argon mainchain apis.

如何安装 @argonprotocol/mainchain?

在项目目录运行 npm install @argonprotocol/mainchain,或使用 pnpm add / yarn add / bun add。

@argonprotocol/mainchain 支持 TypeScript 吗?

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

@argonprotocol/mainchain 支持 ESM 还是 CommonJS?

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

@argonprotocol/mainchain 可以商用吗?

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

@argonprotocol/mainchain 的下载量有多少?

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

@argonprotocol/mainchain 还在维护吗?

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