The Tron (TRON) blockchain has emerged as one of the most dynamic and high-performance networks in the decentralized ecosystem, supporting fast transactions, smart contracts, and a wide range of TRC20 tokens like USDT. For developers, investors, and blockchain enthusiasts, understanding how to programmatically retrieve essential account data—such as TRX balance, USDT holdings, available bandwidth, and energy—is crucial for building applications or managing digital assets effectively.
This guide walks you through the process of fetching real-time wallet information from the Tron network using public APIs. Whether you're integrating blockchain functionality into your app or monitoring your own holdings, this technical walkthrough will help you get started with minimal setup.
Retrieving TRX and USDT Balances via TronGrid API
To check a Tron wallet’s native TRX and TRC20 token balances (like USDT), we can use the TronGrid REST API, which provides reliable access to on-chain data without requiring a local node.
👉 Discover how easy blockchain data access can be with powerful tools
The following C# method demonstrates how to fetch both TRX and USDT (TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t) balances from a given wallet address:
private static Tuple<decimal, decimal> GetBalanceByAddressByOnline(string address)
{
var tuple = new Tuple<decimal, decimal>(0, 0);
var responseString = HttpClientHelper.Get($"https://api.trongrid.io/v1/accounts/{address}");
if (string.IsNullOrEmpty(responseString)) return tuple;
var responseObject = JsonConvert.DeserializeObject<dynamic>(responseString);
if (responseObject == null || !(bool)responseObject.success) return tuple;
if (responseObject.data == null || responseObject.data.Count == 0) return tuple;
var obj = responseObject.data[0];
decimal trxBalance = 0;
var balance = obj.balance;
if (balance != null) trxBalance = (long)balance / 1_000_000m; // Convert from sun to TRX
decimal usdtBalance = 0;
var trc20Tokens = obj.trc20 ?? new object();
foreach (var token in trc20Tokens)
{
var usdtValue = token["TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"];
if (usdtValue != null)
{
usdtBalance = (long)usdtValue / 1_000_000m; // USDT uses 6 decimal places
break;
}
}
return new Tuple<decimal, decimal>(trxBalance, usdtBalance);
}Key Points:
- The endpoint
https://api.trongrid.io/v1/accounts/{address}returns full account details. - TRX is denominated in sun (1 TRX = 1,000,000 sun), so division by 1,000,000 converts it to human-readable form.
- USDT on Tron uses the contract address
TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6tand also has 6 decimals.
Checking Available Bandwidth and Energy
On the Tron network, every transaction consumes either bandwidth or energy, depending on its type:
- Simple transfers consume bandwidth.
- Smart contract interactions require energy, which is obtained by staking TRX.
You can retrieve your remaining resources using the getaccountresource API:
private static Tuple<long, long> GetAccountResource(string address)
{
var tuple = new Tuple<long, long>(0, 0);
var requestObj = new { address = address, visible = true };
var json = JsonConvert.SerializeObject(requestObj);
var responseString = HttpClientHelper.Post("https://api.trongrid.io/wallet/getaccountresource", json, Encoding.UTF8);
if (string.IsNullOrEmpty(responseString)) return tuple;
var responseObject = JsonConvert.DeserializeObject<dynamic>(responseString);
if (responseObject == null) return tuple;
long freeNetLimit = responseObject.freeNetLimit != null ? (long)responseObject.freeNetLimit : 0;
long freeNetUsed = responseObject.freeNetUsed != null ? (long)responseObject.freeNetUsed : 0;
long netLimit = responseObject.NetLimit != null ? (long)responseObject.NetLimit : 0;
long netUsed = responseObject.NetUsed != null ? (long)responseObject.NetUsed : 0;
long totalNetRemaining = (freeNetLimit - freeNetUsed) + (netLimit - netUsed);
long energyLimit = responseObject.EnergyLimit != null ? (long)responseObject.EnergyLimit : 0;
long energyUsed = responseObject.EnergyUsed != null ? (long)responseObject.EnergyUsed : 0;
long energyRemaining = energyLimit - energyUsed;
return new Tuple<long, long>(totalNetRemaining, energyRemaining);
}Understanding Resource Metrics:
- Free Bandwidth: All accounts receive a small daily allocation.
- Staked Bandwidth: Increased by freezing TRX.
- Energy: Used for executing smart contracts; must be staked separately.
Knowing your available resources helps avoid failed transactions due to insufficient bandwidth or energy.
HTTP Client Helper for API Requests
To make secure and standardized HTTP calls to TronGrid, encapsulate your requests in a helper class. This ensures consistent headers, error handling, and formatting.
public static class HttpClientHelper
{
public static string Get(string url)
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "GET";
request.ContentType = "application/json";
request.Accept = "application/json";
request.Headers.Set("TRON-PRO-API-KEY", "your_api_key_here"); // Replace with your key
using var response = (HttpWebResponse)request.GetResponse();
using var stream = response.GetResponseStream();
using var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
public static string Post(string url, string requestBody, Encoding encoding, int timeout = 12000)
{
var request = (HttpWebRequest)WebRequest.Create(url);
return Post(request, requestBody, encoding, timeout);
}
private static HttpWebResponse Post(HttpWebRequest request, string requestBody, Encoding encoding, int timeout = 12000)
{
var bytes = encoding.GetBytes(requestBody);
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = bytes.Length;
request.Timeout = timeout;
request.Accept = "application/json";
request.Headers.Set("TRON-PRO-API-KEY", "your_api_key_here");
using (var stream = request.GetRequestStream())
{
stream.Write(bytes, 0, bytes.Length);
}
return (HttpWebResponse)request.GetResponse();
}
}🔐 Security Tip: Never hardcode your TronGrid API key in production. Use environment variables or secure configuration stores.
👉 Learn how top developers interact with blockchain APIs securely and efficiently
Core Keywords for SEO Optimization
To enhance search visibility and align with user intent, here are the primary keywords naturally integrated throughout this article:
- Tron wallet balance
- Check TRX balance
- USDT on Tron
- Tron bandwidth and energy
- Get USDT balance programmatically
- Tron API tutorial
- Freeze TRX for energy
- Blockchain resource management
These terms reflect common queries from developers and crypto users seeking technical solutions on the Tron network.
Frequently Asked Questions
How do I get a free TronGrid API key?
You can register for a free API key at TronGrid.io. It allows thousands of requests per day and is ideal for development and small-scale projects.
Why does my USDT balance show zero even though I have tokens?
Ensure you're checking the correct contract address: TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t. Also, some wallets only display tokens after an interaction or token registration.
Can I increase my bandwidth without staking TRX?
Yes. Every Tron account receives a small amount of free bandwidth daily. However, for frequent usage, freezing TRX is recommended to obtain more stable resources.
What happens if I run out of bandwidth or energy?
Transactions will fail until you either wait for free bandwidth to refill or stake more TRX to obtain additional resources.
Is it safe to use public APIs like TronGrid?
Yes, when used correctly. Always validate responses, handle errors gracefully, and protect your API keys. Avoid exposing them in client-side code.
How often should I refresh balance data?
For real-time applications, polling every 15–30 seconds is sufficient. For high-frequency needs, consider WebSocket-based services or caching mechanisms.
Final Thoughts
Accessing wallet balances and resource metrics on the Tron blockchain is straightforward with the right tools and understanding. By leveraging TronGrid's robust API and structuring clean HTTP requests, developers can build powerful dApps, monitoring dashboards, or automated trading systems.
Whether you're retrieving TRX, tracking USDT holdings, or managing bandwidth and energy, this foundation equips you with the essentials to interact confidently with the Tron ecosystem.
👉 Explore more blockchain development tools and start building today