Hercle
WebSocket

Create Lightning Invoice

Creates a Lightning Network invoice.

Auth:API Key
Tags:
Lightning
Command Name
CreateLightningInvoice

Command Arguments

ClientId
Required
Type:
string
Description:

Custom client ID (max 36 characters)

Example: "my-invoice-123"
AmountBtc
Required
Type:
decimal
Description:

Amount of BTC to be invoiced

Example: 0.001
Memo
Required
Type:
string | null
Description:

Optional memo for the invoice

Example: "Payment for services"
ExpiryHours
Required
Type:
number | null
Description:

Expiry time in hours (default: 24 (if null), max: 720)

Example: 24

Command Invocation

Command Arguments Example:
[
  "my-invoice-123",
  0.001,
  "Payment for services",
  24
]
Invocation Example:
connection.invoke('CreateLightningInvoice', ['my-invoice-123', 0.001, 'Payment for services', 24])

Response Event

Event Name
executionEvents
Subject
execution.invoice.created
FieldTypeDescription
httpStatusCodenumberHTTP status code of the invoice creation response
idstringUnique identifier for the created invoice
expiresAtstringISO 8601 timestamp when the invoice expires
messagestringResponse message
encodedPaymentRequeststringEncoded Lightning payment request

Example Response

{
  "data": {
    "httpStatusCode": 201,
    "id": "inv_abc123def456",
    "expiresAt": "2024-03-28T16:03:12.456Z",
    "message": "Lightning invoice created successfully",
    "encodedPaymentRequest": "lnbc10u1p3xnhl2pp5jmxtqn235tkjzf..."
  }
}

Code Examples

const signalR = require('@microsoft/signalr');

const apiKey = 'YOUR_API_KEY_HERE';
const connection = new signalR.HubConnectionBuilder()
  .withUrl('https://publicapi.sandbox.hercle.financial/ExecutionLiveServer/v1', {
    accessTokenFactory: () => apiKey,
  })
  .build();

connection.start()
  .then(() => {
    console.log('Connected to WebSocket');
    
    // Invoke command
    connection.invoke('CreateLightningInvoice', "my-invoice-123", 0.001, "Payment for services", 24)
      .then(() => {
        console.log('Command sent successfully');
      })
      .catch(err => {
        console.error('Command failed:', err);
      });
  })
  .catch(err => {
    console.error('Connection failed:', err);
  });

// Listen for events
connection.on('executionEvents', (data) => {
  console.log('Received event:', data);
});

SignalR API Tester

Test this command in the sandbox environment

Disconnected

Your API key is only used locally and never stored

Event Log

No events yet. Connect and invoke a command to see events.