kemalevren/geth-php

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

安装: 356

依赖: 0

建议者: 0

安全: 0

星标: 6

关注者: 3

分支: 4

开放问题: 2

类型:项目

v1.1.6 2020-01-20 09:25 UTC

README

用于 Geth JSON-RPC 的 PHP 封装

要求

  • PHP >= 7.0.x
  • phpunit >= 6.5.*
  • cURL 扩展
  • illuminate/support >= 5.1.*

安装

composer require kemalevren/geth-php

使用方法

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