2017 © Pedro Peláez
 

library ethereum-php

Ethereum client for PHP.

image

ericychu/ethereum-php

Ethereum client for PHP.

  • Thursday, June 7, 2018
  • by ericychu
  • Repository
  • 3 Watchers
  • 11 Stars
  • 34 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 6 Forks
  • 0 Open issues
  • 18 Versions
  • 21 % Grown

The README.md

Ethereum Client for PHP

PHP 版本以太坊 JSON RPC 客户端。, (*1)

可通过简单的添加合约地址和 ABI 来方便的调用合约内的方法,对于需要对交易签名的请求,客户端会自动完成。, (*2)

支持对事件(Log)的监听,但需要通过定时器执行 \Ethereum\Client::synchronizer->sync() 方法来轮询, 当有事件到达会执行自定义的回调并传递一个 \Ethereum\Types\Event 的实例,该实例包含了反序列化后的事件输入和相关的区块、交易数据。, (*3)

JSON RPC API 实现度

已实现, (*4)

  • eth_*
  • net_*
  • web3_*

未实现, (*5)

  • shh_*

依赖

php-64bit: ^7.2
ext-gmp: ^7.2
ext-scrypt: ^1.4
ext-secp256k1: ^0.1.0
ext-keccak: ^0.2
graze/guzzle-jsonrpc: ^3.2
bitwasp/buffertools: ^0.5.0

使用

安装

composer require ericychu/ethereum-php

示例

实例化客户端

$client = new Ethereum\Client(
    // JSON RPC 地址
    'https://api.infura.io/v1/jsonrpc/ropsten',
    // 以太坊网络 ID
    3,
    // 节点账户的 Keystore
    '',
    // Keystore 的密码
    '',
    // 存储实例,用来保存一些状态值,可以通过实现 \Ethereum\StorageInterface 接口使用你自己的存储
    new \Ethereum\Storage
);

添加合约

$client->contracts
    ->add(
        // 合约别名
        'test_contract',
        // 合约地址
        '',
        // 合约 ABI(JSON String)
        ''
    );

调用合约中的方法

pureview 的方法,可以直接以数组的形式返回反序列化后的数据;nonpayablepayable 的方法返回交易的哈希(\Ethereum\Types\Hash 实例)。, (*6)

$result = $client->contracts->test_contract->call('test_function', ['test_arg_1', 'test_arg_2']);

监听事件

这里的事件名称是你在合约中定义的事件名称。, (*7)

注意,监听事件需要通过定时器执行 \Ethereum\Client::synchronizer->sync() 方法来轮询以太坊节点。当有事件到达会执行自定义的回调并传递一个 \Ethereum\Types\Event 的实例,该实例包含了反序列化后的事件输入和相关的区块、交易数据。, (*8)

$client->contracts->test_contract->watch('Event1', function (\Ethereum\Types\Event $data) {
    var_dump($data);
});

如果使用 Swoole,可以通过 Swoole 的定时器来来轮询。, (*9)

swoole_timer_tick(1000, function() use ($client) {
    $client->synchronizer->sync();
});

调用 JSON RPC API

支持的方法请查阅 \Ethereum\Methods\Eth\Ethereum\Methods\Web3\Ethereum\Methods\Net 类。, (*10)

echo $client->eth()->protocolVersion();
echo $client->web3()->clientVersion();
echo $client->net()->version();

The Versions

07/06 2018

dev-develop

dev-develop https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

07/06 2018

dev-master

9999999-dev https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

07/06 2018

0.9.6

0.9.6.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

07/06 2018

0.9.5

0.9.5.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

22/05 2018

0.9.4

0.9.4.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

22/05 2018

0.9.3

0.9.3.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

21/05 2018

0.9.2

0.9.2.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

21/05 2018

0.9.1

0.9.1.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

19/05 2018

0.9

0.9.0.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

17/05 2018

0.8

0.8.0.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

04/05 2018

0.7

0.7.0.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

02/05 2018

0.6

0.6.0.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

02/05 2018

0.5

0.5.0.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

11/04 2018

0.4

0.4.0.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

11/04 2018

0.3.1

0.3.1.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

05/04 2018

0.3

0.3.0.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

26/03 2018

0.2

0.2.0.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3

25/03 2018

0.1

0.1.0.0 https://github.com/ericychu/ethereum-php

Ethereum client for PHP.

  Sources   Download

MIT

The Requires

 

ethereum web3