rpc_deploy_contract
Deploy smart contracts to Hedera EVM using JSON-RPC. Handles bytecode deployment, constructor encoding, gas estimation, and returns contract address with transaction details.
Instructions
Deploy smart contract to Hedera via JSON-RPC.
HANDLES: Bytecode deployment, constructor encoding, gas estimation, receipt polling RETURNS: Contract address, transaction hash, deployment details COSTS: Gas fees for contract creation AUTO-KEY: privateKey is OPTIONAL - automatically uses MCP operator account if not provided
USE FOR: Deploying Solidity contracts to Hedera EVM.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| bytecode | Yes | Contract bytecode (0x...) | |
| abi | No | Contract ABI | |
| constructorArgs | No | Constructor arguments | |
| privateKey | No | Deployer private key (optional - uses MCP operator) |
Implementation Reference
- src/tools/rpc.ts:68-122 (handler)Core handler function that executes the rpc_deploy_contract tool. Validates input, calls jsonRpcService.deployContract, formats success/error responses as ToolResult.export async function rpcDeployContract(args: { bytecode: string; abi?: any[]; constructorArgs?: any[]; gasLimit?: number; privateKey?: string; fromAlias?: string; network?: 'mainnet' | 'testnet' | 'previewnet' | 'local'; }): Promise<ToolResult> { try { logger.info('Deploying contract via RPC', { hasConstructorArgs: !!args.constructorArgs?.length, network: args.network, }); // Validate bytecode if (!args.bytecode.startsWith('0x')) { throw new Error('Bytecode must start with 0x'); } const result = await jsonRpcService.deployContract({ bytecode: args.bytecode, abi: args.abi, constructorArgs: args.constructorArgs, gasLimit: args.gasLimit, privateKey: args.privateKey, fromAlias: args.fromAlias, network: args.network, }); return { success: true, data: { contractAddress: result.contractAddress, transactionHash: result.transactionHash, blockNumber: result.receipt.blockNumber, gasUsed: result.receipt.gasUsed, status: result.receipt.status === '0x1' ? 'success' : 'failed', }, metadata: { executedVia: 'json_rpc_relay', command: 'contract deploy', }, }; } catch (error) { logger.error('Contract deployment failed', { error }); return { success: false, error: error instanceof Error ? error.message : 'Unknown error occurred', metadata: { executedVia: 'json_rpc_relay', command: 'contract deploy', }, }; }
- src/index.ts:270-289 (schema)Input schema definition for rpc_deploy_contract tool used in MCP tool listing.{ name: 'rpc_deploy_contract', description: `Deploy smart contract to Hedera via JSON-RPC. HANDLES: Bytecode deployment, constructor encoding, gas estimation, receipt polling RETURNS: Contract address, transaction hash, deployment details COSTS: Gas fees for contract creation AUTO-KEY: privateKey is OPTIONAL - automatically uses MCP operator account if not provided USE FOR: Deploying Solidity contracts to Hedera EVM.`, inputSchema: { type: 'object' as const, properties: { bytecode: { type: 'string', description: 'Contract bytecode (0x...)' }, abi: { type: 'array', items: {}, description: 'Contract ABI' }, constructorArgs: { type: 'array', items: {}, description: 'Constructor arguments' }, privateKey: { type: 'string', description: 'Deployer private key (optional - uses MCP operator)' }, }, required: ['bytecode'], },
- src/index.ts:611-612 (registration)Registration in the main tool dispatcher switch statement that routes calls to the rpcDeployContract handler.case 'rpc_deploy_contract': result = await rpcDeployContract(args as any);
- src/tools/rpc.ts:277-317 (schema)Detailed input schema for rpc_deploy_contract in the exported rpcTools array (source definition).{ name: 'rpc_deploy_contract', description: 'Deploy smart contract to Hedera via JSON-RPC. Handles bytecode deployment, constructor arguments encoding, gas estimation, transaction signing, submission, and receipt polling. Returns contract address and transaction details.', inputSchema: { type: 'object' as const, properties: { bytecode: { type: 'string', description: 'Contract bytecode in hex format (must start with 0x)', }, abi: { type: 'array', description: 'Optional: Contract ABI for constructor encoding', items: {}, }, constructorArgs: { type: 'array', description: 'Optional: Constructor arguments', items: {}, }, gasLimit: { type: 'number', description: 'Optional: Gas limit override (auto-estimated if not provided)', }, privateKey: { type: 'string', description: 'Optional: Private key in DER format (or use fromAlias)', }, fromAlias: { type: 'string', description: 'Optional: Address book alias to use for deployment', }, network: { type: 'string', enum: ['mainnet', 'testnet', 'previewnet', 'local'], description: 'Target network (default: current network)', }, }, required: ['bytecode'], },