Skip to main content

SubscribeTransactions

SubscribeTransactions creates a uni-directional stream from the server to the client in which any newly discovered transactions relevant to the wallet are sent over.

Source: lightning.proto

gRPC

info

This is a server-streaming RPC

rpc SubscribeTransactions (GetTransactionsRequest) returns (stream Transaction);

REST

HTTP MethodPath
GET /v1/transactions/subscribe

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', 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 = {
start_height: <int32>,
end_height: <int32>,
account: <string>,
};
let call = client.subscribeTransactions(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:
// {
// "tx_hash": <string>,
// "amount": <int64>,
// "num_confirmations": <int32>,
// "block_hash": <string>,
// "block_height": <int32>,
// "time_stamp": <int64>,
// "total_fees": <int64>,
// "dest_addresses": <string>,
// "output_details": <OutputDetail>,
// "raw_tx_hex": <string>,
// "label": <string>,
// "previous_outpoints": <PreviousOutPoint>,
// }

Messages

lnrpc.GetTransactionsRequest

Source: lightning.proto

FieldgRPC TypeREST TypeREST Placement
start_height
int32integerquery
end_height
int32integerquery
account
stringstringquery

lnrpc.Transaction

Source: lightning.proto

FieldgRPC TypeREST Type
tx_hash
stringstring
amount
int64string
num_confirmations
int32integer
block_hash
stringstring
block_height
int32integer
time_stamp
int64string
total_fees
int64string
dest_addresses
string[]array
output_details
OutputDetail[]array
raw_tx_hex
stringstring
label
stringstring
previous_outpoints
PreviousOutPoint[]array

Nested Messages

lnrpc.OutputDetail

FieldgRPC TypeREST Type
output_type
OutputScriptTypestring
address
stringstring
pk_script
stringstring
output_index
int64string
amount
int64string
is_our_address
boolboolean

lnrpc.PreviousOutPoint

FieldgRPC TypeREST Type
outpoint
stringstring
is_our_output
boolboolean

Enums

lnrpc.OutputScriptType

NameNumber
SCRIPT_TYPE_PUBKEY_HASH
0
SCRIPT_TYPE_SCRIPT_HASH
1
SCRIPT_TYPE_WITNESS_V0_PUBKEY_HASH
2
SCRIPT_TYPE_WITNESS_V0_SCRIPT_HASH
3
SCRIPT_TYPE_PUBKEY
4
SCRIPT_TYPE_MULTISIG
5
SCRIPT_TYPE_NULLDATA
6
SCRIPT_TYPE_NON_STANDARD
7
SCRIPT_TYPE_WITNESS_UNKNOWN
8
SCRIPT_TYPE_WITNESS_V1_TAPROOT
9