SendPayment
danger
This RPC is deprecated and will be removed in a future version.
Deprecated, use SendPaymentV2. SendPayment attempts to route a payment described by the passed PaymentRequest to the final destination. The call returns a stream of payment status updates.
Source: routerrpc/router.proto
gRPC
info
This is a server-streaming RPC
rpc SendPayment (SendPaymentRequest) returns (stream PaymentStatus);
Code Samples
- gRPC
- Shell
- Javascript
- Python
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>,
amt_msat: <int64>,
payment_hash: <bytes>,
final_cltv_delta: <int32>,
payment_addr: <bytes>,
payment_request: <string>,
timeout_seconds: <int32>,
fee_limit_sat: <int64>,
fee_limit_msat: <int64>,
outgoing_chan_id: <uint64>,
outgoing_chan_ids: <uint64>,
last_hop_pubkey: <bytes>,
cltv_limit: <int32>,
route_hints: <RouteHint>,
dest_custom_records: <DestCustomRecordsEntry>,
allow_self_payment: <bool>,
dest_features: <FeatureBit>,
max_parts: <uint32>,
no_inflight_updates: <bool>,
max_shard_size_msat: <uint64>,
amp: <bool>,
time_pref: <double>,
};
let call = client.sendPayment(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:
// {
// "state": <PaymentState>,
// "preimage": <bytes>,
// "htlcs": <HTLCAttempt>,
// }
import codecs, grpc, os
# Generate the following 2 modules by compiling the routerrpc/router.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import router_pb2 as routerrpc, router_pb2_grpc as routerstub
GRPC_HOST = 'localhost:10009'
MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
TLS_PATH = 'LND_DIR/tls.cert'
# create macaroon credentials
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
def metadata_callback(context, callback):
callback([('macaroon', macaroon)], None)
auth_creds = grpc.metadata_call_credentials(metadata_callback)
# create SSL credentials
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
cert = open(TLS_PATH, 'rb').read()
ssl_creds = grpc.ssl_channel_credentials(cert)
# combine macaroon and SSL credentials
combined_creds = grpc.composite_channel_credentials(ssl_creds, auth_creds)
# make the request
channel = grpc.secure_channel(GRPC_HOST, combined_creds)
stub = routerstub.RouterStub(channel)
request = routerrpc.SendPaymentRequest(
dest=<bytes>,
amt=<int64>,
amt_msat=<int64>,
payment_hash=<bytes>,
final_cltv_delta=<int32>,
payment_addr=<bytes>,
payment_request=<string>,
timeout_seconds=<int32>,
fee_limit_sat=<int64>,
fee_limit_msat=<int64>,
outgoing_chan_id=<uint64>,
outgoing_chan_ids=<uint64>,
last_hop_pubkey=<bytes>,
cltv_limit=<int32>,
route_hints=<RouteHint>,
dest_custom_records=<DestCustomRecordsEntry>,
allow_self_payment=<bool>,
dest_features=<FeatureBit>,
max_parts=<uint32>,
no_inflight_updates=<bool>,
max_shard_size_msat=<uint64>,
amp=<bool>,
time_pref=<double>,
)
for response in stub.SendPayment(request):
print(response)
# {
# "state": <PaymentState>,
# "preimage": <bytes>,
# "htlcs": <HTLCAttempt>,
# }
# There is no CLI command for this RPC
Messages
routerrpc.SendPaymentRequest
Source: routerrpc/router.proto
Field | gRPC Type | REST Type | REST Placement |
---|---|---|---|
dest | bytes | string | body |
amt | int64 | string | body |
amt_msat | int64 | string | body |
payment_hash | bytes | string | body |
final_cltv_delta | int32 | integer | body |
payment_addr | bytes | string | body |
payment_request | string | string | body |
timeout_seconds | int32 | integer | body |
fee_limit_sat | int64 | string | body |
fee_limit_msat | int64 | string | body |
outgoing_chan_id | uint64 | string | body |
outgoing_chan_ids | uint64[] | array | body |
last_hop_pubkey | bytes | string | body |
cltv_limit | int32 | integer | body |
route_hints | RouteHint[] | array | body |
dest_custom_records | DestCustomRecordsEntry[] | object | body |
allow_self_payment | bool | boolean | body |
dest_features | FeatureBit[] | array | body |
max_parts | uint32 | integer | body |
no_inflight_updates | bool | boolean | body |
max_shard_size_msat | uint64 | string | body |
amp | bool | boolean | body |
time_pref | double | number | body |
routerrpc.PaymentStatus
Source: routerrpc/router.proto
Field | gRPC Type | REST Type |
---|---|---|
state | PaymentState | string |
preimage | bytes | string |
htlcs | HTLCAttempt[] | array |
Nested Messages
lnrpc.RouteHint
Field | gRPC Type | REST Type |
---|---|---|
hop_hints | HopHint[] | array |
lnrpc.HopHint
Field | gRPC Type | REST Type |
---|---|---|
node_id | string | string |
chan_id | uint64 | string |
fee_base_msat | uint32 | integer |
fee_proportional_millionths | uint32 | integer |
cltv_expiry_delta | uint32 | integer |
routerrpc.SendPaymentRequest.DestCustomRecordsEntry
Field | gRPC Type | REST Type |
---|---|---|
key | uint64 | unknown |
value | bytes | unknown |
lnrpc.HTLCAttempt
Field | gRPC Type | REST Type |
---|---|---|
attempt_id | uint64 | string |
status | HTLCStatus | string |
route | Route | object |
attempt_time_ns | int64 | string |
resolve_time_ns | int64 | string |
failure | Failure | object |
preimage | bytes | string |
lnrpc.Route
Field | gRPC Type | REST Type |
---|---|---|
total_time_lock | uint32 | integer |
total_fees | int64 | string |
total_amt | int64 | string |
hops | Hop[] | array |
total_fees_msat | int64 | string |
total_amt_msat | int64 | string |
lnrpc.Hop
Field | gRPC Type | REST Type |
---|---|---|
chan_id | uint64 | string |
chan_capacity | int64 | string |
amt_to_forward | int64 | string |
fee | int64 | string |
expiry | uint32 | integer |
amt_to_forward_msat | int64 | string |
fee_msat | int64 | string |
pub_key | string | string |
tlv_payload | bool | boolean |
mpp_record | MPPRecord | object |
amp_record | AMPRecord | object |
custom_records | CustomRecordsEntry[] | object |
metadata | bytes | string |
lnrpc.MPPRecord
Field | gRPC Type | REST Type |
---|---|---|
payment_addr | bytes | string |
total_amt_msat | int64 | string |
lnrpc.AMPRecord
Field | gRPC Type | REST Type |
---|---|---|
root_share | bytes | string |
set_id | bytes | string |
child_index | uint32 | integer |
lnrpc.Hop.CustomRecordsEntry
Field | gRPC Type | REST Type |
---|---|---|
key | uint64 | unknown |
value | bytes | unknown |
lnrpc.Failure
Field | gRPC Type | REST Type |
---|---|---|
code | FailureCode | string |
channel_update | ChannelUpdate | object |
htlc_msat | uint64 | string |
onion_sha_256 | bytes | string |
cltv_expiry | uint32 | integer |
flags | uint32 | integer |
failure_source_index | uint32 | integer |
height | uint32 | integer |
lnrpc.ChannelUpdate
Field | gRPC Type | REST Type |
---|---|---|
signature | bytes | string |
chain_hash | bytes | string |
chan_id | uint64 | string |
timestamp | uint32 | integer |
message_flags | uint32 | integer |
channel_flags | uint32 | integer |
time_lock_delta | uint32 | integer |
htlc_minimum_msat | uint64 | string |
base_fee | uint32 | integer |
fee_rate | uint32 | integer |
htlc_maximum_msat | uint64 | string |
extra_opaque_data | bytes | string |
Enums
lnrpc.FeatureBit
Name | Number |
---|---|
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 |
AMP_REQ | 30 |
AMP_OPT | 31 |
routerrpc.PaymentState
Name | Number |
---|---|
IN_FLIGHT | 0 |
SUCCEEDED | 1 |
FAILED_TIMEOUT | 2 |
FAILED_NO_ROUTE | 3 |
FAILED_ERROR | 4 |
FAILED_INCORRECT_PAYMENT_DETAILS | 5 |
FAILED_INSUFFICIENT_BALANCE | 6 |
lnrpc.HTLCAttempt.HTLCStatus
Name | Number |
---|---|
IN_FLIGHT | 0 |
SUCCEEDED | 1 |
FAILED | 2 |
lnrpc.Failure.FailureCode
Name | Number |
---|---|
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 |
INTERNAL_FAILURE | 997 |
UNKNOWN_FAILURE | 998 |
UNREADABLE_FAILURE | 999 |