Skip to main content
Glama

decode_invoice

Decode BOLT11 Lightning invoices to view payment details like amount, description, expiry, and destination without making a payment.

Instructions

Decode a BOLT11 invoice without paying it. Returns amount, description, expiry, and destination.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bolt11YesBOLT11 invoice string to decode

Implementation Reference

  • The actual implementation of decodeInvoice that makes the API request to decode a BOLT11 invoice.
    async decodeInvoice(bolt11: string): Promise<{
      amountSats: number;
      description: string;
      paymentHash: string;
      destination: string;
      expiresAt: string;
      isExpired: boolean;
      createdAt?: string;
      rawResponse: ApiResponse;
    }> {
      const result = await this.request<ApiResponse & {
        amount_sats?: number;
        num_satoshis?: string;
        description?: string;
        payment_hash?: string;
        destination?: string;
        timestamp?: string;
        expiry?: string;
        expires_at?: string;
        is_expired?: boolean;
      }>('decode_invoice', { invoice: bolt11 });
    
      const amountSats = result.amount_sats || parseInt(result.num_satoshis || '0', 10);
      const timestamp = result.timestamp ? parseInt(result.timestamp, 10) : 0;
      const expiry = result.expiry ? parseInt(result.expiry, 10) : 3600;
      const expiresAt = result.expires_at || new Date((timestamp + expiry) * 1000).toISOString();
      const isExpired = result.is_expired ?? (timestamp + expiry < Date.now() / 1000);
    
      return {
        amountSats,
        description: result.description || '',
        paymentHash: result.payment_hash || '',
        destination: result.destination || '',
        expiresAt,
        isExpired,
        createdAt: timestamp ? new Date(timestamp * 1000).toISOString() : undefined,
        rawResponse: result,
      };
    }
  • src/index.ts:1376-1396 (registration)
    The MCP tool handler that invokes decodeInvoice when the 'decode_invoice' tool is called.
    case 'decode_invoice': {
      const parsed = DecodeInvoiceSchema.parse(args);
      const result = await session.requireClient().decodeInvoice(parsed.bolt11);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify({
              success: true,
              amount_sats: result.amountSats,
              description: result.description,
              payment_hash: result.paymentHash,
              destination: result.destination,
              expires_at: result.expiresAt,
              is_expired: result.isExpired,
              created_at: result.createdAt,
            }, null, 2),
          },
        ],
      };
    }
  • Input validation schema for the decode_invoice tool.
    const DecodeInvoiceSchema = z.object({
      bolt11: z.string().regex(/^ln(bc|tb|bcrt)1[a-z0-9]+$/i, 'Invalid BOLT11 invoice format')
        .describe('BOLT11 invoice string to decode'),
    });

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