Skip to content

Instantly share code, notes, and snippets.

@isNotOkay
Created March 15, 2019 13:15
Show Gist options
  • Save isNotOkay/da91f2a338f71efbca840cea980fce9b to your computer and use it in GitHub Desktop.
Save isNotOkay/da91f2a338f71efbca840cea980fce9b to your computer and use it in GitHub Desktop.
var fs = require('fs');
var grpc = require('grpc');
var http = require('request-promise');
// use a macaroon file to prevent that no one else messes around with your node
var macaroon = fs.readFileSync("../admin.macaroon").toString('hex');
///// REST Example /////
// Add this line if your server has no valid SSL certificate
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = '0';
http.get('https://' + LND_NODE_IP_ADDRESS + ':8080/v1/getinfo', {
headers: {
'Grpc-Metadata-macaroon': macaroon
},
json: true
}).then((response) => {
console.log(response);
});
///// gRPC Example /////
// From the official DOCs:
// "Due to updated ECDSA generated tls.cert we need to let gprc know that
// we need to use that cipher suite otherwise there will be a handhsake
// error when we communicate with the lnd rpc server."
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
var lndCert = fs.readFileSync('../tls.cert');
var sslCreds = grpc.credentials.createSsl(lndCert);
var macaroonCreds = grpc.credentials.createFromMetadataGenerator(function (args, callback) {
var metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
var creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
var lnrpcDescriptor = grpc.load('../rpc.proto');
var lnrpc = lnrpcDescriptor.lnrpc;
var lightning = new lnrpc.Lightning(LND_NODE_IP_ADDRESS, creds);
lightning.getInfo({}, function (err, response) {
console.log(response);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment