Skip to main content
Glama

rpc_call_contract

Execute read-only smart contract functions to query blockchain data without transaction fees. Decodes return values using contract ABI for viewing balances, checking conditions, and reading contract state.

Instructions

Call read-only smart contract function via eth_call (FREE - no gas cost).

EXECUTES: View/pure function on deployed contract DECODES: Return values using provided ABI FREE: No transaction fee, no state changes

USE FOR: Reading contract state, querying balances, checking conditions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractAddressYesContract address (0x...)
abiYesContract ABI
functionNameYesFunction to call
argsNoFunction arguments

Implementation Reference

  • The main handler function that implements the rpc_call_contract tool. It validates the contract address, calls jsonRpcService.callContract to perform the read-only eth_call, and returns formatted success/error results with metadata.
    export async function rpcCallContract(args: {
      contractAddress: string;
      abi: any[];
      functionName: string;
      args?: any[];
      blockNumber?: string;
      network?: 'mainnet' | 'testnet' | 'previewnet' | 'local';
    }): Promise<ToolResult> {
      try {
        logger.info('Calling contract function (read-only)', {
          contractAddress: args.contractAddress,
          functionName: args.functionName,
          network: args.network,
        });
    
        // Validate address
        if (!args.contractAddress.startsWith('0x') || args.contractAddress.length !== 42) {
          throw new Error('Invalid contract address format');
        }
    
        const result = await jsonRpcService.callContract({
          contractAddress: args.contractAddress,
          abi: args.abi,
          functionName: args.functionName,
          args: args.args,
          blockNumber: args.blockNumber,
          network: args.network,
        });
    
        return {
          success: true,
          data: {
            functionName: args.functionName,
            result,
          },
          metadata: {
            executedVia: 'json_rpc_relay',
            command: 'contract call (read-only)',
          },
        };
      } catch (error) {
        logger.error('Contract call failed', { error });
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Unknown error occurred',
          metadata: {
            executedVia: 'json_rpc_relay',
            command: 'contract call (read-only)',
          },
        };
      }
    }
  • The input schema and tool definition for rpc_call_contract used in the optimizedToolDefinitions array for MCP tool listing.
      {
        name: 'rpc_call_contract',
        description: `Call read-only smart contract function via eth_call (FREE - no gas cost).
    
    EXECUTES: View/pure function on deployed contract
    DECODES: Return values using provided ABI
    FREE: No transaction fee, no state changes
    
    USE FOR: Reading contract state, querying balances, checking conditions.`,
        inputSchema: {
          type: 'object' as const,
          properties: {
            contractAddress: { type: 'string', description: 'Contract address (0x...)' },
            abi: { type: 'array', items: {}, description: 'Contract ABI' },
            functionName: { type: 'string', description: 'Function to call' },
            args: { type: 'array', items: {}, description: 'Function arguments' },
          },
          required: ['contractAddress', 'abi', 'functionName'],
        },
      },
  • src/index.ts:608-610 (registration)
    Tool execution registration in the main switch dispatcher. Maps the tool name to the rpcCallContract handler invocation.
    case 'rpc_call_contract':
      result = await rpcCallContract(args as any);
      break;
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and does well: it discloses key behavioral traits including 'read-only', 'no state changes', 'FREE - no gas cost', and 'DECODES: Return values using provided ABI'. It doesn't mention rate limits or specific error conditions, but covers the essential safety and cost profile.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Highly structured with bullet-like sections (EXECUTES, DECODES, FREE, USE FOR), front-loaded with the core purpose, and every sentence earns its place. No wasted words while maintaining clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a read-only tool with no annotations and no output schema, the description does well: covers purpose, usage, behavioral traits (safety, cost, decoding). It doesn't describe return format or error handling, but given the context (simple query tool with good schema coverage), it's mostly complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all 4 parameters. The description mentions 'provided ABI' and 'function to call' but doesn't add meaningful semantic context beyond what the schema provides (like format details or examples). Baseline 3 is appropriate when schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action: 'Call read-only smart contract function via eth_call' with the resource being smart contracts. It distinguishes from siblings like rpc_execute_contract (which likely writes) by emphasizing 'read-only' and 'FREE - no gas cost'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Explicitly states when to use: 'USE FOR: Reading contract state, querying balances, checking conditions.' This provides clear context and distinguishes from write operations. The 'FREE - no gas cost' also implies when not to use (for state-changing operations).

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/justmert/hashpilot'

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