Skip to main content
Glama

contract_call

Execute read-only calls to Hedera smart contract functions to query data without submitting transactions or paying gas fees. Returns contract function results using 0.5 HBAR per call.

Instructions

Execute a read-only call to a Hedera smart contract function and return the result. Does not submit a transaction or cost gas. Costs 0.5 HBAR.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
api_keyYesYour HederaIntel API key
contract_idYesHedera contract ID (e.g. 0.0.123456) or EVM address (0x...)
function_nameYesContract function name to call (e.g. balanceOf, totalSupply, name)
function_paramsNoOptional array of parameter values to pass to the function
abi_hintNoOptional ABI hint - common values: ERC20, ERC721, HTS

Implementation Reference

  • The handler logic for 'contract_call' tool, which prepares contract information, encodes data, executes an eth_call on a mirror node, and decodes the result.
    // --- contract_call ---
    if (name === "contract_call") {
      const payment = chargeForTool("contract_call", args.api_key);
      const base = getMirrorNodeBase();
    
      // Fetch contract info
      const contractRes = await axios.get(`${base}/api/v1/contracts/${args.contract_id}`)
        .catch(() => ({ data: {} }));
      const contract = contractRes.data;
      const evmTarget = contract.evm_address || args.contract_id;
    
      const funcName = args.function_name;
      const params = args.function_params || [];
    
      // Defensively parse return_types and function_params in case they arrive as JSON strings
      const returnTypes = typeof args.return_types === "string"
        ? JSON.parse(args.return_types)
        : (args.return_types || []);
    
      // Build signature: use explicit abi_hint signature if provided (e.g. "balanceOf(address)")
      // Otherwise infer from function name and param types
      let signature;
      if (args.abi_hint && args.abi_hint.includes("(")) {
        // User passed a full signature as abi_hint e.g. "balanceOf(address)"
        signature = args.abi_hint;
      } else {
        signature = inferSignature(funcName, params);
      }
    
      const calldata = buildCalldata(signature, params);
      const selectorUsed = calldata.slice(0, 10);
    
      // Execute via mirror node eth_call
      let callResult = null;
      let callError = null;
      try {
        const callRes = await axios.post(
          `${base}/api/v1/contracts/call`,
          {
            data: calldata,
            to: evmTarget,
            gas: 400000,
            gasPrice: 0,
            estimate: false,
          }
        );
        callResult = callRes.data;
      } catch (e) {
        callError = e.response?.data?._status?.messages?.[0]?.message
          || e.response?.data?.detail
          || e.response?.data?.message
          || JSON.stringify(e.response?.data)
          || e.message;
      }
    
      // Decode the result
      let decoded = null;
      if (callResult?.result && callResult.result !== "0x") {
        if (returnTypes && returnTypes.length > 0) {
          // Precise decode using ethers ABI coder
          try {
            const raw = ethers.utils.defaultAbiCoder.decode(
              returnTypes,
              callResult.result
            );
            // Convert BigNumbers and format addresses with Hedera IDs
            const values = returnTypes.map((type, i) => {
              const val = raw[i];
              if (ethers.BigNumber.isBigNumber(val)) {
                return { type, value: val.toString() };
              }
              if (type === "address" || type.startsWith("address")) {
                const addr = val.toLowerCase();
                // Convert EVM address to Hedera ID (last 4 bytes as decimal)
                const hederaNum = parseInt(addr.slice(-8), 16);
                return { type, value: addr, hedera_id: `0.0.${hederaNum}` };
              }
              return { type, value: val.toString() };
            });
            decoded = {
              raw_hex: callResult.result,
              decoded_values: values,
              note: `Decoded using provided return_types: [${returnTypes.join(", ")}]`,
            };
          } catch (e) {
            // Fall back to heuristic decoder if ethers decode fails
            decoded = { ...decodeResult(callResult.result), ethers_decode_error: e.message };
          }
        } else {
          decoded = decodeResult(callResult.result);
        }
      }
    
      // Recent call history
      const resultsRes = await axios.get(
        `${base}/api/v1/contracts/${args.contract_id}/results?limit=10&order=desc`
      ).catch(() => ({ data: { results: [] } }));
      const results = resultsRes.data.results || [];
    
      return {
        contract_id: args.contract_id,
        evm_address: contract.evm_address || null,
        function_called: funcName,
        signature_used: signature,
        selector_used: selectorUsed,
        params_encoded: params,
        calldata_sent: calldata,
        call_result: decoded,
        call_error: callError,
        note: callError
          ? "Call failed — check signature or params. You can pass a full ABI signature as abi_hint e.g. 'balanceOf(address)'."
          : decoded
          ? "Call succeeded."
          : "Call returned empty result — function may have no return value or is write-only.",
        recent_call_history: results.slice(0, 5).map(r => ({
          timestamp: r.timestamp,
          from: r.from,
          gas_used: r.gas_used,
          status: r.status,
        })),
        payment,
        timestamp: new Date().toISOString(),
      };
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 effectively discloses key behavioral traits: it's read-only, non-transactional, gas-free, and specifies a cost ('Costs 0.5 HBAR'), which are crucial for an agent to understand operational constraints and implications.

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?

Two sentences with zero waste: the first states purpose and key behavior, the second adds cost information. It's front-loaded with essential details and appropriately sized for the tool's complexity.

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?

Given no annotations and no output schema, the description is mostly complete for a read-only contract call tool, covering purpose, behavior, and cost. However, it lacks details on error handling or response format, which could aid the agent in anticipating outcomes.

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 baseline is 3. The description doesn't add meaning beyond the schema, such as explaining parameter interactions or usage examples, but doesn't need to compensate for gaps.

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 ('execute a read-only call'), target resource ('Hedera smart contract function'), and outcome ('return the result'), distinguishing it from siblings like contract_analyze or token_monitor that imply analysis rather than direct execution.

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

Usage Guidelines4/5

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

It explicitly states when to use this tool ('read-only call... does not submit a transaction or cost gas') and distinguishes it from transactional calls, though it doesn't specify alternatives among siblings like contract_read or when not to use it for other purposes.

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/mountainmystic/hederatoolbox'

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