@ensdomains/address-encoder

中文文档
3.0.0发布于 2026/10/22MITTypeScriptES Module构建来源已验证近 30 天下载 16.6万

Encodes and decodes address formats for various cryptocurrencies

原始使用文档
文档目录10 节
  1. Installation
  2. Getting Started
  3. Hex String Encoding
  4. Supported Cryptocurrencies
  5. Additional Functionality
  6. Async Coder Getter
  7. Individual Coin Imports
  8. Individual Coder Function Imports
  9. EVM Chains
  10. Contribution Guide

@ensdomains/address-encoder

A cryptocurrency address encoder/decoder in TypeScript

Text-format addresses are decoded into their native binary representations, and vice-versa. In the case of Bitcoin-derived chains, this means their scriptPubKey; for Ethereum-derived chains this is their hash.

This library was written for use with EIP 2304, but may be useful for anyone looking for a general purpose cryptocurrency address codec.

EVM compatible chains are either specified using SLIP44 coinType or 0x80000000 | chainId where 0x80000000 is msb (most significant bit) reserved at SLIP44 and no coin types exist in that range. This is to avoid number colision with th existing coin types.

Please read the specification page for the more detail

Installation

bun add @ensdomains/address-encoder

Getting Started

// Import coder getter
import { getCoderByCoinName } from "@ensdomains/address-encoder";

// Get the coder for the address you want to encode/decode
const btcCoder = getCoderByCoinName("btc");

// Decode the address
const decodedAddress = btcCoder.decode("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");
// Uint8Array(25) [ 118, 169, 20, 98, 233, 7, 177, 92, 191, 39, 213, 66, 83, 153, 235, 246, 240, 251, 80, 235, 184, 143, 24, 136, 172 ]

// Encode the address
const encodedAddress = btcCoder.encode(decodedAddress);
// 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa

Hex String Encoding

If the data you are encoding is a hex string rather than Uint8Array, you can use hexToBytes() from @noble/hashes to convert it to the correct type. It expects the hex string without the 0x prefix.

import { getCoderByCoinName } from "@ensdomains/address-encoder";
import { hexToBytes } from "@noble/hashes/utils.js";

const btcCoder = getCoderByCoinName("btc");

// Convert hex encoded data to bytes
const dataAsBytes = hexToBytes(
  "76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac"
);
// Uint8Array(25) [ 118, 169, 20, 98, 233, 7, 177, 92, 191, 39, 213, 66, 83, 153, 235, 246, 240, 251, 80, 235, 184, 143, 24, 136, 172 ]

// Pass bytes to encoder
const encodedAddress = btcCoder.encode(dataAsBytes);
// 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa

Supported Cryptocurrencies

To view all the supported cryptocurrencies of this library, see here.

Additional Functionality

Async Coder Getter

import { getCoderByCoinNameAsync } from "@ensdomains/address-encoder/async";

const btcCoder = await getCoderByCoinNameAsync("btc");

Individual Coin Imports

import { btc } from "@ensdomains/address-encoder/coins";

const decodedAddress = btc.decode("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");
const encodedAddress = btc.encode(decodedAddress);

Individual Coder Function Imports

import {
  decodeBtcAddress,
  encodeBtcAddress,
} from "@ensdomains/address-encoder/coders";

const decodedAddress = decodeBtcAddress("1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa");
const encodedAddress = encodeBtcAddress(decodedAddress);

EVM Chains

There are a variety of EVM chains supported, however none of them (except for ETH) are exported from coins or coders. If you want to individually import for an EVM chain, you can just use the eth import as a replacement.

Contribution Guide

To add a coin to this library, or if you're interested in contributing in any other way, read the contribution guide before submitting a PR.

版本与发布记录

@ensdomains/address-encoder 共发布 47 个版本,首次发布于 2019/10/21;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
3.0.0latest2026/10/2222 天前
2.0.12026/10/1727 天前
2.0.02026/10/131 个月前
1.1.52025/11/2411 个月前
1.1.42025/08/261.2 年前
1.1.32025/08/131.3 年前

其他发布通道:next → 1.0.0。

关于 @ensdomains/address-encoder 的常见问题

@ensdomains/address-encoder 是什么?

Encodes and decodes address formats for various cryptocurrencies

如何安装 @ensdomains/address-encoder?

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

@ensdomains/address-encoder 支持 TypeScript 吗?

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

@ensdomains/address-encoder 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@ensdomains/address-encoder 可以商用吗?

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

@ensdomains/address-encoder 的下载量有多少?

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

@ensdomains/address-encoder 还在维护吗?

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