ODOS_GET_CHAIN_ID
Retrieve the numeric chain ID for a given blockchain name to identify the network.
Instructions
Get the chain ID for a given chain name
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| chain | Yes | The chain name to get the ID for |
Implementation Reference
- src/tools/chain-id.ts:8-23 (handler)The main handler/tool definition for ODOS_GET_CHAIN_ID. Contains the execute function that calls getChainFromName and returns the chain ID.
export const chainIdTool = { name: "ODOS_GET_CHAIN_ID", description: "Get the chain ID for a given chain name", parameters: chainIdSchema, execute: async (args: z.infer<typeof chainIdSchema>) => { try { console.log("[ODOS_GET_CHAIN_ID] Called..."); const chain = getChainFromName(args.chain); return chain.id.toString(); } catch (error) { console.error(error); throw error; } }, }; - src/tools/chain-id.ts:4-6 (schema)The Zod schema for input validation. Expects a single 'chain' string parameter describing the chain name.
const chainIdSchema = z.object({ chain: z.string().describe("The chain name to get the ID for"), }); - src/index.ts:18-18 (registration)The tool is registered with the FastMCP server via server.addTool(chainIdTool).
server.addTool(chainIdTool); - src/utils/get-chain.ts:4-63 (helper)Helper function getChainFromName that maps a chain name string to a viem Chain object using the viem/chains library.
export function getChainFromName(name: string): Chain { switch (name.toLowerCase()) { case "fraxtal": return chains.fraxtal; case "mainnet": return chains.mainnet; case "optimism": return chains.optimism; case "polygon": return chains.polygon; case "bsc": return chains.bsc; case "base": return chains.base; case "arbitrum": return chains.arbitrum; case "avalanche": return chains.avalanche; case "linea": return chains.linea; case "scroll": return chains.scroll; case "mode": return chains.mode; case "sonic": return chains.sonic; case "fantom": return chains.fantom; case "zksync era": return chains.zksync; case "mantle": return chains.mantle; case "sepolia": return chains.sepolia; case "goerli": return chains.goerli; case "polygon mumbai": return chains.polygonMumbai; case "arbitrum goerli": return chains.arbitrumGoerli; case "bsc testnet": return chains.bscTestnet; case "eth": return chains.mainnet; case "matic": return chains.polygon; case "bnb": return chains.bsc; case "avax": return chains.avalanche; case "arb": return chains.arbitrum; case "ftm": return chains.fantom; case "era": return chains.zksync; default: throw new Error(`Chain ${name} not supported`); } }