ddv88/tron-api-v2

A PHP API for interacting with Tron (Trx) v2

dev-master 2024-12-17 04:10 UTC

This package is not auto-updated.

Last update: 2025-06-03 03:25:29 UTC


README

Реинкарнация заброшенного репозитория https://github.com/iexbase/tron-api

Latest Stable Version Software License Total Downloads

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