⚠️Blast API (blastapi.io) ends Oct 31. Migrate to Dwellir and skip Alchemy's expensive compute units.
Switch Today →
Skip to main content

wallet/getaccountbalance

Lightning-Fast Balance Queries

Dwellir's TRON nodes return balance information in under 30ms with real-time synchronization. Get account balances with block height confirmation for accurate balance tracking.

Get your free API key →

Retrieve the balance of a TRON account including TRX and all token holdings with the specific block height at which the balance was calculated.

Use Cases

wallet/getaccountbalance is perfect for:

  • Wallet Applications - Display real-time balance updates
  • Exchange Integration - Track deposit confirmations
  • Portfolio Trackers - Monitor multiple asset balances
  • Payment Verification - Confirm payment receipt at specific block
  • Audit Systems - Historical balance verification

Parameters

ParameterTypeRequiredDescription
account_identifierobjectYesAccount identification object
account_identifier.addressstringYesTRON address (Base58 or Hex)
block_identifierobjectNoSpecific block for balance query
block_identifier.hashstringNoBlock hash
block_identifier.numbernumberNoBlock height
visiblebooleanNoUse Base58 format (default: true)

Request Example

{
"account_identifier": {
"address": "TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN"
},
"block_identifier": {
"number": 58234567
},
"visible": true
}

Response Fields

FieldTypeDescription
balancenumberTRX balance in SUN (1 TRX = 1,000,000 SUN)
block_identifierobjectBlock at which balance was calculated
block_identifier.hashstringBlock hash
block_identifier.numbernumberBlock height
trc10arrayTRC10 token balances
trc20arrayTRC20 token balances (requires indexing)

Implementation Examples

const TRON_API = 'https://api-tron-mainnet.n.dwellir.com/YOUR_API_KEY';

// Get current balance
async function getAccountBalance(address) {
const response = await fetch(`${TRON_API}/wallet/getaccountbalance`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
account_identifier: {
address: address
},
visible: true
})
});

if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}

return await response.json();
}

// Get balance at specific block
async function getBalanceAtBlock(address, blockNumber) {
const response = await fetch(`${TRON_API}/wallet/getaccountbalance`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
account_identifier: {
address: address
},
block_identifier: {
number: blockNumber
},
visible: true
})
});

return await response.json();
}

// Comprehensive balance tracker
class BalanceTracker {
constructor(apiKey) {
this.apiUrl = `https://api-tron-mainnet.n.dwellir.com/${apiKey}`;
}

async getFullBalance(address) {
try {
const balance = await this.getBalance(address);

return {
trx: {
amount: balance.balance / 1_000_000,
sun: balance.balance
},
block: {
height: balance.block_identifier.number,
hash: balance.block_identifier.hash
},
trc10: this.formatTokenBalances(balance.trc10 || []),
trc20: this.formatTokenBalances(balance.trc20 || []),
timestamp: new Date().toISOString()
};
} catch (error) {
console.error('Balance fetch error:', error);
throw error;
}
}

async getBalance(address) {
const response = await fetch(`${this.apiUrl}/wallet/getaccountbalance`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
account_identifier: { address },
visible: true
})
});

if (!response.ok) {
throw new Error(`Balance query failed: ${response.statusText}`);
}

return await response.json();
}

formatTokenBalances(tokens) {
return tokens.map(token => ({
id: token.key || token.contract_address,
balance: token.value,
name: token.name || 'Unknown Token'
}));
}

async compareBalances(address, blockNumbers) {
const balances = await Promise.all(
blockNumbers.map(block => this.getBalanceAtBlock(address, block))
);

return balances.map((balance, index) => ({
block: blockNumbers[index],
trx: balance.balance / 1_000_000,
tokenCount: (balance.trc10?.length || 0) + (balance.trc20?.length || 0)
}));
}

async getBalanceAtBlock(address, blockNumber) {
const response = await fetch(`${this.apiUrl}/wallet/getaccountbalance`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
account_identifier: { address },
block_identifier: { number: blockNumber },
visible: true
})
});

