Skip to main content
Glama

deploy_contract

Deploy smart contracts to Hedera networks with auto-detection of project frameworks, constructor argument support, and automatic verification on HashScan.

Instructions

Deploy smart contract to Hedera with unified interface.

AUTO-DETECTS: Hardhat or Foundry project framework SUPPORTS: Constructor arguments, gas limits, auto-verification TRACKS: Deployment history with metadata

USE FOR: Production contract deployment, automated workflows, verified deployments.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contractNameYesContract name
networkYesTarget network
constructorArgsNoConstructor arguments
verifyNoAuto-verify on HashScan
frameworkNoFramework (auto-detected if not specified)

Implementation Reference

  • Primary handler function that executes the deploy_contract tool logic. Parses arguments, calls deploymentService.deployContract, formats ToolResult with success status, deployment details, and metadata.
    export async function deployContract(args: {
      contractName: string;
      network: HederaNetwork;
      constructorArgs?: any[];
      framework?: 'hardhat' | 'foundry' | 'direct';
      fromAlias?: string;
      privateKey?: string;
      gasLimit?: number;
      verify?: boolean;
      metadata?: Record<string, any>;
    }): Promise<ToolResult> {
      try {
        logger.info('Starting contract deployment', {
          contractName: args.contractName,
          network: args.network,
          framework: args.framework || 'auto-detect',
          verify: args.verify || false,
        });
    
        const result = await deploymentService.deployContract({
          contractName: args.contractName,
          network: args.network,
          constructorArgs: args.constructorArgs,
          framework: args.framework,
          fromAlias: args.fromAlias,
          privateKey: args.privateKey,
          gasLimit: args.gasLimit,
          verify: args.verify,
        });
    
        if (result.success && result.record) {
          return {
            success: true,
            data: {
              deploymentId: result.record.id,
              contractName: result.record.contractName,
              contractAddress: result.record.contractAddress,
              network: result.record.network,
              framework: result.record.framework,
              transactionHash: result.record.transactionHash,
              gasUsed: result.record.gasUsed,
              constructorArgs: result.record.constructorArgs,
              status: result.record.status,
              verificationStatus: result.record.verificationStatus,
              hashScanUrl: result.record.hashScanUrl,
              deployedAt: result.record.deployedAt,
            },
            metadata: {
              executedVia: result.record.framework,
              command: 'deploy_contract',
            },
          };
        } else {
          return {
            success: false,
            error: result.error || 'Deployment failed',
            metadata: {
              executedVia: 'deployment-service',
              command: 'deploy_contract',
            },
          };
        }
      } catch (error: any) {
        logger.error('Contract deployment failed', { error: error.message });
        return {
          success: false,
          error: error.message,
          metadata: {
            executedVia: 'deployment-service',
            command: 'deploy_contract',
          },
        };
      }
    }
  • Tool definition including name, description, and inputSchema used for registration and validation of deploy_contract tool.
      {
        name: 'deploy_contract',
        description: `Deploy smart contract to Hedera with unified interface.
    
    AUTO-DETECTS: Hardhat or Foundry project framework
    SUPPORTS: Constructor arguments, gas limits, auto-verification
    TRACKS: Deployment history with metadata
    
    USE FOR: Production contract deployment, automated workflows, verified deployments.`,
        inputSchema: {
          type: 'object' as const,
          properties: {
            contractName: { type: 'string', description: 'Contract name' },
            network: {
              type: 'string',
              enum: ['mainnet', 'testnet', 'previewnet'],
              description: 'Target network',
            },
            constructorArgs: { type: 'array', items: {}, description: 'Constructor arguments' },
            verify: { type: 'boolean', description: 'Auto-verify on HashScan' },
            framework: {
              type: 'string',
              enum: ['hardhat', 'foundry', 'direct'],
              description: 'Framework (auto-detected if not specified)',
            },
          },
          required: ['contractName', 'network'],
        },
      },
  • src/index.ts:633-634 (registration)
    Registration and dispatch logic in the main MCP server request handler that routes 'deploy_contract' calls to the deployContract function.
    case 'deploy_contract':
      result = await deployContract(args as any);
  • Core deployment service method called by the tool handler. Handles framework detection, performs actual deployment based on Hardhat/Foundry/direct, tracks history, and verification.
    async deployContract(options: DeploymentOptions): Promise<DeploymentResult> {
      try {
        logger.info('Starting contract deployment', {
          contractName: options.contractName,
          network: options.network,
          framework: options.framework || 'auto-detect',
        });
    
        // Detect framework if not specified
        const framework = options.framework || (await this.detectFramework());
        if (!framework) {
          return {
            success: false,
            error: 'Could not detect deployment framework',
          };
        }
    
        // Generate deployment ID
        const deploymentId = this.generateDeploymentId(options.contractName, options.network);
    
        // Create pending deployment record
        const record: DeploymentRecord = {
          id: deploymentId,
          contractName: options.contractName,
          contractAddress: '', // Will be filled after deployment
          network: options.network,
          framework,
          deployer: options.fromAlias || 'unknown',
          deployedAt: new Date().toISOString(),
          transactionHash: '',
          gasUsed: 0,
          constructorArgs: options.constructorArgs || [],
          status: 'deploying',
          verificationStatus: 'not_verified',
        };
    
        // Deploy based on framework
        let deploymentData: any;
        switch (framework) {
          case 'hardhat':
            deploymentData = await this.deployWithHardhat(options);
            break;
          case 'foundry':
            deploymentData = await this.deployWithFoundry(options);
            break;
          case 'direct':
            deploymentData = await this.deployWithRPC(options);
            break;
        }
    
        if (!deploymentData.success) {
          record.status = 'failed';
          this.deploymentHistory.push(record);
          await this.saveDeploymentHistory();
    
          return {
            success: false,
            error: deploymentData.error,
            record,
          };
        }
    
        // Update record with deployment data
        record.contractAddress = deploymentData.address;
        record.transactionHash = deploymentData.transactionHash;
        record.gasUsed = deploymentData.gasUsed || 0;
        record.status = 'deployed';
        record.hashScanUrl = hashScanService.getContractUrl(deploymentData.address, options.network);
        record.compilerVersion = deploymentData.compilerVersion;
    
        // Auto-verify if requested
        if (options.verify) {
          logger.info('Auto-verifying contract on HashScan', {
            address: record.contractAddress,
            network: options.network,
          });
    
          record.verificationStatus = 'pending';
          const verifyResult = await this.verifyDeployment(record, framework);
          if (verifyResult) {
            record.verificationStatus = 'verified';
            record.status = 'verified';
          } else {
            record.verificationStatus = 'failed';
          }
        }
    
        // Save to history
        this.deploymentHistory.push(record);
        await this.saveDeploymentHistory();
    
        logger.info('Contract deployment successful', {
          contractName: record.contractName,
          address: record.contractAddress,
          network: record.network,
          transactionHash: record.transactionHash,
          verified: record.verificationStatus === 'verified',
        });
    
        return {
          success: true,
          record,
        };
      } catch (error: any) {
        logger.error('Contract deployment failed', { error: error.message });
        return {
          success: false,
          error: error.message,
        };
      }

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