nawab69/web3php

一个简单的PHP包,用于与Ethereum web3 API交互

dev-master 2020-12-02 09:52 UTC

This package is not auto-updated.

Last update: 2024-09-20 02:37:31 UTC


README

这是一个PHP/Laravel包装的web3 JavaScript API。

安装

composer require nawab69/web3php

Laravel的进一步步骤

当使用Laravel时,将以下行添加到您的 config/app.php

'providers' => [
    ...
    Nawab69\Web3PHP\Providers\Web3PHPServiceProvider::class,
    ...
],
'aliases' => [
    ...
    'Ethereum' => Nawab69\Web3PHP\EthereumFacade::class,
    ...
],

然后生成配置文件

# When using Laravel
php artisan vendor:publish

并使用以下值编辑您的 .env 文件

WEB3_URL='127.0.0.1'
WEB3_PORT=8545

使用方法

此示例演示了如何获取指定地址的余额。

Laravel与门面

$eth = Ethereum::eth_getBalance('0x8fbb99e9e73cd62bb3adea5365ff0f9d90c9e532')
print $eth // Prints the account balance in hex.

PHP

$eth = new \Nawab69\Web3PHP\Ethereum($url, $port);
$eth = $eth->eth_getBalance('0x8fbb99e9e73cd62bb3adea5365ff0f9d90c9e532', $block='latest', $decode_hex=false);

print $eth // Prints the account balance in hex.

这是https://github.com/IlyasDeckers/web3php的更新版本,增加了对Laravel 8.0的支持

完整参考:https://github.com/ethereum/wiki/wiki/JavaScript-API#web3js-api-reference