Skip to main content
Glama

get_erc1155_balance

Retrieve the balance of a specific ERC1155 token ID owned by a wallet address across Ethereum-compatible networks. Input includes token contract address, token ID, and wallet address.

Instructions

Get the balance of a specific ERC1155 token ID owned by an address. ERC1155 allows multiple tokens of the same ID, so the balance can be greater than 1.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
networkNoNetwork name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', 'polygon') or chain ID. ERC1155 tokens exist across many networks. Defaults to Ethereum mainnet.
ownerAddressYesThe wallet address to check the token balance for (e.g., '0x1234...')
tokenAddressYesThe contract address of the ERC1155 token collection (e.g., '0x76BE3b62873462d2142405439777e971754E8E77')
tokenIdYesThe ID of the specific token to check the balance for (e.g., '1234')

Implementation Reference

  • MCP tool handler that takes input parameters, calls the getERC1155Balance service, formats the balance response as JSON, or returns an error message.
    async ({ contractAddress, tokenId, address, network = "ethereum" }) => { try { const balance = await services.getERC1155Balance(contractAddress as Address, address as Address, BigInt(tokenId), network); return { content: [{ type: "text", text: JSON.stringify({ network, contract: contractAddress, tokenId, owner: address, balance: balance.toString() }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error fetching ERC1155 balance: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
  • Zod input schema defining parameters for the get_erc1155_balance tool: contractAddress, tokenId, address, and optional network.
    inputSchema: { contractAddress: z.string().describe("The ERC1155 contract address"), tokenId: z.string().describe("The token ID"), address: z.string().describe("The owner address or ENS name"), network: z.string().optional().describe("Network name or chain ID. Defaults to Ethereum mainnet.") },
  • Registration of the get_erc1155_balance tool with the server, including description, input schema, annotations, and handler function.
    server.registerTool( "get_erc1155_balance", { description: "Get ERC1155 token balance for an address", inputSchema: { contractAddress: z.string().describe("The ERC1155 contract address"), tokenId: z.string().describe("The token ID"), address: z.string().describe("The owner address or ENS name"), network: z.string().optional().describe("Network name or chain ID. Defaults to Ethereum mainnet.") }, annotations: { title: "Get ERC1155 Balance", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true } }, async ({ contractAddress, tokenId, address, network = "ethereum" }) => { try { const balance = await services.getERC1155Balance(contractAddress as Address, address as Address, BigInt(tokenId), network); return { content: [{ type: "text", text: JSON.stringify({ network, contract: contractAddress, tokenId, owner: address, balance: balance.toString() }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error fetching ERC1155 balance: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
  • Helper function implementing the core logic for fetching ERC1155 token balance using readContract and ERC1155 ABI, supporting ENS resolution.
    export async function getERC1155Balance( tokenAddressOrEns: string, ownerAddressOrEns: string, tokenId: bigint, network = 'ethereum' ): Promise<bigint> { // Resolve ENS names to addresses if needed const tokenAddress = await resolveAddress(tokenAddressOrEns, network); const ownerAddress = await resolveAddress(ownerAddressOrEns, network); return readContract({ address: tokenAddress, abi: erc1155Abi, functionName: 'balanceOf', args: [ownerAddress, tokenId] }, network) as Promise<bigint>; }

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/mcpdotdirect/evm-mcp-server'

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