deploy-contract
Deploy smart contracts to the blockchain by providing bytecode and constructor arguments. Simplifies interactions for AI-powered blockchain applications through secure, private key-free integration with MetaMask.
Instructions
Deploy a contract to the network, given bytecode, and constructor arguments
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| abi | Yes | ||
| args | Yes | ||
| bytecode | Yes |
Implementation Reference
- The main handler function that deploys the contract using wagmi/core's deployContract. Parses ABI, args, bytecode, executes deployment, returns transaction hash or handles errors appropriately.execute: async (_args) => { try { const abi = JSON.parse(_args.abi) as Abi const args = _args.args const bytecode = _args.bytecode as Hex const result = await deployContract(wagmiConfig, { abi, args, bytecode, }) 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, } ] } } },
- Zod schema defining the input parameters for the deploy-contract tool: abi (string), args (array of strings), bytecode (string).parameters: z.object({ abi: z.string(), args: z.string().array(), bytecode: z.string(), }),
- packages/metamask-mcp/src/tools/deploy-contract.ts:8-59 (registration)Function that registers the deploy-contract tool with the FastMCP server, defining name, description, schema, and handler.export function registerDeployContractTools(server: FastMCP): void { server.addTool({ name: "deploy-contract", description: "Deploy a contract to the network, given bytecode, and constructor arguments", parameters: z.object({ abi: z.string(), args: z.string().array(), bytecode: z.string(), }), execute: async (_args) => { try { const abi = JSON.parse(_args.abi) as Abi const args = _args.args const bytecode = _args.bytecode as Hex const result = await deployContract(wagmiConfig, { abi, args, bytecode, }) 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, } ] } } }, }); };
- packages/metamask-mcp/src/index.ts:41-41 (registration)Top-level call to register the deploy-contract tool in the main MetaMask MCP server initialization.registerDeployContractTools(server);