Skip to main content
Glama

hardhat_project

Manage Hardhat project lifecycle for Hedera blockchain development. Initialize projects, compile contracts, run tests, and handle configuration for smart contract deployment.

Instructions

Manage Hardhat project lifecycle operations.

OPERATIONS:

  • init: Initialize new Hardhat project with Hedera configuration

  • compile: Compile Solidity contracts (with force option)

  • test: Run Mocha/Chai tests with filtering

  • clean: Clean artifacts and cache

  • flatten: Flatten contracts for verification

  • get_artifacts: Retrieve compiled ABI and bytecode

  • get_accounts: List available accounts with balances

  • config_network: Generate Hedera network config snippet

  • run_task: Execute custom Hardhat task

  • list_tasks: List all available tasks

USE FOR: Project setup, compilation, testing, and configuration management.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
operationYesProject operation to perform
directoryNoAbsolute path to Hardhat project directory (required for all operations except init which creates it)
networksNoNetworks to configure (for init)
solidityNoSolidity version (for init)
typescriptNoUse TypeScript (for init)
forceNoForce recompilation (for compile)
testFilesNoTest files to run (for test)
grepNoTest filter pattern (for test)
networkNoNetwork name
contractPathNoContract file path (for flatten)
contractNameNoContract name (for get_artifacts)
taskNoTask name (for run_task)
paramsNoTask parameters (for run_task)

