Skip to main content

AddInvoice

AddInvoice attempts to add a new invoice to the invoice database. Any duplicated invoices are rejected, therefore all invoices must have a unique payment preimage.

Source: lightning.proto

gRPC

rpc AddInvoice (Invoice) returns (AddInvoiceResponse);

REST

HTTP MethodPath
POST /v1/invoices

Code Samples

const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

const GRPC_HOST = 'localhost:10009'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
const TLS_PATH = 'LND_DIR/tls.cert'

const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync('lightning.proto', loaderOptions);
const lnrpc = grpc.loadPackageDefinition(packageDefinition).lnrpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new lnrpc.Lightning(GRPC_HOST, creds);
let request = {
memo: <string>,
r_preimage: <bytes>,
r_hash: <bytes>,
value: <int64>,
value_msat: <int64>,
settled: <bool>,
creation_date: <int64>,
settle_date: <int64>,
payment_request: <string>,
description_hash: <bytes>,
expiry: <int64>,
fallback_addr: <string>,
cltv_expiry: <uint64>,
route_hints: <RouteHint>,
private: <bool>,
add_index: <uint64>,
settle_index: <uint64>,
amt_paid: <int64>,
amt_paid_sat: <int64>,
amt_paid_msat: <int64>,
state: <InvoiceState>,
htlcs: <InvoiceHTLC>,
features: <FeaturesEntry>,
is_keysend: <bool>,
payment_addr: <bytes>,
is_amp: <bool>,
amp_invoice_state: <AmpInvoiceStateEntry>,
};
client.addInvoice(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "r_hash": <bytes>,
// "payment_request": <string>,
// "add_index": <uint64>,
// "payment_addr": <bytes>,
// }

Messages

lnrpc.Invoice

Source: lightning.proto

FieldgRPC TypeREST TypeREST Placement
memo
stringstringbody
r_preimage
bytesstringbody
r_hash
bytesstringbody
value
int64stringbody
value_msat
int64stringbody
settleddeprecated
boolbooleanbody
creation_date
int64stringbody
settle_date
int64stringbody
payment_request
stringstringbody
description_hash
bytesstringbody
expiry
int64stringbody
fallback_addr
stringstringbody
cltv_expiry
uint64stringbody
route_hints
RouteHint[]arraybody
private
boolbooleanbody
add_index
uint64stringbody
settle_index
uint64stringbody
amt_paid
int64stringbody
amt_paid_sat
int64stringbody
amt_paid_msat
int64stringbody
state
InvoiceStatestringbody
htlcs
InvoiceHTLC[]arraybody
features
FeaturesEntry[]objectbody
is_keysend
boolbooleanbody
payment_addr
bytesstringbody
is_amp
boolbooleanbody
amp_invoice_state
AmpInvoiceStateEntry[]objectbody

lnrpc.AddInvoiceResponse

Source: lightning.proto

FieldgRPC TypeREST Type
r_hash
bytesstring
payment_request
stringstring
add_index
uint64string
payment_addr
bytesstring

Nested Messages

lnrpc.RouteHint

FieldgRPC TypeREST Type
hop_hints
HopHint[]array

lnrpc.HopHint

FieldgRPC TypeREST Type
node_id
stringstring
chan_id
uint64string
fee_base_msat
uint32integer
fee_proportional_millionths
uint32integer
cltv_expiry_delta
uint32integer

lnrpc.InvoiceHTLC

FieldgRPC TypeREST Type
chan_id
uint64string
htlc_index
uint64string
amt_msat
uint64string
accept_height
int32integer
accept_time
int64string
resolve_time
int64string
expiry_height
int32integer
state
InvoiceHTLCStatestring
custom_records
CustomRecordsEntry[]object
mpp_total_amt_msat
uint64string
amp
AMPobject

lnrpc.InvoiceHTLC.CustomRecordsEntry

FieldgRPC TypeREST Type
key
uint64unknown
value
bytesunknown

lnrpc.AMP

FieldgRPC TypeREST Type
root_share
bytesstring
set_id
bytesstring
child_index
uint32integer
hash
bytesstring
preimage
bytesstring

lnrpc.Invoice.FeaturesEntry

FieldgRPC TypeREST Type
key
uint32unknown
value
Featureunknown

lnrpc.Feature

FieldgRPC TypeREST Type
name
stringstring
is_required
boolboolean
is_known
boolboolean

lnrpc.Invoice.AmpInvoiceStateEntry

FieldgRPC TypeREST Type
key
stringunknown
value
AMPInvoiceStateunknown

lnrpc.AMPInvoiceState

FieldgRPC TypeREST Type
state
InvoiceHTLCStatestring
settle_index
uint64string
settle_time
int64string
amt_paid_msat
int64string

Enums

lnrpc.Invoice.InvoiceState

NameNumber
OPEN
0
SETTLED
1
CANCELED
2
ACCEPTED
3

lnrpc.InvoiceHTLCState

NameNumber
ACCEPTED
0
SETTLED
1
CANCELED
2