Skip to main content
Glama

call_contract

Execute read-only smart contract calls to retrieve on-chain data like token balances and prices without gas costs or state changes.

Instructions

Execute a read-only call against a smart contract (eth_call). Returns the raw hex result. Does not cost gas or modify state. Useful for reading on-chain data like token balances, prices, positions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
chain_idYesChain ID
toYesContract address
dataYesABI-encoded calldata (0x-prefixed hex)

Implementation Reference

  • The handler function for call_contract tool. It validates that the chain is not Solana, makes an API call to /eth-call endpoint with chain_id, to (contract address), and data (ABI-encoded calldata), and returns the JSON response. This is the core logic that executes read-only eth_call operations against smart contracts.
    async ({ chain_id, to, data }) => {
      if (isSolanaChain(chain_id)) {
        throw new Error('call_contract is not supported on Solana. Use Solana-specific RPC methods instead.');
      }
      const result = await api('/eth-call', 'POST', { chain_id, to, data });
      return jsonResponse(result);
    },
  • Zod schema definition for call_contract tool inputs. Defines three required parameters: chain_id (integer), to (contract address with 0x-prefixed 40-char hex validation), and data (ABI-encoded calldata string).
    {
      chain_id: z.number().int().describe('Chain ID'),
      to: z.string().regex(/^0x[a-fA-F0-9]{40}$/).describe('Contract address'),
      data: z.string().describe('ABI-encoded calldata (0x-prefixed hex)'),
    },
  • src/index.ts:656-673 (registration)
    Registration of the call_contract tool using server.tool(). Includes tool name 'call_contract', description explaining it's a read-only eth_call for smart contracts, the zod input schema, and the async handler function.
    server.tool(
      'call_contract',
      'Execute a read-only call against a smart contract (eth_call). ' +
        'Returns the raw hex result. Does not cost gas or modify state. ' +
        'Useful for reading on-chain data like token balances, prices, positions.',
      {
        chain_id: z.number().int().describe('Chain ID'),
        to: z.string().regex(/^0x[a-fA-F0-9]{40}$/).describe('Contract address'),
        data: z.string().describe('ABI-encoded calldata (0x-prefixed hex)'),
      },
      async ({ chain_id, to, data }) => {
        if (isSolanaChain(chain_id)) {
          throw new Error('call_contract is not supported on Solana. Use Solana-specific RPC methods instead.');
        }
        const result = await api('/eth-call', 'POST', { chain_id, to, data });
        return jsonResponse(result);
      },
    );

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/hifriendbot/agentwallet-mcp'

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