Skip to main content
Glama

hardhat_contract

Deploy, verify, and interact with Hardhat smart contracts on Hedera networks using automated MCP operator credentials for blockchain operations.

Instructions

Manage Hardhat contract deployment and interaction.

OPERATIONS:

  • deploy: Execute deployment script on target network

  • deploy_ignition: Deploy using Hardhat Ignition (declarative)

  • verify: Get contract verification metadata for HashScan

  • call: Call read-only contract function (FREE)

  • execute: Execute state-changing contract transaction

AUTO-RESOLUTION: Deployment automatically uses MCP operator account credentials. No need to set TESTNET_PRIVATE_KEY manually.

USE FOR: Contract deployment, verification, and interaction.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesContract operation to perform
directoryNoAbsolute path to Hardhat project directory
scriptNoDeployment script path (for deploy)
moduleNoIgnition module path (for deploy_ignition)
networkNoTarget network
addressNoContract address (for verify)
constructorArgsNoConstructor arguments (for verify)
contractAddressNoContract address (for call/execute)
abiNoContract ABI (for call/execute)
methodNoMethod name (for call/execute)
methodArgsNoMethod arguments (for call/execute)
privateKeyNoPrivate key (for execute) - optional, auto-uses MCP operator
valueNoHBAR value in wei (for execute)

Implementation Reference

  • Main handler function for 'hardhat_contract' tool. Dispatches to specific Hardhat operations (deploy, verify, call, execute) by calling imported hardhatTools functions.
    export async function hardhatContractManage(args: {
      operation: 'deploy' | 'deploy_ignition' | 'verify' | 'call' | 'execute';
      // Common
      directory?: string;
      // Deploy-specific
      script?: string;
      network?: string;
      // Deploy Ignition-specific
      module?: string;
      // Verify-specific
      address?: string;
      constructorArgs?: any[];
      // Call/Execute-specific
      contractAddress?: string;
      abi?: any[];
      method?: string;
      methodArgs?: any[];
      privateKey?: string;
      value?: string;
    }): Promise<ToolResult> {
      try {
        logger.info('Hardhat contract operation', { operation: args.operation });
    
        switch (args.operation) {
          case 'deploy':
            return await hardhatTools.hardhatDeploy({
              script: args.script!,
              network: args.network,
              directory: args.directory,
            });
    
          case 'deploy_ignition':
            return await hardhatTools.hardhatDeployIgnition({
              module: args.module!,
              network: args.network,
              directory: args.directory,
            });
    
          case 'verify':
            return await hardhatTools.hardhatVerify({
              address: args.address!,
              constructorArgs: args.constructorArgs,
              directory: args.directory,
            });
    
          case 'call':
            return await hardhatTools.hardhatCallContract({
              address: args.contractAddress!,
              abi: args.abi!,
              method: args.method!,
              args: args.methodArgs,
              directory: args.directory,
            });
    
          case 'execute':
            return await hardhatTools.hardhatExecuteContract({
              address: args.contractAddress!,
              abi: args.abi!,
              method: args.method!,
              args: args.methodArgs,
              value: args.value,
              directory: args.directory,
            });
    
          default:
            throw new Error(`Unknown operation: ${args.operation}`);
        }
      } catch (error) {
        logger.error('Hardhat contract operation failed', { operation: args.operation, error });
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Unknown error',
        };
      }
    }
  • Input schema and description definition for the 'hardhat_contract' tool, including supported operations and parameters.
      {
        name: 'hardhat_contract',
        description: `Manage Hardhat contract deployment and interaction.
    
    OPERATIONS:
    - deploy: Execute deployment script on target network
    - deploy_ignition: Deploy using Hardhat Ignition (declarative)
    - verify: Get contract verification metadata for HashScan
    - call: Call read-only contract function (FREE)
    - execute: Execute state-changing contract transaction
    
    AUTO-RESOLUTION: Deployment automatically uses MCP operator account credentials. No need to set TESTNET_PRIVATE_KEY manually.
    
    USE FOR: Contract deployment, verification, and interaction.`,
        inputSchema: {
          type: 'object' as const,
          properties: {
            operation: {
              type: 'string',
              enum: ['deploy', 'deploy_ignition', 'verify', 'call', 'execute'],
              description: 'Contract operation to perform',
            },
            directory: { type: 'string', description: 'Absolute path to Hardhat project directory' },
            script: { type: 'string', description: 'Deployment script path (for deploy)' },
            module: { type: 'string', description: 'Ignition module path (for deploy_ignition)' },
            network: { type: 'string', description: 'Target network' },
            address: { type: 'string', description: 'Contract address (for verify)' },
            constructorArgs: { type: 'array', items: {}, description: 'Constructor arguments (for verify)' },
            contractAddress: { type: 'string', description: 'Contract address (for call/execute)' },
            abi: { type: 'array', items: {}, description: 'Contract ABI (for call/execute)' },
            method: { type: 'string', description: 'Method name (for call/execute)' },
            methodArgs: { type: 'array', items: {}, description: 'Method arguments (for call/execute)' },
            privateKey: { type: 'string', description: 'Private key (for execute) - optional, auto-uses MCP operator' },
            value: { type: 'string', description: 'HBAR value in wei (for execute)' },
          },
          required: ['operation'],
        },
      },
  • src/index.ts:650-652 (registration)
    Dispatch/registration in the main tool execution switch statement in index.ts, mapping tool calls to the handler.
    case 'hardhat_contract':
      result = await hardhatContractManage(args as any);
      break;
  • src/index.ts:524-525 (registration)
    Inclusion of hardhatFoundryToolDefinitions (containing 'hardhat_contract' schema) into the main optimizedToolDefinitions array.
    ...hardhatFoundryToolDefinitions,
  • Helper function hardhatDeploy called by the handler for 'deploy' operation. Executes Hardhat deployment scripts with operator credentials.
    export async function hardhatDeploy(args: {
      script: string;
      network?: string;
      directory?: string;
    }): Promise<ToolResult> {
      try {
        logger.info('Deploying contracts', { script: args.script, network: args.network, directory: args.directory });
    
        // Import and inject operator environment variables
        const { getDeploymentEnvVars } = await import('../utils/key-converter.js');
        const envVars = getDeploymentEnvVars();
    
        // Inject operator credentials into environment
        for (const [key, value] of Object.entries(envVars)) {
          if (!process.env[key]) {
            // Only set if not already set
            process.env[key] = value;
          }
        }
    
        const hre = await hardhatService.getHRE(args.directory);
    
        // Run the deployment script
        await hre.run('run', { script: args.script, network: args.network });
    
        return {
          success: true,
          data: {
            message: 'Deployment script executed successfully',
            script: args.script,
            network: args.network || hre.network.name,
          },
          metadata: {
            executedVia: 'hardhat',
            command: `hardhat run ${args.script}`,
          },
        };
      } catch (error) {
        logger.error('Deployment failed', { error });
        return {
          success: false,
          error: error instanceof Error ? error.message : 'Deployment failed',
          metadata: {
            executedVia: 'hardhat',
            command: 'hardhat run',
          },
        };
      }
    }
