Skip to main content
Glama

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
NameRequiredDescriptionDefault
addressYesThe address to check balance for
networkNoNetwork name (e.g. 'bsc', 'opbnb', 'ethereum', 'base', etc.) or chain ID. Supports others main popular networks. Defaults to BSC mainnet.bsc

Implementation Reference

  • 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")
        }
      }
    )
  • 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")
      }
    }

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/bnb-chain/bnbchain-mcp'

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