get_native_balance
Retrieve the native token balance for a specific address across various networks, including BSC, Ethereum, and others, with the option to specify the desired network or chain ID.
Instructions
Get native token balance for an address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | The address to check balance for | |
| network | No | Network name (e.g. 'bsc', 'opbnb', 'ethereum', 'base', etc.) or chain ID. Supports others main popular networks. Defaults to BSC mainnet. | bsc |
Implementation Reference
- src/evm/modules/tokens/tools.ts:35-57 (registration)Full registration of the get_native_balance MCP tool, including description, input schema, and handler function."get_native_balance", "Get native token balance for an address", { network: defaultNetworkParam, address: z .string() .optional() .describe("The address to check balance for"), privateKey: privateKeyParam }, async ({ network, address, privateKey }) => { try { const result = await services.getNativeBalance( address || privateKeyToAccount(privateKey as Hex).address, network ) return mcpToolRes.success(result) } catch (error) { return mcpToolRes.error(error, "fetching native token balance") } } )
- src/evm/services/balance.ts:13-37 (handler)Core handler logic for fetching native balance: resolves address/ENS, uses viem to get balance, formats with ether units and metadata.export async function getNativeBalance( addressOrEns: string, network = "bsc" ): Promise<{ raw: bigint formatted: string network: string symbol: string decimals: number }> { // Resolve ENS name to address if needed const address = await resolveAddress(addressOrEns, network) const client = getPublicClient(network) const balance = await client.getBalance({ address }) const nativeCurrency = client.chain?.nativeCurrency return { raw: balance, formatted: formatEther(balance), network, symbol: nativeCurrency?.symbol ?? "Unknown", decimals: nativeCurrency?.decimals ?? 18 } }
- Input schema for get_native_balance tool using Zod: network, optional address, optional privateKey (to derive address).{ network: defaultNetworkParam, address: z .string() .optional() .describe("The address to check balance for"), privateKey: privateKeyParam },
- Tool wrapper handler: derives address from privateKey if needed, calls getNativeBalance service, wraps response in MCP format.async ({ network, address, privateKey }) => { try { const result = await services.getNativeBalance( address || privateKeyToAccount(privateKey as Hex).address, network ) return mcpToolRes.success(result) } catch (error) { return mcpToolRes.error(error, "fetching native token balance") } }