pub struct TronClient { /* private fields */ }Expand description
Tron blockchain client.
Uses TronGrid REST API for data retrieval.
Implementations§
Source§impl TronClient
impl TronClient
Sourcepub fn new(config: &ChainsConfig) -> Result<Self>
pub fn new(config: &ChainsConfig) -> Result<Self>
Creates a new Tron client with the given configuration.
§Arguments
config- Chain configuration containing API endpoint and keys
§Returns
Returns a configured TronClient instance.
§Examples
use scope::chains::TronClient;
use scope::config::ChainsConfig;
let config = ChainsConfig::default();
let client = TronClient::new(&config).unwrap();Sourcepub fn new_with_http(
config: &ChainsConfig,
http: Arc<dyn HttpClient>,
) -> Result<Self>
pub fn new_with_http( config: &ChainsConfig, http: Arc<dyn HttpClient>, ) -> Result<Self>
Creates a new Tron client with a pre-built HTTP transport.
Sourcepub fn with_api_url(api_url: &str) -> Self
pub fn with_api_url(api_url: &str) -> Self
Sourcepub fn chain_name(&self) -> &str
pub fn chain_name(&self) -> &str
Returns the chain name.
Sourcepub fn native_token_symbol(&self) -> &str
pub fn native_token_symbol(&self) -> &str
Returns the native token symbol.
Sourcepub async fn get_balance(&self, address: &str) -> Result<Balance>
pub async fn get_balance(&self, address: &str) -> Result<Balance>
Fetches the TRX balance for an address.
§Arguments
address- The Tron address (T-address format)
§Returns
Returns a Balance struct with the balance in multiple formats.
§Errors
Returns ScopeError::InvalidAddress if the address format is invalid.
Returns ScopeError::Request if the API request fails.
Sourcepub async fn get_trc20_balances(
&self,
address: &str,
) -> Result<Vec<Trc20TokenBalance>>
pub async fn get_trc20_balances( &self, address: &str, ) -> Result<Vec<Trc20TokenBalance>>
Fetches TRC-20 token balances for an address.
Uses the TronGrid /v1/accounts/{address} endpoint which includes
TRC-20 balances in the account data.
Sourcepub async fn get_token_info(&self, contract_address: &str) -> Result<Token>
pub async fn get_token_info(&self, contract_address: &str) -> Result<Token>
Fetches TRC-20 token info from Tronscan API.
Returns symbol, name, decimals, and other metadata for a TRC-20 contract.
Sourcepub async fn get_token_holders(
&self,
contract_address: &str,
limit: u32,
) -> Result<Vec<TokenHolder>>
pub async fn get_token_holders( &self, contract_address: &str, limit: u32, ) -> Result<Vec<TokenHolder>>
Fetches top TRC-20 token holders from Tronscan API.
Returns holders sorted by balance (largest first).
Sourcepub async fn get_token_holder_count(
&self,
contract_address: &str,
) -> Result<u64>
pub async fn get_token_holder_count( &self, contract_address: &str, ) -> Result<u64>
Fetches total holder count for a TRC-20 token.
Sourcepub async fn enrich_balance_usd(&self, balance: &mut Balance)
pub async fn enrich_balance_usd(&self, balance: &mut Balance)
Enriches a balance with a USD value using DexScreener price lookup.
Note: Tron native token price lookup via DexScreener is not yet supported. This is a placeholder that uses CoinGecko-style simple price API as fallback.
Sourcepub async fn get_transaction(&self, hash: &str) -> Result<Transaction>
pub async fn get_transaction(&self, hash: &str) -> Result<Transaction>
Fetches transaction details by hash.
§Arguments
hash- The transaction hash
§Returns
Returns Transaction details.
Sourcepub async fn get_transactions(
&self,
address: &str,
limit: u32,
) -> Result<Vec<Transaction>>
pub async fn get_transactions( &self, address: &str, limit: u32, ) -> Result<Vec<Transaction>>
Fetches recent transactions for an address.
§Arguments
address- The address to querylimit- Maximum number of transactions
§Returns
Returns a vector of Transaction objects.
Sourcepub async fn get_block_number(&self) -> Result<u64>
pub async fn get_block_number(&self) -> Result<u64>
Fetches the current block number.