Skip to main content

SendPaymentV2

SendPaymentV2 attempts to route a payment described by the passed PaymentRequest to the final destination. The call returns a stream of payment updates. When using this RPC, make sure to set a fee limit, as the default routing fee limit is 0 sats. Without a non-zero fee limit only routes without fees will be attempted which often fails with FAILURE_REASON_NO_ROUTE.

Source: routerrpc/router.proto

gRPC

info

This is a server-streaming RPC

rpc SendPaymentV2 (SendPaymentRequest) returns (stream Payment);

REST

HTTP MethodPath
POST /v2/router/send

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 = {
dest: <bytes>,
amt: <int64>,
payment_hash: <bytes>,
final_cltv_delta: <int32>,
payment_request: <string>,
timeout_seconds: <int32>,
fee_limit_sat: <int64>,
outgoing_chan_id: <uint64>,
cltv_limit: <int32>,
route_hints: <RouteHint>,
dest_custom_records: <DestCustomRecordsEntry>,
amt_msat: <int64>,
fee_limit_msat: <int64>,
last_hop_pubkey: <bytes>,
allow_self_payment: <bool>,
dest_features: <FeatureBit>,
max_parts: <uint32>,
no_inflight_updates: <bool>,
outgoing_chan_ids: <uint64>,
payment_addr: <bytes>,
max_shard_size_msat: <uint64>,
amp: <bool>,
time_pref: <double>,
cancelable: <bool>,
first_hop_custom_records: <FirstHopCustomRecordsEntry>,
};
let call = client.sendPaymentV2(request);
call.on('data', function(response) {
// A response was received from the server.
console.log(response);
});
call.on('status', function(status) {
// The current status of the stream.
});
call.on('end', function() {
// The server has closed the stream.
});
// Console output:
// {
// "payment_hash": <string>,
// "value": <int64>,
// "creation_date": <int64>,
// "fee": <int64>,
// "payment_preimage": <string>,
// "value_sat": <int64>,
// "value_msat": <int64>,
// "payment_request": <string>,
// "status": <PaymentStatus>,
// "fee_sat": <int64>,
// "fee_msat": <int64>,
// "creation_time_ns": <int64>,
// "htlcs": <HTLCAttempt>,
// "payment_index": <uint64>,
// "failure_reason": <PaymentFailureReason>,
// "first_hop_custom_records": <FirstHopCustomRecordsEntry>,
// }

Messages

routerrpc.SendPaymentRequest

Source: routerrpc/router.proto

FieldgRPC TypeREST TypeREST Placement
dest
bytesstringbody
amt
int64stringbody
payment_hash
bytesstringbody
final_cltv_delta
int32integerbody
payment_request
stringstringbody
timeout_seconds
int32integerbody
fee_limit_sat
int64stringbody
outgoing_chan_iddeprecated
uint64stringbody
cltv_limit
int32integerbody
route_hints
RouteHint[]arraybody
dest_custom_records
DestCustomRecordsEntry[]objectbody
amt_msat
int64stringbody
fee_limit_msat
int64stringbody
last_hop_pubkey
bytesstringbody
allow_self_payment
boolbooleanbody
dest_features
FeatureBit[]arraybody
max_parts
uint32integerbody
no_inflight_updates
boolbooleanbody
outgoing_chan_ids
uint64[]arraybody
payment_addr
bytesstringbody
max_shard_size_msat
uint64stringbody
amp
boolbooleanbody
time_pref
doublenumberbody
cancelable
boolbooleanbody
first_hop_custom_records
FirstHopCustomRecordsEntry[]objectbody

lnrpc.Payment

Source: lightning.proto

FieldgRPC TypeREST Type
payment_hash
stringstring
valuedeprecated
int64string
creation_datedeprecated
int64string
feedeprecated
int64string
payment_preimage
stringstring
value_sat
int64string
value_msat
int64string
payment_request
stringstring
status
PaymentStatusstring
fee_sat
int64string
fee_msat
int64string
creation_time_ns
int64string
htlcs
HTLCAttempt[]array
payment_index
uint64string
failure_reason
PaymentFailureReasonstring
first_hop_custom_records
FirstHopCustomRecordsEntry[]object

Nested Messages

lnrpc.AMPRecord

FieldgRPC TypeREST Type
root_share
bytesstring
set_id
bytesstring
child_index
uint32integer

lnrpc.ChannelUpdate

FieldgRPC TypeREST Type
signature
bytesstring
chain_hash
bytesstring
chan_id
uint64string
timestamp
uint32integer
message_flags
uint32integer
channel_flags
uint32integer
time_lock_delta
uint32integer
htlc_minimum_msat
uint64string
base_fee
uint32integer
fee_rate
uint32integer
htlc_maximum_msat
uint64string
extra_opaque_data
bytesstring

lnrpc.Failure

