Skip to main content
Glama

deploy-contract

Deploy smart contracts to blockchain networks using bytecode, ABI, and constructor arguments for secure AI-powered blockchain interactions.

Instructions

Deploy a contract to the network, given bytecode, and constructor arguments

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
abiYes
argsYes
bytecodeYes

Implementation Reference

  • Handler function that parses inputs, calls wagmi's deployContract, returns transaction hash or error message.
    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: abi (string), args (array of strings), bytecode (string).
    parameters: z.object({
      abi: z.string(),
      args: z.string().array(),
      bytecode: z.string(),
    }),
  • Function that registers the 'deploy-contract' tool on the FastMCP server with full definition.
    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,
                }
              ]
            }
          }
        },
      });
    };
  • Invocation of the registration function during server setup to add the tool.
    registerDeployContractTools(server);

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/Xiawpohr/mcpilot'

If you have feedback or need assistance with the MCP directory API, please join our Discord server