PHP code example of iexbase / tron-api

1. Go to this page and download the library: Download iexbase/tron-api 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/ */

    

iexbase / tron-api example snippets




declare(strict_types=1);

use IEXBase\TronAPI\Configuration\NodeConfiguration;
use IEXBase\TronAPI\Enum\Network;
use IEXBase\TronAPI\Tron;
use IEXBase\TronAPI\Value\Address;

$tron = Tron::create(NodeConfiguration::forNetwork(
    Network::Shasta,
    getenv('TRON_API_KEY') ?: null,
));

$account = $tron->accounts()->get(
    Address::fromBase58('T...'),
);

echo $account?->balance->decimalValue() ?? 'Account is not activated', PHP_EOL;

use IEXBase\TronAPI\Configuration\NodeConfiguration;
use IEXBase\TronAPI\Tron;

$configuration = NodeConfiguration::custom(
    fullNodeUri: 'http://full-node.internal:8090',
    solidityNodeUri: 'http://solidity-node.internal:8091',
    indexerUri: 'https://indexer.example.com',
    jsonRpcUri: 'http://full-node.internal:8545',
);

$tron = Tron::create(
    $configuration,
    accountHistoryProvider: $yourHistoryProvider,
    eventProvider: $yourEventProvider,
    tokenIndexProvider: $yourTokenProvider,
);

use IEXBase\TronAPI\Value\Amount;

$amount = Amount::fromDecimal('12.345678');

echo $amount->atomicValue();  // 12345678
echo $amount->decimalValue(); // 12.345678

use IEXBase\TronAPI\Crypto\LocalPrivateKeySigner;
use IEXBase\TronAPI\Value\Address;
use IEXBase\TronAPI\Value\Amount;
use IEXBase\TronAPI\Value\Memo;

$privateKey = getenv('TRON_PRIVATE_KEY');
if (!is_string($privateKey) || $privateKey === '') {
    throw new RuntimeException('TRON_PRIVATE_KEY is , $signer);
$result = $tron->transactions()->broadcast($signed);

use IEXBase\TronAPI\Crypto\MessageSigner;
use IEXBase\TronAPI\Crypto\Wallet\ExtendedKey;
use IEXBase\TronAPI\Crypto\Wallet\HierarchicalWallet;
use IEXBase\TronAPI\Crypto\Wallet\MnemonicPhrase;

$mnemonic = getenv('TRON_MNEMONIC');
if (!is_string($mnemonic) || $mnemonic === '') {
    throw new RuntimeException('TRON_MNEMONIC is $accountXpub)
    ->derivePath('0/1')
    ->address();

$signature = MessageSigner::sign('Sign in to Example', $account->signer());
$isValid = MessageSigner::verify(
    'Sign in to Example',
    $signature->toMessageHex(),
    $account->address(),
);
bash
TRON_NETWORK=shasta \
TRON_API_KEY=... \
TRON_ADDRESS=T... \
php examples/02-account-block-and-network.php