Skip to main content
Glama

withdraw

Transfer funds from your Lightning wallet to external BOLT11 invoices using operator authentication, enabling secure withdrawals with built-in security cooldown periods.

Instructions

Withdraw funds from operator account to external Lightning invoice. REQUIRES OPERATOR KEY. Subject to security cooldown.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
invoiceYesBOLT11 invoice to pay out to

Implementation Reference

  • The `withdraw` method implementation in `LightningFaucetClient` handles sending funds to an external Lightning invoice.
    async withdraw(invoice: string): Promise<{
      amountSats: number;
      routingFeeSats: number;
      platformFeeSats: number;
      totalCost: number;
      paymentHash: string;
      newBalance: number;
      rawResponse: ApiResponse;
    }> {
      const result = await this.request<ApiResponse & {
        amount_sats?: number;
        routing_fee_sats?: number;
        platform_fee_sats?: number;
        total_cost?: number;
        payment_hash?: string;
        new_balance?: number;
      }>('withdraw', { invoice });
    
      const amountSats = result.amount_sats || 0;
      const routingFeeSats = result.routing_fee_sats || 0;
      const platformFeeSats = result.platform_fee_sats || 0;
    
      return {
        amountSats,
        routingFeeSats,
        platformFeeSats,
        totalCost: result.total_cost || (amountSats + routingFeeSats + platformFeeSats),
        paymentHash: result.payment_hash || '',
        newBalance: result.new_balance || 0,
        rawResponse: result,
      };
    }
  • The MCP tool request handler for the 'withdraw' tool.
    case 'withdraw': {
      const parsed = WithdrawSchema.parse(args);
      const result = await session.requireClient().withdraw(parsed.invoice);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              message: 'Withdrawal successful',
              amount_sats: result.amountSats,
              routing_fee_sats: result.routingFeeSats,
              platform_fee_sats: result.platformFeeSats,
              total_cost: result.totalCost,
              payment_hash: result.paymentHash,
              new_balance: result.newBalance,
            }, null, 2),
          },
        ],
      };
    }
  • The Zod validation schema for the 'withdraw' tool.
    const WithdrawSchema = z.object({
      invoice: z.string().regex(/^ln(bc|tb|bcrt)1[a-z0-9]+$/i, 'Invalid BOLT11 invoice format')
        .describe('BOLT11 invoice to pay out to'),
    });

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/lightningfaucet/lightning-wallet-mcp'

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