Skip to main content
Glama

rpc_execute_contract

Execute state-changing smart contract functions on Hedera blockchain. Handles transaction signing, gas estimation, and receipt polling for token transfers and contract interactions.

Instructions

Execute state-changing contract function via eth_sendRawTransaction.

EXECUTES: Transaction that modifies contract state HANDLES: Function encoding, signing, gas estimation, receipt polling COSTS: Gas fees for execution RETURNS: Transaction hash, receipt, decoded logs AUTO-KEY: privateKey is OPTIONAL - automatically uses MCP operator account if not provided

USE FOR: Token transfers, contract interactions, state modifications.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractAddressYesContract address (0x...)
abiYesContract ABI
functionNameYesFunction to execute
argsNoFunction arguments
privateKeyNoSender private key (optional - uses MCP operator)
valueNoHBAR value to send (in wei)

Implementation Reference

  • Core implementation of rpc_execute_contract tool: executes state-changing smart contract functions via Hedera JSON-RPC relay, handles validation, service call, and formatted response.
    export async function rpcExecuteContract(args: {
      contractAddress: string;
      abi: any[];
      functionName: string;
      args?: any[];
      value?: string;
      gasLimit?: number;
      privateKey?: string;
      fromAlias?: string;
      network?: 'mainnet' | 'testnet' | 'previewnet' | 'local';
    }): Promise<ToolResult> {
      try {
        logger.info('Executing contract function (state-changing)', {
          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.executeContract({
          contractAddress: args.contractAddress,
          abi: args.abi,
          functionName: args.functionName,
          args: args.args,
          value: args.value,
          gasLimit: args.gasLimit,
          privateKey: args.privateKey,
          fromAlias: args.fromAlias,
          network: args.network,
        });
    
        return {
          success: true,
          data: {
            functionName: args.functionName,
            transactionHash: result.transactionHash,
            blockNumber: result.receipt.blockNumber,
            gasUsed: result.receipt.gasUsed,
            status: result.receipt.status === '0x1' ? 'success' : 'failed',
            logs: result.receipt.logs,
          },
          metadata: {
            executedVia: 'json_rpc_relay',
            command: 'contract execute',
          },
        };
      } catch (error) {
        logger.error('Contract execution failed', { error });
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Unknown error occurred',
          metadata: {
            executedVia: 'json_rpc_relay',
            command: 'contract execute',
          },
        };
      }
    }
  • Detailed input schema definition for rpc_execute_contract tool within the rpcTools export array.
    {
      name: 'rpc_execute_contract',
      description:
        'Execute state-changing contract function via eth_sendRawTransaction. Handles function encoding, transaction signing, gas estimation, submission, and receipt polling. Requires private key. Returns transaction hash and logs.',
      inputSchema: {
        type: 'object' as const,
        properties: {
          contractAddress: {
            type: 'string',
            description: 'Contract address (0x... format)',
          },
          abi: {
            type: 'array',
            description: 'Contract ABI',
            items: {},
          },
          functionName: {
            type: 'string',
            description: 'Function name to execute',
          },
          args: {
            type: 'array',
            description: 'Optional: Function arguments',
            items: {},
          },
          value: {
            type: 'string',
            description: 'Optional: HBAR value to send in wei (18 decimals)',
          },
          gasLimit: {
            type: 'number',
            description: 'Optional: Gas limit override (auto-estimated if not provided)',
          },
          privateKey: {
            type: 'string',
            description: 'Optional: Private key in DER format (or use fromAlias)',
          },
          fromAlias: {
            type: 'string',
            description: 'Optional: Address book alias to use for execution',
          },
          network: {
            type: 'string',
            enum: ['mainnet', 'testnet', 'previewnet', 'local'],
            description: 'Target network (default: current network)',
          },
        },
        required: ['contractAddress', 'abi', 'functionName'],
      },
    },
  • src/index.ts:292-314 (registration)
    Tool registration in the MCP server's optimizedToolDefinitions array, including simplified input schema.
        name: 'rpc_execute_contract',
        description: `Execute state-changing contract function via eth_sendRawTransaction.
    
    EXECUTES: Transaction that modifies contract state
    HANDLES: Function encoding, signing, gas estimation, receipt polling
    COSTS: Gas fees for execution
    RETURNS: Transaction hash, receipt, decoded logs
    AUTO-KEY: privateKey is OPTIONAL - automatically uses MCP operator account if not provided
    
    USE FOR: Token transfers, contract interactions, state modifications.`,
        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 execute' },
            args: { type: 'array', items: {}, description: 'Function arguments' },
            privateKey: { type: 'string', description: 'Sender private key (optional - uses MCP operator)' },
            value: { type: 'string', description: 'HBAR value to send (in wei)' },
          },
          required: ['contractAddress', 'abi', 'functionName'],
        },
      },
  • src/index.ts:614-616 (registration)
    Dispatch registration in the MCP server's CallToolRequestSchema handler switch statement, routing calls to the rpcExecuteContract handler.
    case 'rpc_execute_contract':
      result = await rpcExecuteContract(args as any);
      break;
Behavior5/5

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

With no annotations provided, the description carries full burden and excels by disclosing critical behavioral traits: it's state-changing (modifies contract state), handles function encoding/signing/gas estimation/receipt polling, incurs gas costs, returns transaction hash/receipt/decoded logs, and has automatic key management. This covers mutation, costs, return format, and authentication behavior.

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?

The description is efficiently structured with clear sections (EXECUTES, HANDLES, COSTS, RETURNS, AUTO-KEY, USE FOR), each containing one sentence or phrase. Every element adds value with zero wasted words, making it easy to scan and understand.

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

Completeness5/5

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

For a complex state-changing tool with no annotations and no output schema, the description provides comprehensive context: purpose, behavioral traits (mutation, costs, return format), usage guidelines, and key parameter clarification. It fully compensates for the lack of structured metadata.

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 6 parameters. The description adds minimal parameter-specific semantics beyond the schema, only clarifying that privateKey is optional and auto-uses MCP operator. This meets the baseline of 3 when schema coverage is high.

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 explicitly states the tool's purpose as 'Execute state-changing contract function via eth_sendRawTransaction' and specifies it's for 'Token transfers, contract interactions, state modifications.' This clearly distinguishes it from sibling tools like rpc_call (likely read-only) and rpc_deploy_contract (for deployment).

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?

The description provides explicit guidance with 'USE FOR: Token transfers, contract interactions, state modifications' and distinguishes it from alternatives by noting it handles 'EXECUTES: Transaction that modifies contract state' (versus read-only calls). The AUTO-KEY section also clarifies when to provide privateKey versus using the MCP operator.

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