Skip to main content
The LNbits API provides core Lightning Network functionality including user authentication, wallet management, payment processing, and invoice generation.

Import

import lnbits from '@/api/lnbits'

Authentication

register

Register a new user account and create a default wallet with paylink.
const accessToken = await lnbits.register(username, email, password)
username
string
required
Unique username for the account
email
string
required
Email address for the account
password
string
required
Password for the account
accessToken
string
JWT access token for authenticated requests
import lnbits from '@/api/lnbits'

try {
  const accessToken = await lnbits.register(
    'alice',
    '[email protected]',
    'securePassword123'
  )
  // Store accessToken securely
} catch (error) {
  console.error('Registration failed:', error.message)
}

login

Authenticate an existing user and obtain an access token.
const accessToken = await lnbits.login(username, password)
username
string
required
Account username
password
string
required
Account password
accessToken
string
JWT access token for authenticated requests
import lnbits from '@/api/lnbits'

try {
  const accessToken = await lnbits.login('alice', 'securePassword123')
  // Store accessToken securely
} catch (error) {
  console.error('Login failed:', error.message)
}

getUser

Retrieve user information including all wallets and balances.
const user = await lnbits.getUser(accessToken)
accessToken
string
required
JWT access token from login or register
user
object
User information and wallets
import lnbits from '@/api/lnbits'

const user = await lnbits.getUser(accessToken)
console.log(`Total balance: ${user.totalBalance} sats`)
console.log(`Wallets: ${user.wallets.length}`)

Wallet Management

createWallet

Create a new wallet for the authenticated user.
const wallet = await lnbits.createWallet(name, adminkey)
name
string
required
Display name for the new wallet
adminkey
string
required
Admin key from an existing wallet
wallet
object
Newly created wallet with id, name, balance, adminkey, and inkey

updateWalletName

Update the display name of an existing wallet.
const wallet = await lnbits.updateWalletName(name, adminkey)
name
string
required
New display name for the wallet
adminkey
string
required
Admin key of the wallet to update

deleteWallet

Permanently delete a wallet.
await lnbits.deleteWallet(walletId, adminkey)
walletId
string
required
ID of the wallet to delete
adminkey
string
required
Admin key with permission to delete wallets

Payments

getPayments

Retrieve all successful payments for a wallet with historical fiat prices.
const payments = await lnbits.getPayments(inkey)
inkey
string
required
Invoice key of the wallet
payments
array
Array of payment transactions with fiat snapshots
const payments = await lnbits.getPayments(inkey)

payments.forEach(payment => {
  console.log(`${payment.sats} sats - ${payment.fiatSnapshot.USD} USD`)
})

getPaginatedPayments

Retrieve paginated payment history with limit and offset support.
const payments = await lnbits.getPaginatedPayments(
  inkey,
  { limit: 20, offset: 0, walletId: 'wallet_id' },
  snapshots,
  addSnapshot
)
inkey
string
required
Invoice key of the wallet
options
object
snapshots
Record<string, FiatSnapshot>
required
Cache of historical price snapshots
addSnapshot
function
required
Callback to add snapshot to cache

Invoices

createInvoice

Generate a Lightning invoice for receiving payments.
const invoice = await lnbits.createInvoice(amount, inkey, memo)
amount
number
required
Amount in satoshis
inkey
string
required
Invoice key of the receiving wallet
memo
string
Optional description for the invoice
invoice
object
Invoice object with payment_request and payment_hash
const invoice = await lnbits.createInvoice(
  1000,
  inkey,
  'Payment for coffee'
)

console.log('Invoice:', invoice.payment_request)
console.log('Hash:', invoice.payment_hash)

pay

Pay a Lightning invoice (bolt11) or LNURL.
await lnbits.pay(payData, adminkey)
payData
PayData
required
Payment data object
adminkey
string
required
Admin key of the paying wallet
const payData = {
  type: 'bolt11',
  invoice: 'lnbc1000n1...'
}

await lnbits.pay(payData, adminkey)

payInvoice

Directly pay a bolt11 Lightning invoice.
const payment = await lnbits.payInvoice(invoice, adminkey)
invoice
string
required
Bolt11 invoice string
adminkey
string
required
Admin key of the paying wallet

payLnurl

Pay an LNURL invoice.
const payment = await lnbits.payLnurl(payload, adminkey)
payload
object
required
LNURL payment payload
adminkey
string
required
Admin key of the paying wallet

Create an LNURL paylink for receiving payments.
const lnurl = await lnbits.createPaylink(adminkey)
adminkey
string
required
Admin key of the wallet
lnurl
string
LNURL string for receiving payments

Retrieve all paylinks for a wallet.
const paylinks = await lnbits.getPaylinks(inkey)
inkey
string
required
Invoice key of the wallet
Array of paylink objects

Conversion & Rates

convert

Convert satoshis to fiat currency using current exchange rate.
const fiatAmount = await lnbits.convert(sats, fiat)
sats
number
required
Amount in satoshis to convert
fiat
SupportedFiatCurrencies
required
Target fiat currency (e.g., ‘USD’, ‘EUR’, ‘GBP’)
fiatAmount
number
Converted amount in the specified fiat currency

rate

Get the current Bitcoin exchange rate for a fiat currency.
const exchangeRate = await lnbits.rate(fiat)
fiat
SupportedFiatCurrencies
required
Fiat currency code
rate
number
Current Bitcoin price in the specified fiat currency

WebSocket Subscriptions

subscribePaymentWs

Subscribe to payment status updates via WebSocket.
const webSocket = lnbits.subscribePaymentWs(paymentHash, callback)
paymentHash
string
required
Payment hash to monitor
callback
function
required
Callback function invoked when payment is confirmed
webSocket
WebSocket
WebSocket connection object
const invoice = await lnbits.createInvoice(1000, inkey)

const ws = lnbits.subscribePaymentWs(
  invoice.payment_hash,
  () => {
    console.log('Payment received!')
  }
)

// Cleanup
ws.close()

subscribeInkeyWs

Subscribe to all incoming payments for a wallet via WebSocket.
const webSocket = lnbits.subscribeInkeyWs(inkey, callback)
inkey
string
required
Invoice key of the wallet to monitor
callback
function
required
Callback function invoked with payment amount when received
webSocket
WebSocket
WebSocket connection object
const ws = lnbits.subscribeInkeyWs(
  inkey,
  (amount) => {
    console.log(`Received ${amount} sats`)
  }
)

// Cleanup
ws.close()

Build docs developers (and LLMs) love