Skip to content

use blockchain api easily;好用的区块链API SDK

License

Notifications You must be signed in to change notification settings

stingbo/easyblockchain

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Easy Blockchain Api

Requirement

  1. PHP >= 7.4
  2. Composer

Installation

$ composer require "stingbo/easyblockchain" -vvv

Usage

Tron

🚀 Quick Start
<?php

use EasyBlockchain\Factory;

$config = [
    'tron' => [
        'response_type' => 'array',
        'base_uri' => 'http://127.0.0.1:8090',
        'app_key' => 'YOUR TRON API KEY',
        'app_key_uri' => 'https://api.trongrid.io',
        'log' => [
            'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod
            'channels' => [
                'dev' => [ // 测试环境
                    'driver' => 'daily',
                    'path' => '/tmp/tron.log',
                    'level' => 'debug',
                    'days' => 60,
                ],
                'prod' => [ // 生产环境
                    'driver' => 'daily',
                    'path' => '/tmp/tron.log',
                    'level' => 'debug',
                    'days' => 90,
                ],
            ],
        ],
    ],
];

// 调用通用API
$app = Factory::tron($config['tron']);
$app->client->get('/wallet/generateaddress');

// 调用Trongrid API,有APIKEY标识,则会自动在header里带上此参数,并调用app_key_uri的地址
$block_number = 88888;
$data = $app->client->get("/v1/blocks/{$block_number}/events", [
    'only_confirmed' => $params['only_confirmed'] ?? true,
    'limit' => $params['limit'] ?? 100,
    'fingerprint' => $params['fingerprint'] ?? '',
], 'APIKEY');

ETH

🚀 Quick Start
<?php

use EasyBlockchain\Factory;

$config = [
    'eth' => [
        'response_type' => 'array',
        'base_uri' => 'http://127.0.0.1:8545',
        'log' => [
            'default' => 'dev', // 默认使用的 channel,生产环境可以改为下面的 prod
            'channels' => [
                'dev' => [ // 测试环境
                    'driver' => 'daily',
                    'path' => '/tmp/eth.log',
                    'level' => 'debug',
                    'days' => 60,
                ],
                'prod' => [ // 生产环境
                    'driver' => 'daily',
                    'path' => '/tmp/eth.log',
                    'level' => 'debug',
                    'days' => 90,
                ],
            ],
        ],
    ],
];

$app = Factory::eth($config['eth']);
$result = $app->client->postJson('', [
    'jsonrpc' => '2.0',
    'method' => 'eth_accounts',
    'params' => [],
    'id' => 1,
]);

About

use blockchain api easily;好用的区块链API SDK

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages