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', }, }; } }

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