Skip to content

Send Lightning

lightning.payInvoiceSync(invoice: string)

Attempts to pay an invoice. Returns a Promise that resolves when the payment succeeds or fails / times out.

ts
import { 
FedimintWallet
} from '@fedimint/core-web'
const
wallet
= new
FedimintWallet
()
wallet
.
open
()
const
result
= await
wallet
.
lightning
.
payInvoiceSync
(
'lnbc...', // bolt11 invoice ) if (
result
.
success
) {
console
.
log
(
result
.
data
.
preimage
) // preimage of the settled payment
console
.
log
(
result
.
data
.
feeMsats
) // fee paid in msats
}

lightning.payInvoice(invoice: string)

Attempts to pay a lightning invoice. Returns an OutgoingLightningPayment object containing details about the in-flight payment.

You can use subscribeLnPay to track the payment status. waitForPay returns a Promise that resolves when the payment succeeds or fails / times out.

ts
import { 
FedimintWallet
} from '@fedimint/core-web'
import type {
LnPayState
} from '@fedimint/core-web'
const
wallet
= new
FedimintWallet
()
wallet
.
open
()
const {
fee
,
payment_type
} = await
wallet
.
lightning
.
payInvoice
(
'lnbc...', // bolt11 invoice ) // TODO: Simplify and explain this. // Users should not have to check if the operation_id exists. let
id
= '';
if ('lightning' in
payment_type
) {
id
=
payment_type
.
lightning
// in flight lightning payment id
} const
unsubscribe
=
wallet
.
lightning
.
subscribeLnPay
(
id
,
(
state
:
LnPayState
) =>
console
.
log
(
state
), // State of the payment
(
error
: string) =>
console
.
error
(
error
),
) // ...Cleanup Later
unsubscribe
()
const
result
= await
wallet
.
lightning
.
waitForPay
(
id
)
if (
result
.
success
) {
console
.
log
(
result
.
data
.
preimage
) // preimage of the settled payment
}