get-mon-balance
Check MON token balance for a specific address on the Monad testnet using the Monad MCP server. Ideal for verifying token holdings and interacting with the Monad blockchain.
Instructions
查询 Monad 测试网地址的 MON 代币余额
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | 需要查询的 Monad 测试网地址 |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"address": {
"description": "需要查询的 Monad 测试网地址",
"type": "string"
}
},
"required": [
"address"
],
"type": "object"
}
Implementation Reference
- src/index.ts:41-70 (handler)The asynchronous handler function that queries the MON token balance for the given address on the Monad testnet using viem's publicClient.getBalance, formats it with 18 decimals, and returns a formatted text response. Handles errors gracefully.async ({ address }) => { try { // 调用接口查询余额 const balance = await publicClient.getBalance({ address: address as `0x${string}`, }); // 返回格式化的查询结果 return { content: [ { type: "text", text: `地址 ${address} 的 MON 余额为:${formatUnits(balance, 18)} MON`, }, ], }; } catch (error) { // 错误处理 return { content: [ { type: "text", text: `查询地址 ${address} 的余额失败:${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- src/index.ts:37-39 (schema)Zod schema defining the input parameter 'address' as a string with description in Chinese: '需要查询的 Monad 测试网地址' (The Monad testnet address to query).{ address: z.string().describe("需要查询的 Monad 测试网地址"), },
- src/index.ts:31-71 (registration)Registration of the 'get-mon-balance' tool using server.tool method, including the tool name, Chinese description '查询 Monad 测试网地址的 MON 代币余额' (Query MON token balance of Monad testnet address), input schema, and inline handler function.server.tool( // 功能标识符 "get-mon-balance", // 功能说明 "查询 Monad 测试网地址的 MON 代币余额", // 参数定义 { address: z.string().describe("需要查询的 Monad 测试网地址"), }, // 功能实现 async ({ address }) => { try { // 调用接口查询余额 const balance = await publicClient.getBalance({ address: address as `0x${string}`, }); // 返回格式化的查询结果 return { content: [ { type: "text", text: `地址 ${address} 的 MON 余额为:${formatUnits(balance, 18)} MON`, }, ], }; } catch (error) { // 错误处理 return { content: [ { type: "text", text: `查询地址 ${address} 的余额失败:${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );