kerwin-cn/geth-php

用于 geth JSON-RPC API 的 PHP 封装。

维护者

详细信息

github.com/kerwin-cn/geth-php

源代码

安装: 5

依赖项: 0

建议者: 0

安全性: 0

星标: 0

关注者: 1

分支: 4

类型:项目

v1.2.0 2020-08-03 09:01 UTC

README

用于 GethJSON-RPC 的 PHP 封装。

要求

  • 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;
}