- Install dependencies (googleapis-common-protos is required due to the use of google/api/annotations.proto)
$ gem install grpc grpc-tools googleapis-common-protos
- Clone the google api's repository (required due to the use of google/api/annotations.proto)
$ git clone https://github.com/googleapis/googleapis.git
- Copy the lnd rpc.proto file (you'll find this in lnrpc/rpc.proto) or just download it
$ curl -o rpc.proto -s https://raw.githubusercontent.com/lightningnetwork/lnd/master/lnrpc/rpc.proto
- Copy the rpc.proto file inside googleapis dir
cp rpc.proto googleapis
- Compile the proto file
$ grpc_tools_ruby_protoc -I googleapis --ruby_out=. --grpc_out=. rpc.proto
After following these steps, two files rpc_pb2.rb
and rpc_services_pb.rb
will be generated. These files will be imported in your project while writing your clients. Here's an example of a simple client that was built using these.
$LOAD_PATH.unshift(".")
require "grpc"
require "rpc_pb"
require "rpc_services_pb"
require "pp"
user_name = user # well, set this ;)
channel_creds = GRPC::Core::ChannelCredentials.new(File.read("/home/#{user_name}/.lnd/tls.cert"))
stub = Lnrpc::Lightning::Stub.new("127.0.0.1:10009", channel_creds)
pp stub.get_info(Lnrpc::GetInfoRequest.new).to_h
puts
pp stub.wallet_balance(Lnrpc::WalletBalanceRequest.new(witness_only: true)).to_h
# can't figure out how to pass in macaroons if you do, please let me know :)
# macaroon = File.read("/home/#{user_name}/.lnd/admin.macaroon")
# macaroon = macaroon.force_encoding("utf-8")
# macaroon = macaroon.each_byte.map { |b| b.to_s(16) }.join
# This is python implementation for inputing macaroons in a request for reference, thanks to Freenode:lnd Veggen
# macaroon= binascii.hexlify(open(os.path.expanduser("~/.lnd/admin.macaroon"), 'rb').read()).encode('utf-8')
# metadata = [("macaroon", macaroon)]
# stub = lnrpc.LightningStub(channel)
# response = stub.ListChannels(ln.ListChannelsRequest(), metadata=metadata)
# Thanks takinbo
# Reference https://gist.github.com/takinbo/27b58c84dcb58abf8c556caad3949aea
did you ever figure out passing macaroons?