@exodus/solidity-contract

中文文档
1.3.3发布于 2026/11/03MPL-2.0TypeScriptES Module近 30 天下载 4.2万

Object orient smart contract ABI data building/parsing.

原始使用文档
文档目录5 节
  1. API
  2. new SolidityContract(abi, address)
  3. SolidityContract instance properties
  4. SolidityContract instance methods
  5. SolidityContract static methods

solidity-contract

Object-oriented ABI data building and parsing for Ethereum Smart Contracts.

API

new SolidityContract(abi, address)

  • abi: Array | String The contract's ABI, as a parsed JSON array, or JSON string.
  • address: String (optional)

Creates a new SolidityContract instance, and populates the methods and events of the contract with the methods and events in the ABI.

SolidityContract instance properties

  • contract.abi: Array<Object>

The parsed ABI Array as passed to the constructor.


  • contract.address: String

The contract address string as passed to the constructor. This address isn't used for anything at present.


  • contract.methodIds: Object<String:Object>

An object mapping method ID strings to the ABI method object specifying the details of that method. All method ID string keys are lower case hex strings prefixed with '0x'.

const { methodId, name, stateMutability, payable, constant, type, inputs, outputs } =
  contract.methodIds['0x01234567']

  • contract[eventName]

For every event in the contract's ABI, the contract instance has the event added as a property. For example, an ERC20 token contract would have contract.Transfer and contract.Approval.

Each of these properties is an object which has the following properties and methods:

  • build: (...any) => Buffer UNIMPLEMENTED
  • parse: (callData: String | Buffer) => Array<any> Parse ABI event log data calling and return the parsed values. The values' types depend on the types of the input parameters in the ABI specification. For example, a string type would return a string, a uint would return a stringified number in base 10, a bytes value would return a Buffer, etc. Must the event's raw unindexed log data.
  • testInput: (String | Buffer) => boolean UNIMPLEMENTED
  • eventId: String The event ID hex string.
  • abi: Object The ABI specification for this event as passed to the constructor.

  • contract.eventIds: Object<String:Object>

Same as contract.methodIds, except for contract events instead. Event IDs in solidity are represented in long-form, as full 32 byte Keccak hash, rather than the short 4-byte form used for method IDs.

const { eventId, name, type, inputs, anonymous } =
  contract.eventIds['0xb5bb9d8014a0f9b1d61e21e796d78dccdf1352f23cd32812f4850b878ae4944c']

  • contract[methodName]: Object

For every function on the contract's ABI, the contract instance has the method added as a property. For example, a contract instantiated with an ERC20 token ABI would have contract.transfer, contract.approve, etc.

Each of these properties is an object which has the following properties and methods:

  • build: (...any) => Buffer Build ABI transaction data calling methodName with the supplied parameters. For example, you could call token.transfer('0x' + '0'.repeat(40), 100000) to build the data for a transfer of 100000 wei for any ERC20 token.
  • parse: (callData: String | Buffer) => Array<any> Parse ABI transaction data calling this function and return the parsed values. The values' types depend on the types of the input parameters in the ABI specification. For example, a string type would return a string, a uint would return a stringified number in base 10, a bytes value would return a Buffer, etc. Must supply call data without the 4 method ID prefix bytes.
  • testInput: (String | Buffer) => boolean Check if the input data is valid for this method.
  • methodId: String The method ID hex string.
  • abi: Object The ABI specification for this method as passed to the constructor.
const callData = tokenContract.balanceOf.build(address)
console.log(Buffer.isBuffer(callData)) // true
console.log(tokenContract.balanceOf.testInput(callData)) // true

  • contract[eventName]: Object

For every event in the contract's ABI, the contract instance has the event added as a property. For example, an ERC20 SolidityContract instance has contract.Transfer, contract.Approval, etc.

Each of these properties is equal to the ABI specification object for this event, plus an eventId hex string property. See contract.eventIds[eventId].

SolidityContract instance methods


  • decodeInput(callData: String | Buffer): { method: string, values: Array<any> }

Decode the given call data and attempt to identify which method on the contract was being called. If successful, decode the input parameters and return them in the values array. If unsuccessful, an error is thrown.

SolidityContract static methods


  • SolidityContract.erc20(address: String): SolidityContract

Return a contract implementing the full ERC20 token standard. address parameter is optional.


  • SolidityContract.simpleErc20(address: String): SolidityContract

Returns a contract implementing only the following ERC20 methods and event:

transfer(address,uint256)
balanceOf(address)
Transfer(address,address,uint256)

address parameter is optional.


  • SolidityContract.simpleErc721(address: String): SolidityContract

Returns a contract implementing only the following ERC721 methods:

ownerOf(uint256)
tokenURI(uint256)
uri(uint256)
symbol()
totalSupply()
safeTransferFrom(address,address,uint256)

address parameter is optional.


版本与发布记录

@exodus/solidity-contract 共发布 17 个版本,首次发布于 2019/10/16;过去 12 个月发布了 3 个版本。

版本发布日期距今
1.3.3latest2026/11/0310 天前
1.3.22026/11/0310 天前
1.3.12026/10/1629 天前
1.3.02025/09/171.2 年前
1.2.12024/12/111.9 年前
1.2.02024/11/252 年前

关于 @exodus/solidity-contract 的常见问题

@exodus/solidity-contract 是什么?

Object orient smart contract ABI data building/parsing.

如何安装 @exodus/solidity-contract?

在项目目录运行 npm install @exodus/solidity-contract,或使用 pnpm add / yarn add / bun add。

@exodus/solidity-contract 支持 TypeScript 吗?

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

@exodus/solidity-contract 支持 ESM 还是 CommonJS?

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

@exodus/solidity-contract 可以商用吗?

@exodus/solidity-contract 使用 MPL-2.0 许可。弱 Copyleft:可以商用,也可以和闭源代码一起使用;但如果分发时修改了 MPL 授权的文件,这些文件的修改需以 MPL 开源。以上为概括,不构成法律意见,请以许可原文为准。

@exodus/solidity-contract 的下载量有多少?

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

@exodus/solidity-contract 还在维护吗?

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