get_contract_info
Retrieve contract metadata on Base mainnet including bytecode size, ETH balance, transaction count, and token details to analyze security risks.
Instructions
Get basic contract metadata on Base mainnet: is it a contract, bytecode size, ETH balance, transaction count. For tokens, also returns name/symbol/supply.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Contract or EOA address on Base mainnet |
Implementation Reference
- src/index.ts:870-897 (handler)The tool `get_contract_info` handler implementation. It uses `getBasicContractInfo` and `getTokenMetadata` to fetch and format contract data.
// Tool 6: get_contract_info server.tool( "get_contract_info", "Get basic contract metadata on Base mainnet: is it a contract, bytecode size, ETH balance, transaction count. For tokens, also returns name/symbol/supply.", { address: z.string().describe("Contract or EOA address on Base mainnet"), }, async ({ address }) => { try { const info = await getBasicContractInfo(address); let tokenInfo: Record<string, unknown> | null = null; if (info.isContract) { tokenInfo = await getTokenMetadata(address); if (tokenInfo) { tokenInfo = serializeBigInts(tokenInfo) as Record<string, unknown>; } } return ok({ ...info, tokenMetadata: tokenInfo, }); } catch (err) { return fail(`get_contract_info failed: ${err instanceof Error ? err.message : String(err)}`); } } ); - src/index.ts:260-278 (helper)Helper function used by `get_contract_info` to retrieve basic information about a contract/address.
async function getBasicContractInfo(address: string): Promise<Record<string, unknown>> { const [code, balance, txCount] = await Promise.all([ provider.getCode(address), provider.getBalance(address), provider.getTransactionCount(address), ]); const isContract = code !== "0x" && code.length > 2; const bytecodeSize = isContract ? (code.length - 2) / 2 : 0; return { address, isContract, bytecodeSize, balanceETH: ethers.formatEther(balance), balanceWei: balance.toString(), transactionCount: txCount, }; } - src/index.ts:299-319 (helper)Helper function used by `get_contract_info` to fetch ERC-20 metadata if applicable.
async function getTokenMetadata(address: string): Promise<Record<string, unknown> | null> { const contract = new ethers.Contract(address, ERC20_ABI, provider); const [name, symbol, decimals, totalSupply] = await Promise.all([ safeCall(() => contract.name()), safeCall(() => contract.symbol()), safeCall(() => contract.decimals()), safeCall(() => contract.totalSupply()), ]); if (!name && !symbol) return null; return { name: name ?? "Unknown", symbol: symbol ?? "???", decimals: decimals !== null ? Number(decimals) : 18, totalSupply: totalSupply !== null ? totalSupply.toString() : "0", totalSupplyFormatted: totalSupply !== null && decimals !== null ? ethers.formatUnits(totalSupply, Number(decimals)) : "unknown", }; }