Last active
July 2, 2019 02:59
-
-
Save PierreRochard/ba4b9147ff58cf4f9850e7ecf44882c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// npm init -f | |
// npm install grpc --save | |
// npm install @grpc/proto-loader --save | |
const grpc = require('grpc'); | |
const fs = require('fs'); | |
const protoLoader = require('@grpc/proto-loader'); | |
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA'; | |
const lndCert = fs.readFileSync('tls.cert'); | |
const m = fs.readFileSync('admin.macaroon'); | |
const sslCreds = grpc.credentials.createSsl(lndCert); | |
protoLoader.load('rpc.proto', { | |
keepCase: true, | |
longs: String, | |
enums: String, | |
defaults: true, | |
oneofs: true | |
}).then(packageDefinition => { | |
const packageObject = grpc.loadPackageDefinition(packageDefinition); | |
const lnrpc = packageObject.lnrpc; | |
const macaroon = m.toString('hex'); | |
const metadata = new grpc.Metadata(); | |
metadata.add('macaroon', macaroon); | |
const macaroonCreds = grpc.credentials.createFromMetadataGenerator((_args, callback) => { | |
callback(null, metadata); | |
}); | |
const credentials = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds); | |
const client = new lnrpc.Lightning('localhost:10009', credentials); | |
client.getInfo({}, function (err, response) { | |
console.log(err); | |
console.log('GetInfo:', response); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this. I was struggling with replacing the deprecated grpc.load still being used in the LND example code. It seems that the settings object in protoLoader.load did the trick. So, this: