bi-php/web3-decode-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

bi-php/web3-decode-php

Composer 安装命令:

composer require bi-php/web3-decode-php

包简介

A PHP library for decoding Ethereum logs and errors

README 文档

README

A PHP library for decoding Ethereum logs and errors using contract ABIs. This library provides utilities to decode Ethereum (custom) error messages and event logs, making it easier to work with smart contract data.

Features

  • Decode Ethereum Errors: Decode error messages from Ethereum transactions using the contract ABI.
  • Decode Ethereum Logs: Decode event logs emitted by smart contracts using the contract ABI.
  • Supports Indexed and Non-Indexed Parameters: Handles both indexed and non-indexed parameters in event logs.

Installation

You can install the library via Composer:

composer require bi/web3-decode-php

Usage

Decoding Ethereum Errors

To decode an Ethereum error, use the decodeError function:

require 'vendor/autoload.php';

use Web3DecodePhp\DecodeError;

$errorSelector = '0x12345678'; // Example error selector
$abi = [
    [
        'type' => 'error',
        'name' => 'MyError',
        'inputs' => [
            ['type' => 'uint256'],
            ['type' => 'address']
        ]
    ]
];

$decodedError = DecodeError::decode($errorSelector, $abi);

echo $decodedError;

Decoding Ethereum Logs

To decode an Ethereum log, use the DecodeLog class:

require 'vendor/autoload.php';

use Web3DecodePhp\DecodeLog;

$eventAbi = [
    'name' => 'Transfer',
    'inputs' => [
        ['name' => 'from', 'type' => 'address', 'indexed' => true],
        ['name' => 'to', 'type' => 'address', 'indexed' => true],
        ['name' => 'value', 'type' => 'uint256', 'indexed' => false],
    ]
];

$log = (object) [
    "address" => "0x89d24a6b4ccb1b6faa2625fe562bdd9a23260359", // Contract address
    "topics" => [
        "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef", // Event signature
        "0x0000000000000000000000004bbeeb066ed09b7aed07bf39eee0460dfa261520", // from (indexed)
        "0x000000000000000000000000f977814e90da44bfa03b6295a0616a897441acec", // to (indexed)
    ],
    "data" => "0x0000000000000000000000000000000000000000000000000de0b6b3a7640000", // value (non-indexed)
    "blockHash" => "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef",
    "blockNumber" => "0x123456",
    "blockTimestamp" => "0x6789abcd",
    "transactionHash" => "0xabcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890",
    "transactionIndex" => "0x0",
    "logIndex" => "0x1",
    "removed" => false
];

$decoder = new DecodeLog([$eventAbi]);
$decodedLog = $decoder->decode($log);

// Output the decoded log
echo json_encode($decodedLog, JSON_PRETTY_PRINT);

API Reference

decodeError(string $errorSelector, array $abi): ?array

Decodes an Ethereum error from its selector and ABI.

  • Parameters:
    • $errorSelector: The error selector (hex string).
    • $abi: The contract ABI (including error definitions).
  • Returns: An array containing the decoded error, or null if no match is found.

DecodeLog

A class for decoding Ethereum event logs.

__construct(array $contractAbi)

Initializes the decoder with the contract ABI.

  • Parameters:
    • $contractAbi: The contract ABI (including event definitions).

decode(object $log): array

Decodes an Ethereum log.

  • Parameters:
    • $log: The log object to decode.
  • Returns: An array containing the decoded log data.

Contributing

Contributions are welcome! Please open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License. See the LICENSE file for details.

bi-php/web3-decode-php 适用场景与选型建议

bi-php/web3-decode-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 18 次下载、GitHub Stars 达 1, 最近一次更新时间为 2025 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 bi-php/web3-decode-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bi-php/web3-decode-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 bi-php/web3-decode-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 18
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-19