Implementation Reference

  • Primary handler function that implements the 'hardhat_project' tool logic. Dispatches to Hardhat-specific operations (init, compile, test, etc.) using imported helpers from hardhat.ts.
    export async function hardhatProjectManage(args: { operation: 'init' | 'compile' | 'test' | 'clean' | 'flatten' | 'get_artifacts' | 'get_accounts' | 'config_network' | 'run_task' | 'list_tasks'; // Init-specific directory?: string; networks?: Array<'mainnet' | 'testnet' | 'previewnet' | 'local'>; solidity?: string; typescript?: boolean; // Compile-specific force?: boolean; // Test-specific testFiles?: string[]; grep?: string; network?: string; // Flatten-specific contractPath?: string; // Get artifacts-specific contractName?: string; // Run task-specific task?: string; params?: any; }): Promise<ToolResult> { try { logger.info('Hardhat project operation', { operation: args.operation }); switch (args.operation) { case 'init': return await hardhatTools.hardhatInit({ directory: args.directory, networks: args.networks, solidity: args.solidity, typescript: args.typescript, }); case 'compile': return await hardhatTools.hardhatCompile({ force: args.force, directory: args.directory }); case 'test': return await hardhatTools.hardhatTest({ testFiles: args.testFiles, grep: args.grep, network: args.network, directory: args.directory, }); case 'clean': return await hardhatTools.hardhatClean({ directory: args.directory }); case 'flatten': return await hardhatTools.hardhatFlatten({ files: args.contractPath ? [args.contractPath] : undefined, directory: args.directory }); case 'get_artifacts': return await hardhatTools.hardhatGetArtifacts({ contractName: args.contractName, directory: args.directory }); case 'get_accounts': return await hardhatTools.hardhatGetAccounts({ directory: args.directory }); case 'config_network': // Config network generates a config snippet, doesn't require all params return { success: true, data: { network: args.network || 'testnet', message: 'Use hardhat_contract with operation "deploy" and network parameter for actual deployment', }, }; case 'run_task': return await hardhatTools.hardhatRunTask({ task: args.task!, params: args.params, directory: args.directory, }); case 'list_tasks': return await hardhatTools.hardhatListTasks({ directory: args.directory }); default: throw new Error(`Unknown operation: ${args.operation}`); } } catch (error) { logger.error('Hardhat project 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_project' tool, exported in hardhatFoundryToolDefinitions array.
    { name: 'hardhat_project', description: `Manage Hardhat project lifecycle operations. OPERATIONS: - init: Initialize new Hardhat project with Hedera configuration - compile: Compile Solidity contracts (with force option) - test: Run Mocha/Chai tests with filtering - clean: Clean artifacts and cache - flatten: Flatten contracts for verification - get_artifacts: Retrieve compiled ABI and bytecode - get_accounts: List available accounts with balances - config_network: Generate Hedera network config snippet - run_task: Execute custom Hardhat task - list_tasks: List all available tasks USE FOR: Project setup, compilation, testing, and configuration management.`, inputSchema: { type: 'object' as const, properties: { operation: { type: 'string', enum: ['init', 'compile', 'test', 'clean', 'flatten', 'get_artifacts', 'get_accounts', 'config_network', 'run_task', 'list_tasks'], description: 'Project operation to perform', }, directory: { type: 'string', description: 'Absolute path to Hardhat project directory (required for all operations except init which creates it)' }, networks: { type: 'array', items: { type: 'string', enum: ['mainnet', 'testnet', 'previewnet', 'local'] }, description: 'Networks to configure (for init)', }, solidity: { type: 'string', description: 'Solidity version (for init)' }, typescript: { type: 'boolean', description: 'Use TypeScript (for init)' }, force: { type: 'boolean', description: 'Force recompilation (for compile)' }, testFiles: { type: 'array', items: { type: 'string' }, description: 'Test files to run (for test)' }, grep: { type: 'string', description: 'Test filter pattern (for test)' }, network: { type: 'string', description: 'Network name' }, contractPath: { type: 'string', description: 'Contract file path (for flatten)' }, contractName: { type: 'string', description: 'Contract name (for get_artifacts)' }, task: { type: 'string', description: 'Task name (for run_task)' }, params: { type: 'object', description: 'Task parameters (for run_task)' }, }, required: ['operation'], }, },
  • src/index.ts:647-649 (registration)
    Tool handler registration in the main MCP server request handler switch statement, mapping 'hardhat_project' calls to hardhatProjectManage function.
    case 'hardhat_project': result = await hardhatProjectManage(args as any); break;
  • src/index.ts:524-524 (registration)
    Registration of the tool definition/schema by spreading hardhatFoundryToolDefinitions into optimizedToolDefinitions array used for ListTools.
    ...hardhatFoundryToolDefinitions,
  • Import of helper functions from hardhat.ts used by the hardhatProjectManage dispatcher (e.g., hardhatInit, hardhatCompile, etc.). Actual exec logic in src/tools/hardhat.ts (ID:24511902).
    import * as hardhatTools from './hardhat.js'; import * as foundryTools from './foundry.js'; /** * Composite Hardhat Project Management Tool * Consolidates project-level operations into 1 tool */ export async function hardhatProjectManage(args: { operation: 'init' | 'compile' | 'test' | 'clean' | 'flatten' | 'get_artifacts' | 'get_accounts' | 'config_network' | 'run_task' | 'list_tasks'; // Init-specific directory?: string; networks?: Array<'mainnet' | 'testnet' | 'previewnet' | 'local'>; solidity?: string; typescript?: boolean; // Compile-specific force?: boolean; // Test-specific testFiles?: string[]; grep?: string; network?: string; // Flatten-specific contractPath?: string; // Get artifacts-specific contractName?: string; // Run task-specific task?: string; params?: any; }): Promise<ToolResult> { try { logger.info('Hardhat project operation', { operation: args.operation }); switch (args.operation) { case 'init': return await hardhatTools.hardhatInit({ directory: args.directory, networks: args.networks, solidity: args.solidity, typescript: args.typescript, }); case 'compile': return await hardhatTools.hardhatCompile({ force: args.force, directory: args.directory }); case 'test': return await hardhatTools.hardhatTest({ testFiles: args.testFiles, grep: args.grep, network: args.network, directory: args.directory, }); case 'clean': return await hardhatTools.hardhatClean({ directory: args.directory }); case 'flatten': return await hardhatTools.hardhatFlatten({ files: args.contractPath ? [args.contractPath] : undefined, directory: args.directory }); case 'get_artifacts': return await hardhatTools.hardhatGetArtifacts({ contractName: args.contractName, directory: args.directory }); case 'get_accounts': return await hardhatTools.hardhatGetAccounts({ directory: args.directory }); case 'config_network': // Config network generates a config snippet, doesn't require all params return { success: true, data: { network: args.network || 'testnet', message: 'Use hardhat_contract with operation "deploy" and network parameter for actual deployment', }, }; case 'run_task': return await hardhatTools.hardhatRunTask({ task: args.task!, params: args.params, directory: args.directory, }); case 'list_tasks': return await hardhatTools.hardhatListTasks({ directory: args.directory }); default: throw new Error(`Unknown operation: ${args.operation}`); } } catch (error) { logger.error('Hardhat project operation failed', { operation: args.operation, error }); return { success: false, error: error instanceof Error ? error.message : 'Unknown error', }; } }

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