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
| Name | Required | Description | Default |
|---|---|---|---|
| contractAddress | Yes | Contract address (0x...) | |
| abi | Yes | Contract ABI | |
| functionName | Yes | Function to call | |
| args | No | Function arguments |
Implementation Reference
- src/tools/rpc.ts:128-179 (handler)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)', }, }; } }
- src/index.ts:250-269 (schema)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;