deploy-contract
Deploy smart contracts to blockchain networks using bytecode and constructor arguments. This tool enables secure contract deployment through MetaMask integration.
Instructions
Deploy a contract to the network, given bytecode, and constructor arguments.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| abi | Yes | The contract's ABI. | |
| args | No | Arguments to pass when deploying the contract. Inferred from abi. | |
| bytecode | Yes | The contract's bytecode. |
Implementation Reference
- src/tools/deploy-contract.ts:19-53 (handler)Executes the deployment of a smart contract using wagmi's deployContract function. Returns the transaction hash on success or an error message on failure.execute: async (args) => { try { const result = await deployContract(wagmiConfig, args); return { content: [ { type: "text", text: JSONStringify({ hash: result, }), }, ], }; } catch (error) { if (error instanceof TransactionExecutionError) { return { content: [ { type: "text", text: error.cause.message, }, ], }; } return { content: [ { type: "text", text: (error as Error).message, }, ], }; } },
- src/tools/deploy-contract.ts:12-18 (schema)Defines the tool name, description, and input schema using Zod for ABI, optional constructor arguments, and bytecode.name: "deploy-contract", description: "Deploy a contract to the network, given bytecode, and constructor arguments.", parameters: z.object({ abi: Abi.describe("The contract's ABI."), args: z.unknown().array().optional().describe("Arguments to pass when deploying the contract. Inferred from abi."), bytecode: Calldata.describe("The contract's bytecode."), }),
- src/tools/deploy-contract.ts:10-55 (registration)Registers the "deploy-contract" tool with the FastMCP server, including schema and handler.export function registerDeployContractTools(server: FastMCP, wagmiConfig: Config): void { server.addTool({ name: "deploy-contract", description: "Deploy a contract to the network, given bytecode, and constructor arguments.", parameters: z.object({ abi: Abi.describe("The contract's ABI."), args: z.unknown().array().optional().describe("Arguments to pass when deploying the contract. Inferred from abi."), bytecode: Calldata.describe("The contract's bytecode."), }), execute: async (args) => { try { const result = await deployContract(wagmiConfig, args); return { content: [ { type: "text", text: JSONStringify({ hash: result, }), }, ], }; } catch (error) { if (error instanceof TransactionExecutionError) { return { content: [ { type: "text", text: error.cause.message, }, ], }; } return { content: [ { type: "text", text: (error as Error).message, }, ], }; } }, }); };
- src/tools/register-tools.ts:36-36 (registration)Calls registerDeployContractTools as part of the central tool registration in registerTools.registerDeployContractTools(server, wagmiConfig);