Skip to main content
Glama
balance.ts1.42 kB
import { Agent } from '../../agent'; import { TokenBalance } from '../../types'; export async function getBalances(agent: Agent, address: string): Promise<TokenBalance[]> { try { const balances: TokenBalance[] = []; // Get XRP balance const accountInfo = await agent.client.request({ command: 'account_info', account: address, ledger_index: 'current' }); balances.push({ currency: 'XRP', value: agent.dropsToXrp(accountInfo.result.account_data.Balance) }); // Get token balances (trust lines) try { const trustLines = await agent.client.request({ command: 'account_lines', account: address, ledger_index: 'current' }); if (trustLines.result.lines) { for (const line of trustLines.result.lines) { balances.push({ currency: line.currency, value: line.balance, issuer: line.account }); } } } catch (error) { // Trust lines might not exist, which is fine } return balances; } catch (error) { throw new Error(`Failed to get balances: ${error instanceof Error ? error.message : 'Unknown error'}`); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/tamago-labs/xrpl-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server