FieldgRPC TypeREST Type
code
FailureCodestring
channel_update
ChannelUpdateobject
htlc_msat
uint64string
onion_sha_256
bytesstring
cltv_expiry
uint32integer
flags
uint32integer
failure_source_index
uint32integer
height
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.HopHint

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

lnrpc.HTLCAttempt

FieldgRPC TypeREST Type
attempt_id
uint64string
status
HTLCStatusstring
route
Routeobject
attempt_time_ns
int64string
resolve_time_ns
int64string
failure
Failureobject
preimage
bytesstring

lnrpc.MPPRecord

FieldgRPC TypeREST Type
payment_addr
bytesstring
total_amt_msat
int64string

lnrpc.Payment.FirstHopCustomRecordsEntry

FieldgRPC TypeREST Type
key
uint64unknown
value
bytesunknown

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

lnrpc.RouteHint

FieldgRPC TypeREST Type
hop_hints
HopHint[]array

routerrpc.SendPaymentRequest.DestCustomRecordsEntry

FieldgRPC TypeREST Type
key
uint64unknown
value
bytesunknown

routerrpc.SendPaymentRequest.FirstHopCustomRecordsEntry

FieldgRPC TypeREST Type
key
uint64unknown
value
bytesunknown

Enums

lnrpc.Failure.FailureCode

NameNumber
RESERVED
0
INCORRECT_OR_UNKNOWN_PAYMENT_DETAILS
1
INCORRECT_PAYMENT_AMOUNT
2
FINAL_INCORRECT_CLTV_EXPIRY
3
FINAL_INCORRECT_HTLC_AMOUNT
4
FINAL_EXPIRY_TOO_SOON
5
INVALID_REALM
6
EXPIRY_TOO_SOON
7
INVALID_ONION_VERSION
8
INVALID_ONION_HMAC
9
INVALID_ONION_KEY
10
AMOUNT_BELOW_MINIMUM
11
FEE_INSUFFICIENT
12
INCORRECT_CLTV_EXPIRY
13
CHANNEL_DISABLED
14
TEMPORARY_CHANNEL_FAILURE
15
REQUIRED_NODE_FEATURE_MISSING
16
REQUIRED_CHANNEL_FEATURE_MISSING
17
UNKNOWN_NEXT_PEER
18
TEMPORARY_NODE_FAILURE
19
PERMANENT_NODE_FAILURE
20
PERMANENT_CHANNEL_FAILURE
21
EXPIRY_TOO_FAR
22
MPP_TIMEOUT
23
INVALID_ONION_PAYLOAD
24
INVALID_ONION_BLINDING
25
INTERNAL_FAILURE
997
UNKNOWN_FAILURE
998
UNREADABLE_FAILURE
999

lnrpc.FeatureBit

NameNumber
DATALOSS_PROTECT_REQ
0
DATALOSS_PROTECT_OPT
1
INITIAL_ROUING_SYNC
3
UPFRONT_SHUTDOWN_SCRIPT_REQ
4
UPFRONT_SHUTDOWN_SCRIPT_OPT
5
GOSSIP_QUERIES_REQ
6
GOSSIP_QUERIES_OPT
7
TLV_ONION_REQ
8
TLV_ONION_OPT
9
EXT_GOSSIP_QUERIES_REQ
10
EXT_GOSSIP_QUERIES_OPT
11
STATIC_REMOTE_KEY_REQ
12
STATIC_REMOTE_KEY_OPT
13
PAYMENT_ADDR_REQ
14
PAYMENT_ADDR_OPT
15
MPP_REQ
16
MPP_OPT
17
WUMBO_CHANNELS_REQ
18
WUMBO_CHANNELS_OPT
19
ANCHORS_REQ
20
ANCHORS_OPT
21
ANCHORS_ZERO_FEE_HTLC_REQ
22
ANCHORS_ZERO_FEE_HTLC_OPT
23
ROUTE_BLINDING_REQUIRED
24
ROUTE_BLINDING_OPTIONAL
25
AMP_REQ
30
AMP_OPT
31

lnrpc.HTLCAttempt.HTLCStatus

NameNumber
IN_FLIGHT
0
SUCCEEDED
1
FAILED
2

lnrpc.Payment.PaymentStatus

NameNumber
UNKNOWNdeprecated
0
IN_FLIGHT
1
SUCCEEDED
2
FAILED
3
INITIATED
4

lnrpc.PaymentFailureReason

NameNumber
FAILURE_REASON_NONE
0
FAILURE_REASON_TIMEOUT
1
FAILURE_REASON_NO_ROUTE
2
FAILURE_REASON_ERROR
3
FAILURE_REASON_INCORRECT_PAYMENT_DETAILS
4
FAILURE_REASON_INSUFFICIENT_BALANCE
5
FAILURE_REASON_CANCELED
6