@avalabs/avalanchejs

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

Avalanche Platform JS Library

原始使用文档
文档目录7 节
  1. Overview
  2. Requirements
  3. Installation
  4. Using the NPM Package
  5. Build from Repository
  6. Use AvalancheJS in Projects
  7. Importing Essentials

AvalancheJS - The Avalanche Platform JavaScript Library

Overview

AvalancheJS is a JavaScript Library for interfacing with the Avalanche Platform. It is built using TypeScript and intended to support both browser and Node.js. The AvalancheJS library allows you to issue commands to the Avalanche node APIs.

Using AvalancheJS, developers can:

  • Retrieve balances on addresses
  • Get UTXOs for addresses
  • Build and sign transactions
  • Issue signed transactions to the X-Chain, P-Chain, and C-Chain
  • Perform cross-chain swaps between the X, P and C chains
  • Add Validators and Delegators
  • Create Subnets and Blockchains

Requirements

AvalancheJS requires Node.js LTS version 20.11.1 or higher to compile.

Installation

Using the NPM Package

Add AvalancheJS to your project via npm or yarn.

For installing via npm:

npm install --save @avalabs/avalanchejs

For installing via yarn:

yarn add @avalabs/avalanchejs

Build from Repository

You can also pull the repo down directly and build it from scratch.

Clone the AvalancheJS repository:

git clone https://github.com/ava-labs/avalanchejs.git

Then build it:

npm run build

or

yarn build

Use AvalancheJS in Projects

The AvalancheJS library can be imported into your existing project as follows:

import { avm, pvm, evm } from '@avalabs/avalanchejs';

Importing Essentials

import { avm /** X-chain */, pvm /** P-chain */, evm /** C-chain */, utils, secp256k1 } from "@avalabs/avalanchejs"

// example calls
const exportTx = avm.newExportTx(...) // constructs a new export tx from X
const addValidatorTx = pvm.newAddPermissionlessValidatorTx(...) // constructs a new add validator tx on P
const importTx = evm.newImportTx(...) // constructs a new import tx to C

const publicKeyBytes = utils.hexToBuffer(publicKeyHex)
const signature = secp256k1.signHash(bytes, privateKeyBytes)

Please check out the examples folder for more info.

版本与发布记录

@avalabs/avalanchejs 共发布 79 个版本,首次发布于 2022/08/11;过去 12 个月发布了 16 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.2.0latest2026/09/261 个月前
5.2.0-alpha.1master2026/09/251 个月前
5.1.1-alpha.42026/08/312 个月前
5.1.1-alpha.32026/08/312 个月前
5.1.1-alpha.22026/07/173 个月前
5.1.0-dev.1fix/oidc-publishing-pr2026/07/173 个月前

其他发布通道:legacy → 3.18.1,feat/acp-236 → 5.1.0-canary.5,feat/delegator-tx-fee-output → 5.1.0-fee-output.1,fix/oidc-publishing-pr → 5.1.0-dev.1,master → 5.2.0-alpha.1。

关于 @avalabs/avalanchejs 的常见问题

@avalabs/avalanchejs 是什么?

Avalanche Platform JS Library

如何安装 @avalabs/avalanchejs?

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

@avalabs/avalanchejs 支持 TypeScript 吗?

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

@avalabs/avalanchejs 支持 ESM 还是 CommonJS?

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

@avalabs/avalanchejs 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@avalabs/avalanchejs 可以商用吗?

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

@avalabs/avalanchejs 的下载量有多少?

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

@avalabs/avalanchejs 还在维护吗?

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