Skip to main content

AddInvoice

AddInvoice is a wrapper around lnd's lnrpc.AddInvoice method with asset specific parameters. It allows RPC users to create invoices that correspond to the specified asset amount. If a peer pubkey is specified, then only that peer will be used for RFQ negotiations. If none is specified then RFQ quotes for all peers with suitable asset channels will be created.

Source: tapchannelrpc/tapchannel.proto

gRPC

rpc AddInvoice (AddInvoiceRequest) returns (AddInvoiceResponse);

REST

HTTP MethodPath
POST /v1/taproot-assets/channels/invoice

Code Samples

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

const GRPC_HOST = 'localhost:10029'
const MACAROON_PATH = 'TAPROOT-ASSETS_DIR/regtest/taproot-assets.macaroon'
const TLS_PATH = 'TAPROOT-ASSETS_DIR/tls.cert'

const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync('tapchannelrpc/tapchannel.proto', loaderOptions);
const tapchannelrpc = grpc.loadPackageDefinition(packageDefinition).tapchannelrpc;
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 tapchannelrpc.TaprootAssetChannels(GRPC_HOST, creds);
let request = {
asset_id: <bytes>,
asset_amount: <uint64>,
peer_pubkey: <bytes>,
invoice_request: <Invoice>,
hodl_invoice: <HodlInvoice>,
group_key: <bytes>,
};
client.addInvoice(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "accepted_buy_quote": <PeerAcceptedBuyQuote>,
// "invoice_result": <AddInvoiceResponse>,
// }

Messages

tapchannelrpc.AddInvoiceRequest

Source: tapchannelrpc/tapchannel.proto

FieldgRPC TypeREST TypeREST Placement
asset_id
bytesstringbody
asset_amount
uint64stringbody
peer_pubkey
bytesstringbody
invoice_request
Invoiceobjectbody
hodl_invoice
HodlInvoiceobjectbody
group_key
bytesstringbody

tapchannelrpc.AddInvoiceResponse

Source: tapchannelrpc/tapchannel.proto

FieldgRPC TypeREST Type
accepted_buy_quote
PeerAcceptedBuyQuoteobject
invoice_result
AddInvoiceResponseobject

Nested Messages

rfqrpc.FixedPoint

FieldgRPC TypeREST Type
coefficient
stringstring
scale
uint32integer

rfqrpc.PeerAcceptedBuyQuote

FieldgRPC TypeREST Type
peer
stringstring
id
bytesstring
scid
uint64string
asset_max_amount
uint64string
ask_asset_rate
FixedPointobject
expiry
uint64string
min_transportable_units
uint64string

tapchannelrpc.HodlInvoice

FieldgRPC TypeREST Type
payment_hash
bytesstring