Skip to main content
Glama

create_wallet

Generate a new EVM or Solana wallet with encrypted private key storage, returning wallet ID and address for secure on-chain operations.

Instructions

Create a new EVM or Solana wallet. Returns the wallet ID and address. Private key is encrypted server-side and never exposed.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
labelNoFriendly name for the wallet
chain_idNoDefault chain ID (1=Ethereum, 8453=Base, 42161=Arbitrum, 10=Optimism, 137=Polygon, 43114=Avalanche, 56=BSC, 7777777=Zora, 369=PulseChain, 900=Solana, 901=Solana Devnet)

Implementation Reference

  • The handler for 'create_wallet' tool. Registers the tool with MCP server, defines the input schema (label and chain_id), and implements the handler that makes a POST request to /wallets API endpoint to create a new wallet.
    server.tool(
      'create_wallet',
      'Create a new EVM or Solana wallet. Returns the wallet ID and address. ' +
        'Private key is encrypted server-side and never exposed.',
      {
        label: z.string().default('').describe('Friendly name for the wallet'),
        chain_id: z.number().int().default(8453).describe('Default chain ID (1=Ethereum, 8453=Base, 42161=Arbitrum, 10=Optimism, 137=Polygon, 43114=Avalanche, 56=BSC, 7777777=Zora, 369=PulseChain, 900=Solana, 901=Solana Devnet)'),
      },
      async ({ label, chain_id }) => {
        const data = await api('/wallets', 'POST', { label, chain_id });
        return jsonResponse(data);
      },
    );
  • Input schema for create_wallet tool using Zod validation. Defines two parameters: 'label' (optional friendly name) and 'chain_id' (defaulting to Base chain 8453) for wallet creation.
      label: z.string().default('').describe('Friendly name for the wallet'),
      chain_id: z.number().int().default(8453).describe('Default chain ID (1=Ethereum, 8453=Base, 42161=Arbitrum, 10=Optimism, 137=Polygon, 43114=Avalanche, 56=BSC, 7777777=Zora, 369=PulseChain, 900=Solana, 901=Solana Devnet)'),
    },
  • API helper function used by create_wallet to make HTTP requests to the AgentWallet backend. Handles authentication, request formatting, and x402 payment flow.
    async function api(path: string, method = 'GET', body?: Record<string, unknown>, extraHeaders?: Record<string, string>): Promise<unknown> {
      const url = `${API_BASE}${path}`;
      const headers: Record<string, string> = {
        'Content-Type': 'application/json',
        ...extraHeaders,
      };
    
      if (API_USER && API_PASS) {
        headers['Authorization'] = 'Basic ' + Buffer.from(`${API_USER}:${API_PASS}`).toString('base64');
      }
    
      const options: RequestInit = { method, headers };
      if (body && method !== 'GET') {
        options.body = JSON.stringify(body);
      }
    
      const res = await fetch(url, options);
      const data = await res.json();
    
      // Handle 402 Payment Required — auto-pay if wallet configured
      if (res.status === 402 && X402_WALLET_ID && !extraHeaders?.['X-PAYMENT']) {
        return handleX402Payment(data as X402Response, path, method, body);
      }
    
      if (!res.ok) {
        const error = (data as { error?: string }).error || `HTTP ${res.status}`;
        throw new Error(error);
      }
    
      return data;
    }

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/hifriendbot/agentwallet-mcp'

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