furqansiddiqui/ethereum-php
Composer 安装命令:
composer require furqansiddiqui/ethereum-php
包简介
A modern, dependency-light Ethereum library powered by a clean cryptographic core
README 文档
README
A modern, dependency-light Ethereum library for PHP 8.5+, powered by a clean cryptographic core. This library provides a comprehensive suite of tools for interacting with the Ethereum blockchain, including account management, transaction handling, and smart contract interaction.
Features
- Account Management: Generate keypairs, derive Ethereum addresses, and handle EIP-55 checksums.
- JSON-RPC Client: Full support for standard Ethereum RPC methods via a clean, extensible client.
- Transaction Types: Support for Legacy, EIP-2930 (Type 1), and EIP-1559 (Type 2) transactions.
- Smart Contracts (EVM): Encode/decode ABI data, call contract methods, and handle contract events.
- RLP & ABI Codecs: High-performance implementations of Recursive Length Prefix (RLP) and Application Binary Interface (ABI) encoding/decoding.
- Unit Management: Easy conversion between Wei, GWei, and Ether denominations using the
Weiclass.
Requirements
- PHP: ^8.5 (64-bit)
- Extensions:
ext-openssl,ext-gmp,ext-bcmath,ext-curl,ext-json - Dependencies:
furqansiddiqui/blockchain-core-phpcharcoal-dev/http-client
Installation
Install via Composer:
composer require furqansiddiqui/ethereum-php
Quick Start
1. Keypairs and Addresses
use FurqanSiddiqui\Ethereum\Ethereum; use Charcoal\Buffers\Types\Bytes32; /** @var Ethereum $eth */ $privateKey = new Bytes32("..."); // 32-byte private key $publicKey = $eth->keypair->generatePublicKey($privateKey); $address = $eth->keypair->addressFromPublicKey($publicKey, withChecksum: true); echo $address->address; // 0x...
2. JSON-RPC Client
use FurqanSiddiqui\Ethereum\Rpc\GethRpc; use Charcoal\Http\Client\ClientConfig; $rpc = new GethRpc("127.0.0.1", 8545, new ClientConfig()); $balance = $rpc->eth_getBalance("0x...", "latest"); echo $balance->eth(); // Balance in ETH
3. Smart Contract Interaction
use FurqanSiddiqui\Ethereum\Evm\SmartContract; use FurqanSiddiqui\Ethereum\Evm\DeployedContract; use FurqanSiddiqui\Ethereum\Keypair\EthereumAddress; // Load ABI from DTO (Array) $abi = SmartContract::fromDto($abiArray); // Initialize deployed contract $contract = new DeployedContract( new EthereumAddress("0x..."), $abi, $rpc ); // Call a constant method $method = $contract->methodFromSignature("symbol()"); $result = $contract->call($method); print_r($result);
4. Transactions
// Create a Type 2 (EIP-1559) transaction $tx = $eth->tx->type2(); $tx->nonce = 1; $tx->to = new EthereumAddress("0x..."); $tx->value = \FurqanSiddiqui\Ethereum\Unit\Wei::fromETH("0.1"); $tx->gasLimit = 21000; $tx->maxFeePerGas = \FurqanSiddiqui\Ethereum\Unit\Wei::fromGWei(50); $tx->maxPriorityFeePerGas = \FurqanSiddiqui\Ethereum\Unit\Wei::fromGWei(2); // Sign the transaction $signedTx = $tx->withSignature($ecdsaSignature); // Get raw hex for broadcasting echo $signedTx->encode()->serialize();
Unit Management
The Wei class provides a safe way to handle Ethereum's large numbers and unit conversions.
use FurqanSiddiqui\Ethereum\Unit\Wei; $value = Wei::fromETH("1.5"); echo $value->wei->getArray(); // Raw Wei (GMP) echo $value->gWei(); // 1500000000 echo $value->eth(); // 1.5
License
This package is open-source software licensed under the MIT license.
furqansiddiqui/ethereum-php 适用场景与选型建议
furqansiddiqui/ethereum-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 25.71k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2020 年 09 月 19 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 furqansiddiqui/ethereum-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 furqansiddiqui/ethereum-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 25.71k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 19
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-09-19