Skip to main content
Glama

deploy_wallet

Deploy a new NFT-owned wallet using deterministic addressing for AI agent payments through the ClawPay MCP server.

Instructions

Deploy a new AgentAccountV2 wallet via the factory contract. The wallet is deterministically addressed (CREATE2) and owned by an NFT. Returns the wallet address and deployment transaction hash. Requires FACTORY_ADDRESS and NFT_CONTRACT_ADDRESS env vars (or pass them as arguments).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
token_idYesNFT token ID that will own this wallet (e.g. "1")
nft_contract_addressNoNFT contract address. Defaults to NFT_CONTRACT_ADDRESS env var.
factory_addressNoFactory contract address. Defaults to FACTORY_ADDRESS env var.

Implementation Reference

  • The main logic for deploying a wallet using the `deployWallet` SDK function, including configuration validation and result formatting.
    export async function handleDeployWallet(
      input: DeployWalletInput
    ): Promise<{ content: Array<{ type: 'text'; text: string }>; isError?: boolean }> {
      try {
        const config = getConfig();
    
        const factoryAddress = (input.factory_address ?? config.factoryAddress) as Address | undefined;
        if (!factoryAddress) {
          throw new Error(
            'Factory address required. Pass factory_address argument or set FACTORY_ADDRESS env var.'
          );
        }
    
        const nftContractAddress = (input.nft_contract_address ?? config.nftContractAddress) as Address | undefined;
        if (!nftContractAddress) {
          throw new Error(
            'NFT contract address required. Pass nft_contract_address argument or set NFT_CONTRACT_ADDRESS env var.'
          );
        }
    
        const tokenId = BigInt(input.token_id);
    
        const chainMap: Record<number, typeof base | typeof baseSepolia> = {
          8453: base,
          84532: baseSepolia,
        };
        const chainNameMap: Record<number, 'base' | 'base-sepolia'> = {
          8453: 'base',
          84532: 'base-sepolia',
        };
    
        const chain = chainMap[config.chainId];
        if (!chain) {
          throw new Error(`Unsupported chain for deployment: ${config.chainId}`);
        }
    
        const account = privateKeyToAccount(config.agentPrivateKey);
        const walletClient = createWalletClient({
          account,
          chain,
          transport: http(config.rpcUrl, { timeout: 30_000 }),
        });
    
        const result = await deployWallet({
          factoryAddress,
          tokenContract: nftContractAddress,
          tokenId,
          chain: chainNameMap[config.chainId] ?? 'base',
          rpcUrl: config.rpcUrl,
          walletClient,
        });
    
        const explorerAddr = explorerAddressUrl(result.walletAddress, config.chainId);
        const explorerTx = explorerTxUrl(result.txHash, config.chainId);
        const cname = chainName(config.chainId);
    
        return {
          content: [
            textContent(
              `✅ Agent Wallet deployed successfully!\n\n` +
              `📍 Wallet Address: ${result.walletAddress}\n` +
              `🔗 Explorer: ${explorerAddr}\n\n` +
              `📋 Transaction: ${result.txHash}\n` +
              `🔗 Explorer: ${explorerTx}\n\n` +
              `🔑 Owner NFT: ${nftContractAddress} #${input.token_id}\n` +
              `🌐 Chain: ${cname}\n\n` +
              `â„šī¸  Next steps:\n` +
              `  1. Set AGENT_WALLET_ADDRESS=${result.walletAddress} in your .env\n` +
              `  2. Use set_spend_policy (via SDK) to configure autonomous spending limits\n` +
              `  3. Fund the wallet with ETH or USDC for agent payments`
            ),
          ],
        };
      } catch (error: unknown) {
        return {
          content: [textContent(formatError(error, 'deploy_wallet'))],
          isError: true,
        };
      }
    }
  • Zod schema definition for input validation of the `deploy_wallet` tool.
    export const DeployWalletSchema = z.object({
      token_id: z
        .string()
        .describe('NFT token ID that will own the deployed wallet (e.g. "1")'),
      nft_contract_address: z
        .string()
        .optional()
        .describe(
          'NFT contract address that owns this wallet. ' +
          'Defaults to NFT_CONTRACT_ADDRESS env var.'
        ),
      factory_address: z
        .string()
        .optional()
        .describe(
          'AgentAccountFactoryV2 address. ' +
          'Defaults to FACTORY_ADDRESS env var.'
        ),
    });
    
    export type DeployWalletInput = z.infer<typeof DeployWalletSchema>;
  • MCP tool definition for `deploy_wallet` providing metadata and inputSchema.
    export const deployWalletTool = {
      name: 'deploy_wallet',
      description:
        'Deploy a new AgentAccountV2 wallet via the factory contract. ' +
        'The wallet is deterministically addressed (CREATE2) and owned by an NFT. ' +
        'Returns the wallet address and deployment transaction hash. ' +
        'Requires FACTORY_ADDRESS and NFT_CONTRACT_ADDRESS env vars (or pass them as arguments).',
      inputSchema: {
        type: 'object' as const,
        properties: {
          token_id: {
            type: 'string',
            description: 'NFT token ID that will own this wallet (e.g. "1")',
          },
          nft_contract_address: {
            type: 'string',
            description: 'NFT contract address. Defaults to NFT_CONTRACT_ADDRESS env var.',
          },
          factory_address: {
            type: 'string',
            description: 'Factory contract address. Defaults to FACTORY_ADDRESS env var.',
          },
        },
        required: ['token_id'],
      },
    };

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/up2itnow0822/claw-pay-mcp'

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