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
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | The wallet or contract address or ENS name to check (e.g., '0x1234...' or 'uniswap.eth') | |
| network | No | Network name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', etc.) or chain ID. Supports all EVM-compatible networks. Defaults to Ethereum mainnet. |
Implementation Reference
- src/core/tools.ts:1236-1288 (registration)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 }; } } );
- src/core/services/contracts.ts:301-317 (handler)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'; }
- src/core/tools.ts:1240-1252 (schema)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." ) },
- src/server/server.ts:18-18 (registration)High-level registration call to registerEVMTools which includes the 'is_contract' tool among others.registerEVMTools(server);