Create Lightning Invoice

Overview

A Lightning invoice is a payment request that allows a payer to send bitcoin over the Lightning Network. You can generate a Lightning invoice by specifying the amount and optional metadata, such as a memo or expiry time. You then share the invoice with a payer, who uses it to complete the payment.

Create Lightning Invoice

Endpoint: Create a lightning invoice

export COIN="tlntbc"
export WALLET_ID="<YOUR_WALLET_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export ADDRESS="<DESTINATION_ADDRESS>"
export AMOUNT="<AMOUNT_IN_BASE_UNITS>"
export WALLET_PASSPHRASE="<YOUR_WALLET_PASSPHRASE>"

curl -X POST \
  https://app.bitgo-test.com/api/v2/$COIN/wallet/$WALLET_ID/lightning/invoice \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
    "valueMsat": string,   # Amount in millisatoshis (required)
    "memo": string,        # Description of the invoice (optional)
    "expiry": number       # Expiration time in seconds (optional)
}'
  const { BitGo } = require('bitgo');
  const { getLightningWallet } = require('@bitgo/abstract-lightning');
  const accessToken = '<YOUR_ACCESS_TOKEN>';

  // Initialize the SDK
  const bitgo = new BitGo({
    accessToken: accessToken,
    env: 'test',
    customRootURI: 'https://app.bitgo-test.com',
  });

  // Enter your Lightning wallet
  const walletId = '<YOUR_WALLET_ID>'
  const existingWallet = await bitgo.coin('tlnbtc').wallets().get({ id: walletId });
  const lightningWallet = getLightningWallet(existingWallet);
    
  const invoice = await lightningWallet.createInvoice({ valueMsat: 1000n, memo: 'test', expiry: 36000 });
  console.dir(invoice);

Step Result

{
    "value": bigint,       // Amount in millisatoshis
    "memo": string,        // Description of the invoice
    "paymentHash": string, // Unique identifier of the payment
    "invoice": string,     // Encoded payment request
    "walletId": string,    // ID of the BitGo wallet that created the invoice
    "status": open,        // Current status of the invoice (e.g., "open")
    "expiresAt": string    // ISO timestamp when the invoice expires
}

Next Steps

Pay Lightning Invoice

See Also

Reference: Bitcoin Lightning Network