Skip to content

Receive Lightning

lightning.createInvoice()

Create a Lightning Invoice for a given amount. Returns a CreateBolt11Response object containing details about the created invoice.

You can use subscribeLnReceive to track the invoice status.

waitForReceive returns a Promise that resolves when the invoice succeeds or timeoutMs is reached.

ts
import { 
FedimintWallet
} from '@fedimint/core-web'
import type {
LnReceiveState
} from '@fedimint/core-web'
const
wallet
= new
FedimintWallet
()
wallet
.
open
()
const {
operation_id
,
invoice
} = await
wallet
.
lightning
.
createInvoice
(
10_000, // msats 'This is an invoice description', )
console
.
log
(
operation_id
) // operation id for the invoice
console
.
log
(
invoice
) // bolt11 invoice
const
unsubscribe
=
wallet
.
lightning
.
subscribeLnReceive
(
operation_id
,
(
state
:
LnReceiveState
) =>
console
.
log
(
state
),
(
error
: string) =>
console
.
error
(
error
),
) // ...Cleanup Later
unsubscribe
()
try { const
timeoutMs
= 10000
await
wallet
.
lightning
.
waitForReceive
(
operation_id
,
timeoutMs
)
console
.
log
('Payment Received!')
} catch (
error
) {
console
.
error
(
error
) // Timeout waiting for payment
}