y0zh/tron-api

用于与 Tron (Trx) 交互的 PHP API

dev-master 2023-11-30 12:35 UTC

This package is not auto-updated.

Last update: 2024-09-19 16:24:54 UTC


README

用于与 Tron 协议交互的 PHP API

安装

> composer require y0zh/tron-api --ignore-platform-reqs

要求

此版本支持以下版本的 PHP。

  • PHP 7.4

示例用法

use IEXBase\TronAPI\Tron;

$fullNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$solidityNode = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');
$eventServer = new \IEXBase\TronAPI\Provider\HttpProvider('https://api.trongrid.io');

try {
    $tron = new \IEXBase\TronAPI\Tron($fullNode, $solidityNode, $eventServer);
}
catch (\IEXBase\TronAPI\Exception\TronException $e) {
    exit($e->getMessage());
}


$this->setAddress('..');
//Balance
$tron->getBalance(null, true);

// Transfer Trx
var_dump($tron->send('to', 1.5));

//Generate Address
var_dump($tron->createAccount());

//Get Last Blocks
var_dump($tron->getLatestBlocks(2));

//Change account name (only once)
var_dump($tron->changeAccountName('address', 'NewName'));


// Contract
$tron->contract('Contract Address');

测试

$ vendor/bin/phpunit