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
| Name | Required | Description | Default |
|---|---|---|---|
| operation | Yes | Contract operation to perform | |
| directory | No | Absolute path to Hardhat project directory | |
| script | No | Deployment script path (for deploy) | |
| module | No | Ignition module path (for deploy_ignition) | |
| network | No | Target network | |
| address | No | Contract address (for verify) | |
| constructorArgs | No | Constructor arguments (for verify) | |
| contractAddress | No | Contract address (for call/execute) | |
| abi | No | Contract ABI (for call/execute) | |
| method | No | Method name (for call/execute) | |
| methodArgs | No | Method arguments (for call/execute) | |
| privateKey | No | Private key (for execute) - optional, auto-uses MCP operator | |
| value | No | HBAR value in wei (for execute) |
Implementation Reference
- src/tools/composite.ts:739-813 (handler)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', }; } }
- src/tools/composite.ts:1041-1078 (schema)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,
- src/tools/hardhat.ts:274-322 (helper)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', }, }; } }