TronAPI 6.0 is a strictly typed PHP 8.4 SDK for TRON FullNode, SolidityNode, JSON-RPC, smart contracts, tokens, staking, governance, indexed data, local signing, and hierarchical wallets.
Version 6.0 is a complete architecture rewrite. It is not source-compatible with 5.x. The new API deliberately removes global address/private-key state, floating-point asset values, duplicated route logic, and any native-service dependency on TronGrid.
The default dependency resolution uses Guzzle 8. Applications whose ecosystem still requires the current Guzzle 7 line can use it without replacing the TronAPI transport API.
- PHP 8.4 on a 64-bit platform.
- Extensions:
bcmath,ctype,curl,filter,gmp,hash,json, andmbstring. - Composer 2.
Install the package without bypassing platform checks:
composer require iexbase/tron-api:^6.0<?php
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;The public-network profiles use TronGrid as the default hosted endpoint and indexer adapter. The SDK core is not coupled to it. A local FullNode, a separate SolidityNode, another JSON-RPC server, and any custom indexer can be composed independently:
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,
);jsonRpcUri is the complete endpoint. Use the dedicated port root for a
self-hosted java-tron node (for example http://full-node.internal:8545) or the
provider's exact path when it exposes JSON-RPC through a gateway.
See Node providers for role routing and custom adapter contracts.
TRX values are never represented by float. Amount stores an exact
non-negative decimal count of sun and converts decimal text without precision
loss:
use IEXBase\TronAPI\Value\Amount;
$amount = Amount::fromDecimal('12.345678');
echo $amount->atomicValue(); // 12345678
echo $amount->decimalValue(); // 12.345678Address accepts checksum-verified Base58Check, 21-byte TRON hex, or explicit
20-byte ABI/EVM hex. Conversion never relies on an external node.
A state-changing service builds a transaction and approves its local
TransactionIntent only after the returned node payload is checked against the
requested owner, recipient/contract, amount, token ID, permission, memo, and fee
limit. The SDK also reconstructs the official protobuf Transaction.raw bytes
and requires an exact match with raw_data_hex, so displayed JSON cannot hide a
different payload. Signing occurs locally and broadcasting is a separate
explicit action.
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 required.');
}
$signer = new LocalPrivateKeySigner($privateKey);
$transaction = $tron->transfers()->createTrxTransfer(
$signer->address(),
Address::fromBase58('T...'),
Amount::fromDecimal('1.25'),
Memo::fromText('Invoice 1042'),
);
$signed = $tron->transactions()->appendSignature($transaction, $signer);
$result = $tron->transactions()->broadcast($signed);Imported transactions have no trusted local intent and therefore require an
explicit TransactionIntent before signing. Permission-aware multisignature
workflows use the same verifier and append signatures immutably.
Before signing, estimateBandwidth() calculates the official protobuf size for
the expected signature count. maximumBandwidthBurn() combines it with
$tron->network()->bandwidthUnitPrice(); the result deliberately excludes
available staked/free resources, Energy, account activation, memo, multisignature,
and other operation-specific fixed fees.
The wallet module implements BIP-39, BIP-32, the TRON BIP-44 path
m/44'/195'/account'/change/index, xprv/xpub import/export, and public-only
non-hardened address derivation.
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 required.');
}
$phrase = MnemonicPhrase::parse($mnemonic);
$passphrase = getenv('TRON_PASSPHRASE');
$wallet = HierarchicalWallet::fromMnemonic($phrase, is_string($passphrase) ? $passphrase : '');
$account = $wallet->account("m/44'/195'/0'/0/0");
$accountXpub = $wallet->accountExtendedPublicKey(0);
$watchAddress = ExtendedKey::fromBase58($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(),
);Recovery phrases, passphrases, private keys, xprv chain codes, and provider API keys are redacted from debugger output. Private signers and wallet objects reject serialization. See Security model.
The ABI subsystem supports overloaded functions, constructors, nested tuples,
fixed/dynamic arrays, signed and unsigned integers, bytes, strings, addresses,
return values, custom errors, revert reasons, anonymous events, and indexed log
topics. Solidity aliases are expanded to their canonical types before selector
hashing, and recursive encoded data is bounded before allocation. Complete
calldata can be resolved by its four-byte selector and decoded with
ContractService::decodeFunctionCall().
Typed contract services provide:
- constant calls through confirmed or latest state;
- Energy estimation and state-changing trigger transactions;
- deployment with constructor arguments, fee limit, call value, token value, origin Energy limit, and resource percentage;
- ABI replacement/removal and contract resource settings;
- TRC-20, TRC-721, and TRC-1155 wrappers;
- receipt event decoding and provider-neutral indexed event queries.
Runnable examples are documented in examples/README.md, including local key generation, balances, contract reads/writes, deployment, token standards, ABI events, and revert decoding.
| Entry point | Responsibility |
|---|---|
$tron->accounts() |
Accounts, resources, activation, names, IDs, exact TRC-10 balances |
$tron->blocks() |
Latest, confirmed, hash/number/range, transaction counts |
$tron->transactions() |
Lookup, local signing, intent verification, multisig, broadcast, receipts |
$tron->transfers() |
Verified TRX transfers |
$tron->assets() |
TRC-10 issue/update/query/transfer/participation |
$tron->stake() |
Stake 2.0 freeze, unfreeze, cancel, delegate, reclaim, resource queries |
$tron->legacyStake() |
Explicit Stake 1.0 compatibility operations |
$tron->contracts() |
ABI calls, estimation, writes, deployment, settings, tokens, events |
$tron->permissions() |
Owner/active/witness permissions and operation bitmaps |
$tron->network() |
Node state, peers, chain parameters, prices, synchronization |
$tron->witnesses() |
Super Representatives, votes, rewards, brokerage, candidacy |
$tron->governance() |
Proposals, approvals, cancellation, maintenance schedule |
$tron->exchanges() |
Protocol-native exchange operations |
$tron->market() |
Native market orders and order-book queries |
$tron->jsonRpc() |
Complete documented TRON Ethereum-compatible JSON-RPC surface |
$tron->accountHistory() |
Optional provider-neutral indexed account history |
$tron->events() |
Optional provider-neutral indexed event discovery |
$tron->tokenIndex() |
Optional provider-neutral indexed token discovery |
$tron->api() |
Strict role-aware access to any new native endpoint |
The complete coverage map is documented in API coverage.
Every example is executable and defaults to Shasta for read operations. Any
broadcast requires TRON_BROADCAST=1; transaction examples read private keys
only from the environment and never send them to a node. Examples 01 and 18
print newly generated local private/public values for direct inspection.
TRON_NETWORK=shasta \
TRON_API_KEY=... \
TRON_ADDRESS=T... \
php examples/02-account-block-and-network.phpThe numbered examples cover:
- local account/private-key generation, addresses, and exact amounts;
- accounts, blocks, and network information;
- custom node topology;
- build, verify, sign, and optionally broadcast;
- multisignature permissions;
- TRC-10;
- Stake 2.0;
- contract reads;
- contract writes;
- contract deployment;
- ABI function calldata and event decoding;
- TRC-20, TRC-721, and TRC-1155;
- provider-neutral indexed history;
- JSON-RPC;
- witnesses and governance;
- native exchanges and market orders;
- low-level/current-future endpoint access and active shielded TRC-20 routes;
- BIP-39/BIP-32/xprv/xpub wallets and local key output;
- Message Signature V2.
The protocol reference used by this project is the official TRON developer documentation, current java-tron HTTP API implementation, and TronWeb interoperability behavior.
composer validate --strict
composer audit
composer checkcomposer check runs syntax validation, PHPStan at maximum level, and the full
PHPUnit suite. Network-independent tests use deterministic transports and
official protocol vectors; they never broadcast funds.
TronAPI is released under the MIT License.
Copyright (c) 2018-2026 iEXBase.