get_erc1155_balance
Retrieve ERC1155 token balance for a specific address and token ID on EVM-compatible blockchains to verify ownership and track multi-token assets.
Instructions
Get ERC1155 token balance for an address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| contractAddress | Yes | The ERC1155 contract address | |
| tokenId | Yes | The token ID | |
| address | Yes | The owner address or ENS name | |
| network | No | Network name or chain ID. Defaults to Ethereum mainnet. |
Implementation Reference
- src/core/tools.ts:1672-1736 (handler)MCP server.tool registration and handler for 'get_erc1155_balance', including input schema validation with Zod and the execution logic that delegates to services.getERC1155Balance.'get_erc1155_balance', '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.', { tokenAddress: z .string() .describe( "The contract address of the ERC1155 token collection (e.g., '0x76BE3b62873462d2142405439777e971754E8E77')" ), tokenId: z .string() .describe( "The ID of the specific token to check the balance for (e.g., '1234')" ), ownerAddress: z .string() .describe( "The wallet address to check the token balance for (e.g., '0x1234...')" ), network: z .string() .optional() .describe( "Network name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', 'polygon') or chain ID. ERC1155 tokens exist across many networks. Defaults to Ethereum mainnet." ) }, async ({ tokenAddress, tokenId, ownerAddress, network = 'ethereum' }) => { try { const balance = await services.getERC1155Balance( tokenAddress as Address, ownerAddress as Address, BigInt(tokenId), network ); return { content: [ { type: 'text', text: JSON.stringify( { contract: tokenAddress, tokenId, owner: ownerAddress, network, balance: balance.toString() }, null, 2 ) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error fetching ERC1155 token balance: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );
- src/core/services/balance.ts:203-219 (helper)Core helper function getERC1155Balance that resolves addresses (including ENS), reads the ERC1155 contract's balanceOf function, and returns the raw balance as bigint.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>; }
- src/server/server.ts:17-19 (registration)Registration of EVMTools (which includes get_erc1155_balance) on the MCP server instance.registerEVMResources(server); registerEVMTools(server); registerEVMPrompts(server);