is_contract
Verify whether a given address is a smart contract or an externally owned account (EOA) on supported networks, including BSC, Ethereum, and more.
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 to check | |
| network | No | Network name (e.g. 'bsc', 'opbnb', 'ethereum', 'base', etc.) or chain ID. Supports others main popular networks. Defaults to BSC mainnet. | bsc |
Implementation Reference
- src/evm/modules/contracts/tools.ts:11-35 (registration)MCP tool registration for 'is_contract', including input schema (address, network), handler logic using services.isContract, and response formatting.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 to check"), network: defaultNetworkParam }, async ({ address, network = "bsc" }) => { try { const isContract = await services.isContract( address as Address, network ) return mcpToolRes.success({ address, network, isContract, type: isContract ? "Contract" : "EOA" }) } catch (error) { return mcpToolRes.error(error, "checking contract status") } } )
- src/evm/services/contracts.ts:46-62 (helper)Core helper function isContract that resolves ENS if needed, fetches bytecode using viem public client, and determines if it's a contract (non-empty code)./** * 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.getCode({ address }) return code !== undefined && code !== "0x" }
- src/evm/modules/contracts/index.ts:8-8 (registration)Module-level registration call to registerContractTools, which includes the 'is_contract' tool.registerContractTools(server)
- src/evm/index.ts:13-13 (registration)EVM module registration that includes contracts tools like 'is_contract'.registerContracts(server)