ddv88 / tron-api-v2
A PHP API for interacting with Tron (Trx) v2
dev-master
2024-12-17 04:10 UTC
Requires
- php: >=7.4
- ext-bcmath: *
- ext-json: *
- comely-io/data-types: ^1.0
- guzzlehttp/guzzle: ^7.2
- iexbase/web3.php: ^2.0.1
- kornrunner/secp256k1: ^0.2
- simplito/elliptic-php: ^1.0
Requires (Dev)
- phpunit/phpunit: ^6.0
This package is not auto-updated.
Last update: 2025-06-03 03:25:29 UTC
README
Реинкарнация заброшенного репозитория https://github.com/iexbase/tron-api
Install
> composer require ddv88/tron-api-v2 --ignore-platform-reqs
Пример создания контракта USDT
try {
$tron = new \IEXBase\TronAPI\Tron(
new HttpProvider("https://api.trongrid.io"),
new HttpProvider("https://api.trongrid.io"),
new HttpProvider("https://api.trongrid.io")
);
$tron->setPrivateKey($private_key_from);
$tron->setAddress($address_from);
$amount = 1.0; //USDT
$transaction = $tron->getTransactionBuilder()->triggerSmartContract(
$abi,
$tron->toHex($this->contract), // Адрес контракта
"transfer",
[
$tron->toHex($address_to), // Получатель
$amount * 1000000, // Сумма в SUN
],
1 * 1000000, // Лимит комиссии
$tron->toHex($address_from), // Отправитель
0
);
$signedTransaction = $tron->signTransaction($transaction);
$response = $tron->sendRawTransaction($signedTransaction);
return $response;
} catch (\IEXBase\TronAPI\Exception\TronException $e) {
exit($e->getMessage());
}
Testing
$ vendor/bin/phpunit