Skip to content

5 · Create an invoice

Bob asks to be paid by creating an invoice. The invoice holds fresh addresses from his wallet, an amount and, optionally, an expiry. Bob’s app shares these with Alice, and later checks her payment against them.

bin/first_payment.dart (step 5)
// Step 5: Bob creates an invoice.
final invoice = await coordinator.ask(CreateInvoiceCommand(
walletId: 'bob',
amount: BigInt.from(100000),
description: 'Tutorial coffee',
));
print('Bob invoices ${invoice.amount} sats to ${invoice.addresses.first}');
Bob invoices 100000 sats to mvd5qb56orNeWYdutrXpub9YR1yAJbrUKr

The reply is an InvoiceCreatedEvent:

Field What it is
invoiceId The invoice’s id. Payments and validation refer to it.
addresses The addresses to pay (one by default; numberOfAddresses asks for more)
amount The amount asked for, in satoshis
expiresAt When the invoice expires, if you gave it an expiry (expiresIn)

An invoice can also ask for several outputs of different kinds, such as multisig or OP_RETURN data. See Multi-output invoices.

Next: Alice pays →