Behavior3/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 does provide some useful behavioral context: the AUTO-RESOLUTION section explains credential handling, and it distinguishes between 'call' (read-only, FREE) and 'execute' (state-changing). However, it doesn't address important behavioral aspects like error handling, rate limits, network requirements, or what happens during deployment failures.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (OPERATIONS, AUTO-RESOLUTION, USE FOR) and uses bullet points effectively. It's appropriately sized for a multi-operation tool with 13 parameters. While efficient, the 'OPERATIONS' section could be slightly more concise by integrating the parenthetical clarifications into the main bullet points.

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

Completeness3/5

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

Given the tool's complexity (13 parameters, 5 operations, no annotations, no output schema), the description provides a reasonable foundation but has significant gaps. It explains what operations are available and some behavioral aspects, but doesn't address error cases, return formats, or prerequisites. For a tool with this many parameters and operations interacting with blockchain contracts, more comprehensive guidance would be helpful.

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 13 parameters thoroughly. The description adds minimal parameter semantics - it mentions that 'deploy_ignition' uses 'Hardhat Ignition (declarative)' and that 'call' is read-only while 'execute' is state-changing. These are helpful clarifications, but most parameter context remains in the schema. The baseline of 3 is appropriate given the comprehensive schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as 'Manage Hardhat contract deployment and interaction' and lists five specific operations, providing a comprehensive overview. However, it doesn't explicitly distinguish this tool from sibling tools like 'deploy_contract', 'verify_contract', or 'rpc_deploy_contract', which appear to have overlapping functionality in the same domain.

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 'USE FOR' section explicitly states when to use this tool: 'Contract deployment, verification, and interaction.' This provides clear context about appropriate use cases. However, it doesn't specify when NOT to use it or mention alternatives among the many sibling tools that appear related (like deploy_contract, verify_contract, rpc_deploy_contract, etc.).

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