PHP code example of just-luka / php-tron
1. Go to this page and download the library: Download just-luka/php-tron library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
just-luka / php-tron example snippets bash
composer php
use Trx\TrxClient;
$tron = new TrxClient(apiKey: 'YOUR-API-KEY');
php
use Trx\TrxClient;
$tron = new TrxClient(apiKey: 'YOUR-API-KEY', testMode: true);
php
$wallet = $tron->wallet()->create();
echo $wallet->getAddress(); // T...
echo $wallet->getPrivateKey(); // 64-char hex
php
$wallets = $tron->wallet()->createMultiple(5);
foreach ($wallets as $wallet) {
echo $wallet->getAddress();
}
php
$account = $tron->account('TDrbCtdTj5KMo67mtQw2XXu5eTqwwVYoKz')->explore();
echo $account->balance; // SUN (1 TRX = 1,000,000 SUN)
echo $account->address;
echo $account->createTime;
echo $account->netWindowSize;
echo $account->ownerPermissionThreshold;
echo $account->activePermissionThreshold;
// Energy & bandwidth resources
echo $account->resource->energyWindowSize;
echo $account->resource->energyUsage;
echo $account->resource->energyWindowOptimized;
// TRC20 token balances [ ['token_contract_address' => balance], ... ]
var_dump($account->trc20);
php
$blocks = $tron->account('TDrbCtdTj5KMo67mtQw2XXu5eTqwwVYoKz')->blocks();
foreach ($blocks as $block) {
echo $block->txID;
echo $block->blockNumber;
echo $block->blockTimestamp;
echo $block->contractBalance;
echo $block->contractOwnerAddress;
echo $block->contractReceiverAddress;
echo $block->netFee;
echo $block->energyFee;
}
php
$transactions = $tron->account('TDrbCtdTj5KMo67mtQw2XXu5eTqwwVYoKz')->transactions();
foreach ($transactions as $tx) {
echo $tx->transactionId;
echo $tx->from;
echo $tx->to;
echo $tx->value;
echo $tx->blockTimestamp;
echo $tx->type;
// Token info
echo $tx->tokenInfo->symbol;
echo $tx->tokenInfo->name;
echo $tx->tokenInfo->decimals;
echo $tx->tokenInfo->address;
}
php
$contract = $tron->contract('TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t');
$blocks = $contract->blocks();
$tokens = $contract->tokens();
php
$asset->id;
$asset->name;
$asset->abbr;
$asset->description;
$asset->url;
$asset->totalSupply;
$asset->precision;
$asset->ownerAddress;
$asset->startTime;
$asset->endTime;
php
$account = $tron->account('TDrbCtdTj5KMo67mtQw2XXu5eTqwwVYoKz');
$transactions = $account
->filterOnlyConfirmed()
->filterLimit(50)
->filterContractAddress('TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t') // USDT
->filterMinTimestamp('1700000000000')
->filterMaxTimestamp('1710000000000')
->filterOrderBy('block_timestamp,asc')
->transactions();