call_contract
Execute read-only smart contract methods on the Rootstock blockchain by specifying the contract address, method name, and parameters using the standardized Model Context Protocol APIs.
Instructions
Call a smart contract method (read-only)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| abi | No | Optional contract ABI | |
| contractAddress | Yes | Smart contract address | |
| methodName | Yes | Method name to call | |
| parameters | No | Method parameters |
Implementation Reference
- src/index.ts:765-784 (handler)MCP server handler for 'call_contract' tool: calls rootstockClient.callContract and returns formatted result or error.private async handleCallContract(params: CallContractParams) { try { const result = await this.rootstockClient.callContract( params.contractAddress, params.methodName, params.parameters || [], params.abi ); return { content: [ { type: 'text', text: `Contract Call Result:\n\nContract: ${params.contractAddress}\nMethod: ${params.methodName}\nResult: ${JSON.stringify(result.result, null, 2)}`, }, ], }; } catch (error) { throw new Error(`Failed to call contract: ${error}`); } }
- src/types.ts:147-152 (schema)TypeScript interface defining input parameters for call_contract: contract address, method, params, optional ABI.export interface CallContractParams { contractAddress: string; methodName: string; parameters?: any[]; abi?: any[]; }
- src/index.ts:316-343 (registration)Tool registration in MCP server's getAvailableTools(): defines name, description, and inputSchema for 'call_contract'.{ name: 'call_contract', description: 'Call a smart contract method (read-only)', inputSchema: { type: 'object', properties: { contractAddress: { type: 'string', description: 'Smart contract address', }, methodName: { type: 'string', description: 'Method name to call', }, parameters: { type: 'array', description: 'Method parameters', items: {}, }, abi: { type: 'array', description: 'Optional contract ABI', items: {}, }, }, required: ['contractAddress', 'methodName'], }, },
- src/rootstock-client.ts:333-355 (helper)Low-level implementation in RootstockClient: creates ethers.Contract and performs read-only method call using provided or generated ABI.async callContract( contractAddress: string, methodName: string, parameters: any[] = [], abi?: any[] ): Promise<ContractCallResponse> { try { // Use a basic ABI if none provided const contractAbi = abi || [ `function ${methodName}(${parameters.map((_, i) => `uint256 param${i}`).join(', ')}) view returns (uint256)`, ]; const contract = new ethers.Contract(contractAddress, contractAbi, this.getProvider()); const result = await contract[methodName](...parameters); return { result: result.toString(), }; } catch (error) { throw new Error(`Failed to call contract: ${error}`); } }