kerwin-cn / geth-php
用于 geth JSON-RPC API 的 PHP 封装。
v1.2.0
2020-08-03 09:01 UTC
Requires
- php: >=7.0
- guzzlehttp/guzzle: ~6.3
- illuminate/support: 5.0.*|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*|5.8.*|7.5.*
Requires (Dev)
- phpunit/phpunit: 6.5.*
README
要求
- PHP >= 7.0.x
- phpunit >= 6.5.*
- cURL 扩展
- illuminate/support >= 5.1.*
安装
composer require kerwin-cn/geth-php ^1.2
使用方法
$geth = new \kemalevren\Geth\JsonRpc([ // Geth JSON-RPC version 'version' => '2.0', // Host part of address 'host' => '127.0.0.1', // Port part of address 'port' => 8545, // Return results as associative arrays instead of objects 'assoc' => true, ]); $version = $geth->web3_getVersion(); $accounts = $geth->eth_accounts(); foreach($accounts as $account) { echo $account, ': ', $geth->eth_getBalance($account, 'latest'), PHP_EOL; }
Laravel 5
在您的 config/app.php 中添加服务提供者和外观
服务提供者
kemalevren\Geth\Laravel5\GethPhpServiceProvider::class,
外观
'JsonRpc' => kemalevren\Geth\Laravel5\Facades\JsonRpc::class,
Laravel 5 使用方法
JsonRpc::setOptions([ // Geth JSON-RPC version 'version' => '2.0', // Host part of address 'host' => '127.0.0.1', // Port part of address 'port' => 8545, // Return results as associative arrays instead of objects 'assoc' => true, ]); $version = JsonRpc::web3_getVersion(); $accounts = JsonRpc::eth_accounts(); foreach($accounts as $account) { echo $account, ': ', JsonRpc::eth_getBalance($account, 'latest'), PHP_EOL; }