return await response.json();
}
}

// Usage examples
(async () => {
const tracker = new BalanceTracker('YOUR_API_KEY');

try {
// Get current balance
const balance = await tracker.getFullBalance('TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN');
console.log(`Current balance: ${balance.trx.amount} TRX at block ${balance.block.height}`);

// Compare historical balances
const history = await tracker.compareBalances(
'TRX6Q82wMqWNbCCmJPLz9mR8AZwqvUU2pN',
[58234567, 58234568, 58234569]
);
console.log('Balance history:', history);

} catch (error) {
console.error('Error:', error);
}
})();

Response Examples

Successful Response

{
"balance": 15000000000,
"block_identifier": {
"hash": "0000000003787ac74d9bb8f8c9c59ac3f3e3b9b8c9e3e8f9c8d7e8f9c8d7e8f9",
"number": 58234567
},
"trc10": [
{
"key": "1002000",
"value": 50000000
}
],
"trc20": [
{
"contract_address": "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
"value": "100000000",
"name": "USDT",
"symbol": "USDT",
"decimals": 6
}
]
}

Empty Account Response

{
"balance": 0,
"block_identifier": {
"hash": "0000000003787ac74d9bb8f8c9c59ac3f3e3b9b8c9e3e8f9c8d7e8f9c8d7e8f9",
"number": 58234567
},
"trc10": [],
"trc20": []
}

Common Use Cases

1. Real-Time Balance Display

async function displayBalance(address) {
const balance = await getAccountBalance(address);

return {
display: `${(balance.balance / 1_000_000).toFixed(6)} TRX`,
blockHeight: balance.block_identifier.number,
tokens: [
...(balance.trc10 || []).map(t => ({ type: 'TRC10', ...t })),
...(balance.trc20 || []).map(t => ({ type: 'TRC20', ...t }))
]
};
}

2. Payment Confirmation

async function confirmPayment(address, expectedAmount, minConfirmations = 19) {
const balance = await getAccountBalance(address);
const currentBlock = balance.block_identifier.number;

// Check if payment received
const received = balance.balance >= expectedAmount;

// Get latest block to check confirmations
const latestBlock = await getLatestBlock();
const confirmations = latestBlock.number - currentBlock;

return {
received,
amount: balance.balance,
confirmations,
confirmed: received && confirmations >= minConfirmations
};
}

3. Balance Change Detection

class BalanceMonitor {
constructor(apiKey, address) {
this.apiKey = apiKey;
this.address = address;
this.lastBalance = null;
}

async checkForChanges() {
const current = await getAccountBalance(this.address);

if (this.lastBalance === null) {
this.lastBalance = current.balance;
return { changed: false, balance: current.balance };
}

const changed = current.balance !== this.lastBalance;
const difference = current.balance - this.lastBalance;

this.lastBalance = current.balance;

return {
changed,
balance: current.balance,
difference,
direction: difference > 0 ? 'received' : 'sent',
amount: Math.abs(difference) / 1_000_000
};
}
}

Error Handling

Error CodeDescriptionSolution
400Invalid address formatVerify address is valid Base58 or Hex
404Block not foundCheck block number exists
429Rate limit exceededImplement backoff strategy
500Internal server errorRetry with exponential backoff
async function safeGetBalance(address, retries = 3) {
for (let i = 0; i < retries; i++) {
try {
return await getAccountBalance(address);
} catch (error) {
if (i === retries - 1) throw error;

// Exponential backoff
await new Promise(resolve =>
setTimeout(resolve, Math.pow(2, i) * 1000)
);
}
}
}

Best Practices

  1. Cache Results - Balance queries can be cached for 3 seconds
  2. Batch Requests - Query multiple accounts in parallel
  3. Monitor Changes - Use block height to detect balance changes
  4. Handle Errors - Implement proper error handling and retries
  5. Validate Addresses - Check address format before querying

Need help? Contact support or check our TRON documentation.