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;

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