Skip to main content
Glama

is_contract

Verify whether an Ethereum address is a smart contract or an externally owned account (EOA) across EVM-compatible networks to ensure accurate interactions with blockchain addresses.

Instructions

Check if an address is a smart contract or an externally owned account (EOA)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYesThe wallet or contract address or ENS name to check (e.g., '0x1234...' or 'uniswap.eth')
networkNoNetwork name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', etc.) or chain ID. Supports all EVM-compatible networks. Defaults to Ethereum mainnet.

Implementation Reference

  • Registration of the 'is_contract' MCP tool, including input schema (address, optional network), description, and inline async handler that delegates to services.isContract and formats the response as JSON.
    // Check if address is a contract server.tool( 'is_contract', 'Check if an address is a smart contract or an externally owned account (EOA)', { address: z .string() .describe( "The wallet or contract address or ENS name to check (e.g., '0x1234...' or 'uniswap.eth')" ), network: z .string() .optional() .describe( "Network name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', etc.) or chain ID. Supports all EVM-compatible networks. Defaults to Ethereum mainnet." ) }, async ({ address, network = 'ethereum' }) => { try { const isContract = await services.isContract(address, network); return { content: [ { type: 'text', text: JSON.stringify( { address, network, isContract, type: isContract ? 'Contract' : 'Externally Owned Account (EOA)' }, null, 2 ) } ] }; } catch (error) { return { content: [ { type: 'text', text: `Error checking if address is a contract: ${error instanceof Error ? error.message : String(error)}` } ], isError: true }; } } );
  • Core implementation of the isContract function: resolves ENS to address if needed, fetches bytecode using viem's public client, returns true if bytecode exists and is non-empty (indicating a contract). Called by the tool handler.
    /** * Check if an address is a contract * @param addressOrEns Address or ENS name to check * @param network Network name or chain ID * @returns True if the address is a contract, false if it's an EOA */ export async function isContract( addressOrEns: string, network = 'ethereum' ): Promise<boolean> { // Resolve ENS name to address if needed const address = await resolveAddress(addressOrEns, network); const client = getPublicClient(network); const code = await client.getBytecode({ address }); return code !== undefined && code !== '0x'; }
  • Input schema for the 'is_contract' tool using Zod: requires 'address' string (supports ENS), optional 'network' string.
    { address: z .string() .describe( "The wallet or contract address or ENS name to check (e.g., '0x1234...' or 'uniswap.eth')" ), network: z .string() .optional() .describe( "Network name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', etc.) or chain ID. Supports all EVM-compatible networks. Defaults to Ethereum mainnet." ) },
  • High-level registration call to registerEVMTools which includes the 'is_contract' tool among others.
    registerEVMTools(server);

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

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