DecodePayReq
DecodePayReq takes an encoded payment request string and attempts to decode it, returning a full description of the conditions encoded within the payment request.
Source: lightning.proto
gRPC
rpc DecodePayReq (PayReqString) returns (PayReq);
REST
| HTTP Method | Path | 
|---|---|
| GET | /v1/payreq/{pay_req} | 
Code Samples
- gRPC
 - REST
 - 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', 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 = {
  pay_req: <string>,
};
client.decodePayReq(request, function(err, response) {
  console.log(response);
});
// Console output:
//  {
//    "destination": <string>,
//    "payment_hash": <string>,
//    "num_satoshis": <int64>,
//    "timestamp": <int64>,
//    "expiry": <int64>,
//    "description": <string>,
//    "description_hash": <string>,
//    "fallback_addr": <string>,
//    "cltv_expiry": <int64>,
//    "route_hints": <RouteHint>,
//    "payment_addr": <bytes>,
//    "num_msat": <int64>,
//    "features": <FeaturesEntry>,
//    "blinded_paths": <BlindedPaymentPath>,
//  }
import codecs, grpc, os
# Generate the following 2 modules by compiling the lightning.proto with the grpcio-tools.
# See https://github.com/lightningnetwork/lnd/blob/master/docs/grpc/python.md for instructions.
import lightning_pb2 as lnrpc, lightning_pb2_grpc as lightningstub
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 = lightningstub.LightningStub(channel)
request = lnrpc.PayReqString(
  pay_req=<string>,
)
response = stub.DecodePayReq(request)
print(response)
# {
#    "destination": <string>,
#    "payment_hash": <string>,
#    "num_satoshis": <int64>,
#    "timestamp": <int64>,
#    "expiry": <int64>,
#    "description": <string>,
#    "description_hash": <string>,
#    "fallback_addr": <string>,
#    "cltv_expiry": <int64>,
#    "route_hints": <RouteHint>,
#    "payment_addr": <bytes>,
#    "num_msat": <int64>,
#    "features": <FeaturesEntry>,
#    "blinded_paths": <BlindedPaymentPath>,
# }
- Javascript
 - Python
 
const fs = require('fs');
const request = require('request');
const REST_HOST = 'localhost:8080'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
let options = {
  url: `https://${REST_HOST}/v1/payreq/{pay_req}`,
  // Work-around for self-signed certificates.
  rejectUnauthorized: false,
  json: true,
  headers: {
    'Grpc-Metadata-macaroon': fs.readFileSync(MACAROON_PATH).toString('hex'),
  },
}
request.get(options, function(error, response, body) {
  console.log(body);
});
// Console output:
//  {
//    "destination": <string>, // <string> 
//    "payment_hash": <string>, // <string> 
//    "num_satoshis": <string>, // <int64> 
//    "timestamp": <string>, // <int64> 
//    "expiry": <string>, // <int64> 
//    "description": <string>, // <string> 
//    "description_hash": <string>, // <string> 
//    "fallback_addr": <string>, // <string> 
//    "cltv_expiry": <string>, // <int64> 
//    "route_hints": <array>, // <RouteHint> 
//    "payment_addr": <string>, // <bytes> 
//    "num_msat": <string>, // <int64> 
//    "features": <object>, // <FeaturesEntry> 
//    "blinded_paths": <array>, // <BlindedPaymentPath> 
//  }
import base64, codecs, json, requests
REST_HOST = 'localhost:8080'
MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
TLS_PATH = 'LND_DIR/tls.cert'
url = f'https://{REST_HOST}/v1/payreq/{pay_req}'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
headers = {'Grpc-Metadata-macaroon': macaroon}
r = requests.get(url, headers=headers, verify=TLS_PATH)
print(r.json())
# {
#    "destination": <string>,
#    "payment_hash": <string>,
#    "num_satoshis": <int64>,
#    "timestamp": <int64>,
#    "expiry": <int64>,
#    "description": <string>,
#    "description_hash": <string>,
#    "fallback_addr": <string>,
#    "cltv_expiry": <int64>,
#    "route_hints": <RouteHint>,
#    "payment_addr": <bytes>,
#    "num_msat": <int64>,
#    "features": <FeaturesEntry>,
#    "blinded_paths": <BlindedPaymentPath>,
# }
$ lncli decodepayreq --help
NAME:
   lncli decodepayreq - Decode a payment request.
USAGE:
   lncli decodepayreq [command options] pay_req
CATEGORY:
   Invoices
DESCRIPTION:
   Decode the passed payment request revealing the destination, payment hash and value of the payment request
OPTIONS:
   --pay_req value  the bech32 encoded payment request
   
Messages
lnrpc.PayReqString
Source: lightning.proto
| Field | gRPC Type | REST Type | REST Placement | 
|---|---|---|---|
pay_req | string | string | path | 
lnrpc.PayReq
Source: lightning.proto
| Field | gRPC Type | REST Type | 
|---|---|---|
destination | string | string | 
payment_hash | string | string | 
num_satoshis | int64 | string | 
timestamp | int64 | string | 
expiry | int64 | string | 
description | string | string | 
description_hash | string | string | 
fallback_addr | string | string | 
cltv_expiry | int64 | string | 
route_hints | RouteHint[] | array | 
payment_addr | bytes | string | 
num_msat | int64 | string | 
features | FeaturesEntry[] | object | 
blinded_paths | BlindedPaymentPath[] | array | 
Nested Messages
lnrpc.BlindedHop
| Field | gRPC Type | REST Type | 
|---|---|---|
blinded_node | bytes | string | 
encrypted_data | bytes | string | 
lnrpc.BlindedPath
| Field | gRPC Type | REST Type | 
|---|---|---|
introduction_node | bytes | string | 
blinding_point | bytes | string | 
blinded_hops | BlindedHop[] | array | 
lnrpc.BlindedPaymentPath
| Field | gRPC Type | REST Type | 
|---|---|---|
blinded_path | BlindedPath | object | 
base_fee_msat | uint64 | string | 
proportional_fee_rate | uint32 | integer | 
total_cltv_delta | uint32 | integer | 
htlc_min_msat | uint64 | string | 
htlc_max_msat | uint64 | string | 
features | FeatureBit[] | array | 
lnrpc.Feature
| Field | gRPC Type | REST Type | 
|---|---|---|
name | string | string | 
is_required | bool | boolean | 
is_known | bool | boolean | 
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 | 
lnrpc.PayReq.FeaturesEntry
| Field | gRPC Type | REST Type | 
|---|---|---|
key | uint32 | unknown | 
value | Feature | unknown | 
lnrpc.RouteHint
| Field | gRPC Type | REST Type | 
|---|---|---|
hop_hints | HopHint[] | array | 
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 | 
ROUTE_BLINDING_REQUIRED | 24 | 
ROUTE_BLINDING_OPTIONAL | 25 | 
AMP_REQ | 30 | 
AMP_OPT | 31 |