@findeth/abi

中文文档
0.7.1发布于 2021/04/05MITTypeScriptESM + CJS零依赖近 30 天下载 4.3万

A tiny Solidity ABI encoder and decoder

原始使用文档
文档目录5 节
  1. Installation
  2. Getting Started
  3. Encode
  4. Decode
  5. Development

@findeth/abi

Version License GitHub CI codecov

@findeth/abi is a zero-dependencies ABI encoder and decoder library for FindETH. It supports both Node.js and web browsers. This library is experimental, and may not work with all contract interfaces. It is used in the FindETH applications, that can be found here:

Currently, most types (except fixed-point numbers (fixed<M>x<N>), and fixed-length arrays type<M>) are supported.

Note: This is a work-in-progress version of FindETH, and is not production-ready. For the current version of FindETH, please refer to this repository. The public API may change in minor releases below 1.0.0 (though this is unlikely).


Installation

You can install @findeth/abi with Yarn (recommended) or NPM:

$ yarn add @findeth/abi
$ npm install @findeth/abi

Note: If you are using TypeScript, @findeth/abi requires TypeScript 4.1 or newer. This is used for automatically inferring the types of the input and output, based on the specified types.

Getting Started

You can use the encode and decode functions to encode and decode ABI respectively.

Encode

The encode function takes an array of ABI types (e.g., ["string", "uint256"]) and an array of values to encode. For example:

import { encode, toHex } from "@findeth/abi";

const buffer = encode(["string", "uint256"], ["foo bar", 12345]);
console.log(toHex(buffer));

// 000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000030390000000000000000000000000000000000000000000000000000000000000007666f6f2062617200000000000000000000000000000000000000000000000000

Decode

The decode function takes an array of ABI types, and a buffer (Uint8Array) to decode. Note that Node.js Buffers are compatible with Uint8Array, but in order to maintain full compatibility with web browsers (without the need for polyfills), this library does not use Buffer. Example:

import { decode, fromHex } from "@findeth/abi";

const value = fromHex("000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000030390000000000000000000000000000000000000000000000000000000000000007666f6f2062617200000000000000000000000000000000000000000000000000");
console.log(decode(["string", "uint256"], value));

// ["foo bar", 12345n]

Development

Install dependencies with yarn:

$ yarn

To run automated tests, use the test script:

$ yarn test

To build the library, use the build script:

$ yarn build

版本与发布记录

@findeth/abi 共发布 14 个版本,首次发布于 2020/06/05;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.7.1latest2021/04/055 年前
0.7.02021/04/055 年前
0.6.12021/04/045 年前
0.6.02021/04/045 年前
0.5.22021/03/095 年前
0.5.12021/03/085 年前

关于 @findeth/abi 的常见问题

@findeth/abi 是什么?

A tiny Solidity ABI encoder and decoder

如何安装 @findeth/abi?

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

@findeth/abi 支持 TypeScript 吗?

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

@findeth/abi 支持 ESM 还是 CommonJS?

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

@findeth/abi 需要什么版本的 Node.js?

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

@findeth/abi 可以商用吗?

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

@findeth/abi 的下载量有多少?

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

@findeth/abi 还在维护吗?

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