Skip to main content
Glama

contract_read

Read Hedera smart contract state without executing transactions. Get contract info, bytecode size, activity logs, and storage details for 0.1 HBAR per query.

Instructions

Read state from a Hedera smart contract - get contract info, bytecode size, recent activity, and storage details without executing a transaction. Costs 0.1 HBAR.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
api_keyYesYour HederaIntel API key
contract_idYesHedera contract ID (e.g. 0.0.123456) or EVM address (0x...)

Implementation Reference

  • The handler function for `contract_read` which interacts with the Hedera Mirror Node API to fetch contract data, recent call results, and state information.
    if (name === "contract_read") {
      const payment = chargeForTool("contract_read", args.api_key);
      const base = getMirrorNodeBase();
    
      // Fetch contract info
      const contractRes = await axios.get(`${base}/api/v1/contracts/${args.contract_id}`);
      const contract = contractRes.data;
    
      // Fetch recent contract results (calls)
      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 || [];
    
      // Fetch contract state entries count
      const stateRes = await axios.get(
        `${base}/api/v1/contracts/${args.contract_id}/state?limit=25`
      ).catch(() => ({ data: { state: [] } }));
      const stateEntries = stateRes.data.state || [];
    
      // Calculate contract age
      const createdAt = contract.created_timestamp
        ? new Date(parseFloat(contract.created_timestamp) * 1000)
        : null;
      const ageDays = createdAt
        ? Math.floor((Date.now() - createdAt.getTime()) / (1000 * 60 * 60 * 24))
        : null;
    
      // Recent callers
      const callers = [...new Set(results.map(r => r.from).filter(Boolean))];
    
      // Gas usage stats
      const gasUsed = results.map(r => parseInt(r.gas_used || 0));
      const avgGas = gasUsed.length > 0
        ? Math.round(gasUsed.reduce((a, b) => a + b, 0) / gasUsed.length)
        : null;
      const maxGas = gasUsed.length > 0 ? Math.max(...gasUsed) : null;
    
      return {
        contract_id: args.contract_id,
        evm_address: contract.evm_address || null,
        admin_key: contract.admin_key ? true : false,
        auto_renew_account: contract.auto_renew_account_id || null,
        auto_renew_period: contract.auto_renew_period || null,
        created_at: createdAt ? createdAt.toISOString() : null,
        age_days: ageDays,
        expiration_timestamp: contract.expiration_timestamp || null,
        memo: contract.memo || null,
        obtainer_account: contract.obtainer_account_id || null,
        proxy_account: contract.proxy_account_id || null,
        bytecode_size_bytes: contract.bytecode ? Math.round(contract.bytecode.length / 2) : null,
        file_id: contract.file_id || null,
        max_automatic_token_associations: contract.max_automatic_token_associations || 0,
        hbar_balance: contract.balance?.balance
          ? (contract.balance.balance / 100000000).toFixed(4) + " HBAR"
          : "0.0000 HBAR",
        recent_call_count: results.length,
        recent_callers: callers.slice(0, 5),
        gas_stats: {
          avg_gas_used: avgGas,
          max_gas_used: maxGas,
        },
        state_entry_count: stateEntries.length,
        deleted: contract.deleted || false,
        payment,
        timestamp: new Date().toISOString(),
      };
    }
  • The input schema for the `contract_read` tool defining the expected `contract_id` and `api_key`.
    {
      name: "contract_read",
      description: "Read state from a Hedera smart contract - get contract info, bytecode size, recent activity, and storage details without executing a transaction. Costs 0.2 HBAR.",
      inputSchema: {
        type: "object",
        properties: {
          contract_id: { type: "string", description: "Hedera contract ID (e.g. 0.0.123456) or EVM address (0x...)" },
          api_key: { type: "string", description: "Your HederaIntel API key" },
        },
        required: ["contract_id", "api_key"],
      },
    },
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively communicates that this is a read-only operation ('Read state... without executing a transaction'), discloses the cost ('Costs 0.1 HBAR'), and implies it's a query rather than a mutation. However, it doesn't mention rate limits, authentication requirements beyond the api_key parameter, or error conditions.

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 extremely concise (two sentences) and front-loaded with the core purpose in the first sentence. Every word earns its place: the first sentence defines the action and scope, while the second adds critical behavioral information (cost). There's no wasted text or redundancy.

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 the tool's moderate complexity (read operation with cost disclosure), no annotations, and no output schema, the description is reasonably complete. It covers purpose, behavioral traits (read-only, cost), and distinguishes from alternatives. However, without an output schema, it doesn't describe return values or error formats, leaving some gaps in full contextual understanding.

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 both parameters (api_key and contract_id) with descriptions. The description doesn't add any additional meaning about parameters beyond what the schema provides, such as format examples for contract_id or usage context for api_key. The baseline of 3 is appropriate when the schema does the heavy lifting.

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 ('Read state from a Hedera smart contract') and lists the types of information retrieved ('contract info, bytecode size, recent activity, and storage details'). It distinguishes from potential siblings by explicitly stating 'without executing a transaction', which differentiates it from tools like contract_call that likely execute transactions.

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?

The description provides clear context for when to use this tool ('get contract info, bytecode size, recent activity, and storage details without executing a transaction'), which implicitly suggests it's for read-only queries rather than state-changing operations. However, it doesn't explicitly mention when NOT to use it or name specific alternative tools among the siblings (e.g., contract_analyze, contract_call).

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