zetrix_sdk_get_balance
Retrieve the current balance for a specified Zetrix blockchain account address using the official SDK.
Instructions
Get account balance using the official SDK
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | The Zetrix account address |
Implementation Reference
- src/zetrix-sdk.ts:108-127 (handler)Core handler implementation: Queries account balance using the official zetrix-sdk-nodejs package via dynamic import and SDK initialization.async getBalance(address: string): Promise<ZetrixSDKBalance> { await this.initSDK(); try { const result = await this.sdk.account.getBalance(address); if (result.errorCode !== 0) { throw new Error(result.errorDesc || `SDK Error: ${result.errorCode}`); } return { address, balance: result.result.balance, }; } catch (error) { throw new Error( `Failed to get balance: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/index.ts:428-441 (registration)Tool registration in the MCP tools array, including name, description, and input schema.{ name: "zetrix_sdk_get_balance", description: "Get account balance using the official SDK", inputSchema: { type: "object", properties: { address: { type: "string", description: "The Zetrix account address", }, }, required: ["address"], }, },
- src/index.ts:1151-1164 (handler)MCP server dispatcher: Handles tool call by invoking ZetrixSDK.getBalance and formatting response.case "zetrix_sdk_get_balance": { if (!args) { throw new Error("Missing arguments"); } const balance = await zetrixSDK.getBalance(args.address as string); return { content: [ { type: "text", text: JSON.stringify(balance, null, 2), }, ], }; }
- src/zetrix-sdk.ts:64-78 (helper)Helper method to lazily initialize the official Zetrix SDK instance.private async initSDK() { if (this.sdk) return; try { // Dynamically import the CommonJS module const module = await import("zetrix-sdk-nodejs"); const ZtxChainSDK = module.default || module; this.sdk = new ZtxChainSDK({ host: this.host }); } catch (error) { throw new Error( `Failed to initialize Zetrix SDK: ${error instanceof Error ? error.message : String(error)}` ); } }