Reading chain state
Every TronProvider exposes a set of read methods. None of them require a
signer — a plain ProviderBuilder::new().connect_grpc(...) provider can run them
all.
Blocks
let block = provider.get_now_block().await?;
println!("number : {}", block.number);
println!("timestamp : {} ms", block.timestamp);
println!("hash : {:#x}", block.hash);BlockInfo carries the number, hash (B256), and timestamp.
Accounts
let account = provider.get_account(address).await?;
println!("balance : {} TRX", account.balance);
println!("name : {}", account.name);
println!("activated : {}", account.is_activated);
// Stake 2.0 frozen balances
for f in &account.frozen_v2 {
println!("staked {} for {:?}", f.amount, f.resource);
}AccountInfo also exposes unfrozen_v2 (in-progress unfreezes), votes,
permissions (multisig), and trc10_balances.
Resources
let res = provider.get_account_resource(address).await?;
println!("bandwidth : {}/{}", res.bandwidth_used, res.bandwidth_limit);
println!("energy : {}/{}", res.energy_used, res.energy_limit);
println!("tron power: {}", res.tron_power_used);AccountResource separates free vs. staked bandwidth, energy, delegated-out
totals, received-via-delegation totals, and TRON Power limits.
Delegations and staking limits
use tronz::primitives::ResourceCode;
// Who is this account delegating to / receiving from?
let idx = provider.get_delegated_resource_index(address).await?;
println!("delegating to : {} accounts", idx.to_accounts.len());
println!("receiving from : {} accounts", idx.from_accounts.len());
// Max still delegatable, per resource.
let max_energy = provider.get_can_delegate_max(address, ResourceCode::Energy).await?;
// Unclaimed staking rewards.
let reward = provider.get_reward(address).await?;
println!("pending reward : {}", reward);Transactions and receipts
let tx = provider
.get_transaction(tx_id)
.await?
.ok_or_else(|| anyhow::anyhow!("transaction not found"))?;
// `get_transaction_info` returns `None` until the node has indexed the tx.
let info = provider
.get_transaction_info(tx_id)
.await?
.ok_or_else(|| anyhow::anyhow!("transaction not found or not yet confirmed"))?;
println!("block : {}", info.block_number);
println!("status : {:?}", info.status);
println!("energy : {}", info.receipt.energy_usage);Both get_transaction and get_transaction_info return Option: None means
the node has not found or indexed that transaction. Likewise,
get_block_by_number, get_exchange_by_id, and get_market_order_by_id return
None when their requested value is missing. tronz also normalizes java-tron's
"order not found in store" gRPC error into None. Once present,
TransactionInfo is the receipt: block number/timestamp, status
(Success/Failed), energy and bandwidth usage and fees, the detailed
contract_result, emitted logs, and a revert_reason when a contract
reverts. See Transaction lifecycle.
Other reads
| Method | Returns |
|---|---|
chain_parameters() | HashMap<String, i64> of network parameters |
get_node_info() | FullNode head and peer summary |
get_dynamic_properties() | Head block number, ID, and timestamp |
get_blocks_by_latest_num(count) | Most recent blocks |
get_blocks_by_limit(start, end) | Blocks in a half-open number range |
get_account_net(addr) | Bandwidth and energy usage/limits |
get_contract_info(addr) | Contract metadata incl. deployed bytecode |
list_witnesses() | All super representatives and candidates |
get_paginated_now_witness_list(offset, limit) | A page of SRs sorted by live vote count |
get_pending_size() | Number of pending transactions |
get_pending_transactions() | Transactions in the pending pool |
get_bandwidth_prices() / get_energy_prices() | Resource price history |
get_can_withdraw_unfreeze_amount(addr, ts_ms) | TRX withdrawable from expired unfreezes |
get_available_unfreeze_count(addr) | Remaining unfreeze slots (max 32) |
estimate_energy(params) | Estimated energy for a contract call |
Protocol-specific reads such as proposals, exchanges, and market orders are provided by extension traits.
