ethereum php,digitaldonkey/ethereum-php

这是一个PHP-7.1+版本的库,提供Ethereum JSON-RPC API的接口,支持通过Ganache等服务连接以太坊网络并调用智能合约。使用Composer进行依赖管理,可用于获取区块链上的信息。

README

is a typed PHP-7.1+ interface to Ethereum JSON-RPC API.

Check out the latest API documentation.

Add library in a composer.json file

{

"minimum-stability":"dev",

"autoload": {

"psr-4": {

"Ethereum\\": "src/"

}

},

"repositories": [

{

"type": "git",

"url": "https://github.com/digitaldonkey/ethereum-php.git"

}

],

"require": {

"digitaldonkey/ethereum-php": "dev-master"

}

}

Usage

composer require digitaldonkey/ethereum-php

require __DIR__ . '/vendor/autoload.php';

use Ethereum\Ethereum;

try {

// Connect to Ganache

$eth = new Ethereum('http://127.0.0.1:7545');

// Should return Int 63

echo $eth->eth_protocolVersion()->val();

}

catch (\Exception $exception) {

die ("Unable to connect.");

}

Calling Contracts

You can call (unpayed) functions in smart contracts easily.

The json file "$fileName" used is what you get when you compile a contract with Truffle.

$ContractMeta = json_decode(file_get_contents($fileName));

$contract = new SmartContract(

$ContractMeta->abi,

$ContractMeta->networks->{NETWORK_ID}->address,

new Ethereum(SERVER_URL)

);

$someBytes = new EthBytes('34537ce3a455db6b')

$x = $contract->myContractMethod();

echo $x->val()

You can also run tests at smart contracts, check out EthTestClient.

Event listening and handling

You can use Ethereum-PHP to watch changed on your smart contracts or index a Blockchain block by block. gs

Limitations

Currently not all datatypes are supported.

This library is read-only for now. This means you can retrieve information stored in Ethereum Blockchain.

To write to the blockchain you need a to sign transactions with a private key which is not supported yet.

ArchitectureDiagrammCS6.png

Documentation

The API documentation is available at ethereum-php.org.

There is also a more readable Ethereum Frontier Guide version.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值