Skip to main content

BuildRoute

BuildRoute builds a fully specified route based on a list of hop public keys. It retrieves the relevant channel policies from the graph in order to calculate the correct fees and time locks. Note that LND will use its default final_cltv_delta if no value is supplied. Make sure to add the correct final_cltv_delta depending on the invoice restriction. Moreover the caller has to make sure to provide the payment_addr if the route is paying an invoice which signaled it.

Source: routerrpc/router.proto

gRPC

rpc BuildRoute (BuildRouteRequest) returns (BuildRouteResponse);

REST

HTTP MethodPath
POST /v2/router/route

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', 'routerrpc/router.proto'], loaderOptions);
const routerrpc = grpc.loadPackageDefinition(packageDefinition).routerrpc;
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 routerrpc.Router(GRPC_HOST, creds);
let request = {
amt_msat: <int64>,
final_cltv_delta: <int32>,
outgoing_chan_id: <uint64>,
hop_pubkeys: <bytes>,
payment_addr: <bytes>,
first_hop_custom_records: <FirstHopCustomRecordsEntry>,
};
client.buildRoute(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "route": <Route>,
// }

Messages

routerrpc.BuildRouteRequest

Source: routerrpc/router.proto

FieldgRPC TypeREST TypeREST Placement
amt_msat
int64stringbody
final_cltv_delta
int32integerbody
outgoing_chan_id
uint64stringbody
hop_pubkeys
bytes[]arraybody
payment_addr
bytesstringbody
first_hop_custom_records
FirstHopCustomRecordsEntry[]objectbody

routerrpc.BuildRouteResponse

Source: routerrpc/router.proto

FieldgRPC TypeREST Type
route
Routeobject

Nested Messages

lnrpc.AMPRecord

FieldgRPC TypeREST Type
root_share
bytesstring
set_id
bytesstring
child_index
uint32integer

lnrpc.Hop

FieldgRPC TypeREST Type
chan_id
uint64string
chan_capacity
int64string
amt_to_forward
int64string
fee
int64string
expiry
uint32integer
amt_to_forward_msat
int64string
fee_msat
int64string
pub_key
stringstring
tlv_payload
boolboolean
mpp_record
MPPRecordobject
amp_record
AMPRecordobject
custom_records
CustomRecordsEntry[]object
metadata
bytesstring
blinding_point
bytesstring
encrypted_data
bytesstring
total_amt_msat
uint64string

lnrpc.Hop.CustomRecordsEntry

FieldgRPC TypeREST Type
key
uint64unknown
value
bytesunknown

lnrpc.MPPRecord

FieldgRPC TypeREST Type
payment_addr
bytesstring
total_amt_msat
int64string

lnrpc.Route

FieldgRPC TypeREST Type
total_time_lock
uint32integer
total_fees
int64string
total_amt
int64string
hops
Hop[]array
total_fees_msat
int64string
total_amt_msat
int64string
first_hop_amount_msat
int64string
custom_channel_data
bytesstring

routerrpc.BuildRouteRequest.FirstHopCustomRecordsEntry

FieldgRPC TypeREST Type
key
uint64unknown
value
bytesunknown