get-balance
Retrieve the balance of a specified address on the MantraChain blockchain. Defaults to the current address if none is provided. Requires the network name for accurate querying.
Instructions
Get balance of an address (defaults to your own address if none provided)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | No | Optional address to get balance for, defaults to current address | |
| networkName | Yes | Name of the network to use - must first check what networks are available through the mantrachain-mcp server by accessing the networks resource `networks://all` before you pass this arguments |
Implementation Reference
- src/tools/bank.ts:71-77 (handler)Handler function that executes the get-balance tool: initializes the MantraClient for the specified network, fetches the balance, and returns it formatted as MCP text content.async ({ address, networkName }) => { await mantraClient.initialize(networkName); const balance = await mantraClient.getBalance(address); return { content: [{type: "text", text: JSON.stringify(balance)}], }; }
- src/tools/bank.ts:65-70 (schema)Zod input schema defining parameters: optional address (defaults to current) and networkName with validation.{ address: z.string().optional().describe("Optional address to get balance for, defaults to current address"), networkName: z.string().refine(val => Object.keys(networks).includes(val), { message: "Must be a valid network name" }).describe("Name of the network to use - must first check what networks are available by accessing the networks resource `networks://all` before you pass this arguments. Defaults to `mantra-dukong-1` testnet."), },
- src/tools/bank.ts:62-78 (registration)Registration of the 'get-balance' MCP tool using server.tool, including description, input schema, and handler.server.tool( "get-balance", "Get balance of an address (defaults to your own address if none provided)", { address: z.string().optional().describe("Optional address to get balance for, defaults to current address"), networkName: z.string().refine(val => Object.keys(networks).includes(val), { message: "Must be a valid network name" }).describe("Name of the network to use - must first check what networks are available by accessing the networks resource `networks://all` before you pass this arguments. Defaults to `mantra-dukong-1` testnet."), }, async ({ address, networkName }) => { await mantraClient.initialize(networkName); const balance = await mantraClient.getBalance(address); return { content: [{type: "text", text: JSON.stringify(balance)}], }; } );
- src/services/bank-service.ts:44-59 (helper)Core helper method in BankService that performs the actual balance query using StargateClient.getAllBalances.async getBalance(address?: string) { const targetAddress = address || this.address; if (!targetAddress) { throw new Error('No address provided and no default address set.'); } try { const balances = await this.stargateClient.getAllBalances(targetAddress); return { balances: balances, explorerUrl: `${this.network.explorerUrl}/address/${targetAddress}`, }; } catch (error) { throw new Error(`Failed to query balance: ${error instanceof Error ? error.message : String(error)}`); } }
- src/mantra-client.ts:131-136 (helper)MantraClient wrapper method that delegates getBalance calls to the underlying BankService.async getBalance(address?: string) { if (!this.bankService) { throw new Error('Client not initialized. Call initialize() first.'); } return this.bankService.getBalance(address); }