npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

event-decode

v1.0.2

Published

🔍 以太坊智能合约事件解码工具库 - 支持从交易日志中解析和解码智能合约事件,基于Web3.js构建,提供完整的ABI事件解析功能

Downloads

22

Readme

Event Decode

一个用于解码以太坊智能合约事件的实用工具库,基于Web3.js构建。

功能特性

  • 🔍 从交易日志中解码智能合约事件
  • 📝 支持完整的ABI事件解析
  • 🔗 自动匹配事件签名
  • 💾 处理BigInt序列化
  • 🎯 支持单个事件和批量事件解码
  • 📋 列出可用事件列表

安装

npm install event-decode

使用方法

基本用法

const { 
  decodeEventFromLog, 
  decodeEventsFromTransaction, 
  decodeSingleEvent,
  listAvailableEvents,
  web3 
} = require('event-decode');

// 你的合约ABI
const contractABI = [
  {
    "type": "event",
    "name": "Transfer",
    "inputs": [
      {"name": "from", "type": "address", "indexed": true},
      {"name": "to", "type": "address", "indexed": true},
      {"name": "value", "type": "uint256", "indexed": false}
    ]
  }
  // ... 其他ABI定义
];

// 解码单个事件
const topics = ["0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef"];
const data = "0x0000000000000000000000000000000000000000000000000000000000000064";
const decodedEvent = decodeSingleEvent(contractABI, topics, data);

// 从交易哈希解码所有事件
const transactionHash = "0x...";
await decodeEventsFromTransaction(transactionHash, contractABI);

// 列出所有可用事件
listAvailableEvents(contractABI);

高级用法

// 自定义Web3连接
const Web3 = require('web3').Web3;
const customWeb3 = new Web3('https://mainnet.infura.io/v3/YOUR_PROJECT_ID');

// 使用自定义Web3实例
const { decodeEventFromLog } = require('event-decode');
const decodedEvent = decodeEventFromLog(contractABI, topics, data);

API 参考

decodeEventFromLog(allABI, topics, data)

解码单个事件日志。

参数:

  • allABI (Array): 完整的合约ABI数组
  • topics (Array): 事件日志的topics数组
  • data (String): 事件日志的data字符串

返回:

  • Object: 包含事件名称和解码数据的对象,如果解码失败返回null

decodeEventsFromTransaction(transactionHash, allABI)

从交易哈希解码所有事件。

参数:

  • transactionHash (String): 交易哈希
  • allABI (Array): 完整的合约ABI数组

decodeSingleEvent(allABI, topics, data)

解码单个事件并打印结果。

参数:

  • allABI (Array): 完整的合约ABI数组
  • topics (Array): 事件日志的topics数组
  • data (String): 事件日志的data字符串

listAvailableEvents(allABI)

列出ABI中所有可用的事件。

参数:

  • allABI (Array): 完整的合约ABI数组

extractEventsFromABI(abi)

从ABI中提取所有事件定义。

参数:

  • abi (Array): 完整的合约ABI数组

返回:

  • Object: 包含所有事件定义的对象

findEventBySignature(topics, allEvents)

根据事件签名查找匹配的事件ABI。

参数:

  • topics (Array): 事件日志的topics数组
  • allEvents (Object): 事件定义对象

返回:

  • Object: 包含事件名称和ABI的对象,如果未找到返回null

convertBigIntToString(obj)

将对象中的BigInt值转换为字符串,用于JSON序列化。

参数:

  • obj (Any): 需要转换的对象

返回:

  • Any: 转换后的对象

示例

ERC-20 Transfer事件解码

const { decodeSingleEvent } = require('event-decode');

const erc20ABI = [
  {
    "type": "event",
    "name": "Transfer",
    "inputs": [
      {"name": "from", "type": "address", "indexed": true},
      {"name": "to", "type": "address", "indexed": true},
      {"name": "value", "type": "uint256", "indexed": false}
    ]
  }
];

// Transfer事件数据
const topics = [
  "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", // Transfer事件签名
  "0x0000000000000000000000001234567890123456789012345678901234567890", // from地址
  "0x0000000000000000000000000987654321098765432109876543210987654321"  // to地址
];
const data = "0x0000000000000000000000000000000000000000000000000000000000000064"; // value (100)

const result = decodeSingleEvent(erc20ABI, topics, data);
// 输出: { eventName: "Transfer", decodedData: { from: "0x1234...", to: "0x0987...", value: "100" } }

依赖

许可证

MIT

贡献

欢迎提交Issue和Pull Request!

更新日志

1.0.0

  • 初始版本发布
  • 支持基本的事件解码功能
  • 支持BigInt序列化处理