Skip to main content
Glama
lienhage

Blockchain MCP Server

by lienhage

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
NameRequiredDescriptionDefault
blockTagNoBlock tag (latest, earliest, pending, or block number)latest
chainYesChain identifier. Available: ethereum, polygon, bsc, arbitrum, optimism, avalanche, fantom, sepolia
dataYesABI-encoded function call data
toYesContract address to call

Implementation Reference

  • 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
              };
            }
          }
  • 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")
    }
  • 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
              };
            }
          }
        );
Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/lienhage/blockchain-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server