ecourty / ethereum-php
Interact with an Ethereum node via JSON-RPC using PHP
Installs: 81
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/ecourty/ethereum-php
Requires
- php: >=8.3
- ext-bcmath: *
- symfony/http-client: ^7.2
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.65
- phpstan/phpstan: ^2.0
- phpunit/phpunit: ^11.5
README
Ethereum PHP allows you to interact with the Ethereum blockchain using PHP.
All you need to start is a running Ethereum node, with the JSON-RPC interface enabled.
Installation
Install this package using composer:
composer require ecourty/ethereum-php
Usage
Connecting to a Node
<?php use EthereumPHP\Client\EthereumClient; $client = new EthereumClient('http://localhost:8545'); // ... $balance = $clent->getBalance('0x1234567890123456789012345678901234567890'); // ... $latestBlock = $client->getLastBlock(); // ...
Using the EthereumConverter utility
EthereumPHP\Utils\EthereumConverter provides a set of methods to convert between different Ethereum units (wei, gwei, ether).
<?php use EthereumPHP\Utils\EthereumConverter; // ... $weiAmount = 14500000789000000; $etherAmount = EthereumConverter::weiToEther($weiAmount); $gweiAmount = EthereumConverter::weiToGwei($weiAmount);
Remarks
Precise numbers such as WEI / GWEI / ETHER amounts are represented as strings instead of float or int to avoid precision loss.
The bcmath extension is needed for this library to work.
Features
EthereumPHP comes with a handful of methods to interact with the Ethereum blockchain.
Here is a list of all currently supported JSON-RPC methods:
net_versionnet_listeningnet_peerCounteth_protocolVersioneth_syncingeth_chainIdeth_miningeth_hashrateeth_gasPriceeth_accountseth_blockNumbereth_getBalanceeth_getStorageAteth_getTransactionCounteth_getBlockTransactionCountByHasheth_getBlockTransactionCountByNumbereth_getUncleCountByBlockHasheth_getUncleCountByBlockNumbereth_getCodeeth_signeth_signTransactioneth_sendTransactioneth_sendRawTransactioneth_calleth_estimateGaseth_getBlockByHasheth_getBlockByNumbereth_getTransactionByHasheth_getTransactionByBlockHashAndIndexeth_getTransactionByBlockNumberAndIndexeth_getTransactionReceipteth_getUncleByBlockHashAndIndexeth_getUncleByBlockNumberAndIndexeth_newFiltereth_newBlockFiltereth_newPendingTransactionFiltereth_uninstallFiltereth_getFilterChangeseth_getFilterLogseth_getLogs