ilyasdeckers / web3php
A simple PHP package to interact with the Ethereum web3 API
dev-master
2018-02-22 10:17 UTC
Requires
- php: >=7.0.0
- illuminate/session: ~5.0
- illuminate/support: ~5.0
This package is auto-updated.
Last update: 2024-10-18 02:20:12 UTC
README
A PHP/Laravel wrapper around web3 JavaScript API.
Installation
composer require ilyasdeckers/web3php
Further steps for Laravel
When using Laravel, add the following lines to your config/app.php
'providers' => [ ... IlyasDeckers\Web3PHP\Providers\Web3PHPServiceProvider::class, ... ], 'aliases' => [ ... 'Ethereum' => IlyasDeckers\Web3PHP\EthereumFacade::class, ... ],
then generate the config file
# When using Laravel
php artisan vendor:publish
And edit your .env file with the following values
WEB3_URL='127.0.0.1'
WEB3_PORT=8545
Usage
This example shows you how to get the balance for a given address.
Laravel with facades
$eth = Ethereum::eth_getBalance('0x8fbb99e9e73cd62bb3adea5365ff0f9d90c9e532') print $eth // Prints the account balance in hex.
PHP
$eth = new \IlyasDeckers\Web3PHP\Ethereum($url, $port); $eth = $eth->eth_getBalance('0x8fbb99e9e73cd62bb3adea5365ff0f9d90c9e532', $block='latest', $decode_hex=false); print $eth // Prints the account balance in hex.
Full reference: https://github.com/ethereum/wiki/wiki/JavaScript-API#web3js-api-reference