static-call
Perform read-only smart contract calls on EVM-compatible chains to retrieve data without altering the blockchain state. Supports Ethereum, Polygon, BSC, and more.
Instructions
Make a static call to a smart contract on any EVM-compatible chain (read-only)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| blockTag | No | Block tag (latest, earliest, pending, or block number) | latest |
| chain | Yes | Chain identifier. Available: ethereum, polygon, bsc, arbitrum, optimism, avalanche, fantom, sepolia | |
| data | Yes | ABI-encoded function call data | |
| to | Yes | Contract address to call |
Implementation Reference
- src/rpc-service/index.ts:95-158 (handler)Handler function that performs the static call to the contract using the ethers JsonRpcProvider.async ({ chain, to, data, blockTag = "latest" }) => { try { const chainConfig = DEFAULT_CHAINS[chain.toLowerCase()]; if (!chainConfig) { return { content: [{ type: "text", text: `Error: Unsupported chain "${chain}". Available chains: ${Object.keys(DEFAULT_CHAINS).join(', ')}` }], isError: true }; } if (!ethers.isAddress(to)) { return { content: [{ type: "text", text: `Error: Invalid contract address: ${to}` }], isError: true }; } const provider = this.providers.get(chain.toLowerCase()); if (!provider) { return { content: [{ type: "text", text: `Error: Provider not initialized for chain: ${chain}` }], isError: true }; } const result = await provider.call({ to: to, data: data }); return { content: [{ type: "text", text: `Static call result: ๐ Chain: ${chainConfig.name} (${chainConfig.chainId}) ๐ Contract: ${to} ๐ Call Data: ${data} ๐ท๏ธ Block: ${blockTag} ๐ค Result: ${result} ${chainConfig.explorerUrl ? `๐ Explorer: ${chainConfig.explorerUrl}/address/${to}` : ''}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error making static call: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
- src/rpc-service/index.ts:89-93 (schema)Input schema using Zod for validating chain, contract address, call data, and optional block tag.chain: z.string().describe(`Chain identifier. Available: ${Object.keys(DEFAULT_CHAINS).join(', ')}`), to: z.string().describe("Contract address to call"), data: z.string().describe("ABI-encoded function call data"), blockTag: z.string().optional().describe("Block tag (latest, earliest, pending, or block number)").default("latest") }
- src/rpc-service/index.ts:83-159 (registration)Registers the 'static-call' tool with the MCP server, providing schema and handler.server.registerTool( "static-call", { title: "Static Call", description: "Make a static call to a smart contract on any EVM-compatible chain (read-only)", inputSchema: { chain: z.string().describe(`Chain identifier. Available: ${Object.keys(DEFAULT_CHAINS).join(', ')}`), to: z.string().describe("Contract address to call"), data: z.string().describe("ABI-encoded function call data"), blockTag: z.string().optional().describe("Block tag (latest, earliest, pending, or block number)").default("latest") } }, async ({ chain, to, data, blockTag = "latest" }) => { try { const chainConfig = DEFAULT_CHAINS[chain.toLowerCase()]; if (!chainConfig) { return { content: [{ type: "text", text: `Error: Unsupported chain "${chain}". Available chains: ${Object.keys(DEFAULT_CHAINS).join(', ')}` }], isError: true }; } if (!ethers.isAddress(to)) { return { content: [{ type: "text", text: `Error: Invalid contract address: ${to}` }], isError: true }; } const provider = this.providers.get(chain.toLowerCase()); if (!provider) { return { content: [{ type: "text", text: `Error: Provider not initialized for chain: ${chain}` }], isError: true }; } const result = await provider.call({ to: to, data: data }); return { content: [{ type: "text", text: `Static call result: ๐ Chain: ${chainConfig.name} (${chainConfig.chainId}) ๐ Contract: ${to} ๐ Call Data: ${data} ๐ท๏ธ Block: ${blockTag} ๐ค Result: ${result} ${chainConfig.explorerUrl ? `๐ Explorer: ${chainConfig.explorerUrl}/address/${to}` : ''}` }] }; } catch (error) { return { content: [{ type: "text", text: `Error making static call: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );