@conflux-dev/conflux-address-js

中文文档
2.1.0发布于 2026/08/20MITTypeScriptCommonJS近 30 天下载 1.8万

The encoder and decoder for Conflux Network address

原始使用文档
文档目录6 节
  1. Install
  2. Opt-in for performance
  3. Usage
  4. Encoding
  5. Decoding
  6. API

conflux-address-js

The simple encoder and decoder for Conflux address.

Check CIP-37 for the protocols.

Install

$ npm install @conflux-dev/conflux-address-js

Opt-in for performance

To gain a address conversion performance boost, you can install @conflux-dev/conflux-address-rust in your project. Which will be used to replace the purejs version and can gain a 10-100 performance boost.

$ npm install --save-optional @conflux-dev/conflux-address-rust

Usage

Encoding

const confluxAddr = require('@conflux-dev/conflux-address-js')
const hexBuffer = Buffer.from('106d49f8505410eb4e671d51f7d96d2c87807b09', 'hex')
const netId = 1029 // Conflux main-net

console.log(confluxAddr.encode(hexBuffer, netId))
// cfx:aajg4wt2mbmbb44sp6szd783ry0jtad5bea80xdy7p

console.log(confluxAddr.encode(hexBuffer, netId, true)) // verbose mode to generate address with type
// CFX:TYPE.USER:AAJG4WT2MBMBB44SP6SZD783RY0JTAD5BEA80XDY7P

Decoding

const confluxAddr = require('@conflux-dev/conflux-address-js')
console.log(confluxAddr.decode('cfx:aajg4wt2mbmbb44sp6szd783ry0jtad5bea80xdy7p'))
/*
{ hexAddress:
   <Buffer 10 6d 49 f8 50 54 10 eb 4e 67 1d 51 f7 d9 6d 2c 87 80 7b 09>,
  netId: 1029,
  type: 'user' }
 */


console.log(confluxAddr.decode('CFX:TYPE.USER:AAJG4WT2MBMBB44SP6SZD783RY0JTAD5BEA80XDY7P'))
/*
{ hexAddress:
   <Buffer 10 6d 49 f8 50 54 10 eb 4e 67 1d 51 f7 d9 6d 2c 87 80 7b 09>,
  netId: 1029,
  type: 'user' }
 */

API

  • encode: Low level encode method
  • decode: Low level decode method
  • isValidCfxAddress: Return a boolean value indicating whether the address is valid
  • verifyCfxAddress: Check whether a address is valid, if not will throw an error
  • hasNetworkPrefix: Check a string whether has an network prefix
  • simplifyCfxAddress: Return a non verbose address
  • shortenCfxAddress: Return a shorten address
  • isZeroAddress: Check whether a address is zero address
  • isInternalContractAddress: Check where a address is Conflux InternalContract address
  • isValidHexAddress: Check whether a address is valid hex address
  • isValidCfxHexAddress: Check where a address is valid Conflux hex address

版本与发布记录

@conflux-dev/conflux-address-js 共发布 29 个版本,首次发布于 2021/05/18;过去 12 个月发布了 1 个版本。

版本发布日期距今
2.1.0latest2026/08/202 个月前
2.0.12023/11/272 年前
2.0.02023/11/272 年前
1.4.02023/11/272 年前
1.3.172023/11/142 年前
1.3.162022/07/224 年前

其他发布通道:next → 1.3.2。

关于 @conflux-dev/conflux-address-js 的常见问题

@conflux-dev/conflux-address-js 是什么?

The encoder and decoder for Conflux Network address

如何安装 @conflux-dev/conflux-address-js?

在项目目录运行 npm install @conflux-dev/conflux-address-js,或使用 pnpm add / yarn add / bun add。

@conflux-dev/conflux-address-js 支持 TypeScript 吗?

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

@conflux-dev/conflux-address-js 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@conflux-dev/conflux-address-js 可以商用吗?

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

@conflux-dev/conflux-address-js 的下载量有多少?

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

@conflux-dev/conflux-address-js 还在维护吗?

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