一个 GitHub 上的 Laravel 以太坊扩展包 —— Laravel-ethereum

栏目: 编程语言 · PHP · 发布时间: 7年前

内容简介:这是一个简单的Laravel服务提供程序,提供要使用Composer安装PHP客户端库:或者,将这两行添加到composer require部分:

介绍

这是一个简单的 Laravel 服务提供程序,提供 Generic JSON RPC管理API

安装

要使用Composer安装 PHP 客户端库:

composer require jcsofts/laravel-ethereum

或者,将这两行添加到composer require部分:

{
    "require": {
        "jcsofts/laravel-ethereum": "dev-master"
    }
}

Laravel 5.5+

如果您使用的是Laravel 5.5或更高版本,该软件包将自动注册以太坊 Ethereum 和facade接口。

Laravel 5.4及以下

Jcsofts\LaravelEthereum\EthereumServiceProvider 添加到 config/app.php 中的providers数组中:

'providers' => [
    // Other service providers...

    Jcsofts\LaravelEthereum\EthereumServiceProvider::class,
],

如果要使用facade接口,可以在需要时使用facade类:

use Jcsofts\LaravelEthereum\Facade\Ethereum;

或者在 config/app.php 中添加别名:

'aliases' => [
    ...
    'Ethereum' => Jcsofts\LaravelEthereum\Facade\Ethereum::class,
],

使用Laravel-Ethereum和Lumen

laravel-ethereum也与 Lumen 合作! 您需要手动完成一些工作才能启动并运行。 首先,使用composer安装包:

composer require jcsofts/laravel-ethereum

接下来,我们必须告诉Lumen我们的库在哪儿。 更新 bootstrap/app.php 并注册 EthereumServiceProvider

$app->register(Jcsofts\LaravelEthereum\EthereumServiceProvider::class);

最后,我们需要配置一下库。不幸的是,Lumen不支持自动发布文件,因此您必须自己创建配置文件并将配置文件从包中复制到项目中:

mkdir config
cp vendor/jcsofts/laravel-ethereum/config/ethereum.php config/ethereum.php

此时,在 .env 文件中设置 ETH_HOSTETH_PORT ,注意适合您的计算机环境。 您可以使用以下路线进行测试:

try{
        $ret = \Jcsofts\LaravelEthereum\Facade\Ethereum::eth_protocolVersion();
        print_r($ret);
    }catch (Exception $e){
        echo $e->getMessage();
    }

设置

您可以使用 artisan vendor:publish 将配置文件复制到应用程序的 config 目录:

php artisan vendor:publish

然后使用您的凭据更新 config/ethereum.php 。 或者,您可以使用以下内容更新 .env 文件:

ETH_HOST=http://localhost
ETH_PORT=8545

用法

要使用以太坊客户端库,您可以使用 facade ,或从服务容器请求实例:

try{
    $ret = \Jcsofts\LaravelEthereum\Facade\Ethereum::eth_protocolVersion();
    print_r($ret);
}catch (Exception $e){
    echo $e->getMessage();
}

或者

$thereum = app('Ethereum');

$result=$thereum->eth_protocolVersion();

原文: https://github.com/jcsofts/laravel-ethereum

php以太坊开发教程 ,主要是介绍使用php进行区块链以太坊智能合约开发交互,进行账号创建、交易、转账、代币开发以及过滤器和事件等内容。


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Introduction to Graph Theory

Introduction to Graph Theory

Douglas B. West / Prentice Hall / 2000-9-1 / USD 140.00

For undergraduate or graduate courses in Graph Theory in departments of mathematics or computer science. This text offers a comprehensive and coherent introduction to the fundamental topics of graph ......一起来看看 《Introduction to Graph Theory》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具