[BITCOIN] Lightning Network mailing – episode 2: Communicating with the lightning network using gRPC !!!

Tram Ho

In this section, we will learn how to set up and interact with lnd through the gRPC protocol. Before starting this step, make sure you have installed btcd and lnd you can see here and also node and npm . References in this , this is the API docs for web on lncli (CLI) can interact with Python and JavaScript communicate with local LND through gRPC. It is for those who already understand LND you can read here . In addition, LND also provides an interactive method vs other LND that is REST you can read here

The example below assumes that running LND local and port connection on port 10009. File gRPC rpc.proto can be downloaded here

Init wallet

I will use my repo, which has fully setup the docker environment, you can clone at https://github.com/vinhyenvodoi98/LightningNetwork-Nodejs

Quickly go through the steps to start any LND network you just need to run the command

After running this command, they will create:

  • a simnet bitcoin network
  • 3 Bitcoin LND nodes (concurrently connecting peers between nodes)

Note: name these 3 nodes alice, bob, charlie and we will work with node alice in this article

Then to get environment variables we need to run

Copies Alice’s LND_MACAROON and LND_CERT to the .env file

GRPC Setting

We use this code to set up the connet with gRPC

Tested a bit with the getinfo function, right:

Get walletbalance

Check out the peer

Create Channel

Now we need to mine 5 blocks for the channel to be considered valid:

Note that creating a channel here is a one-way channel, meaning that once the channel is created, it will only create a channel to recharge. This is called a single-funds channel, and the channel created with 2 people who deposit money is called mutually funds channels and the LND developer in the next updates. There are some suggested solutions you can read here: https://bitcoin.stackexchange.com/questions/80792/how-to-create-bidirectional-channels-using-lnd

Conducting transactions between channels

Create an invoice

We take payment_request and send payment in alice’s order -> bob

Create a payment

We run commad against bob’s node

payment_request taken above. Then we will confirm

It is completed

Close Channel


You can create an external node by yourself or start another container then connect to the remaining nodes and create the same channel as above.

Creating the P2P Network

Now that the two accounts have some Bitcoin on the simnet, let’s connect the two accounts vs each other

We take Alice’s public key and know Alice’s port is 10012

Where identity_pubkey is my Public key

Connect peer

Then we can check the peer

So we can connect with Alice.

references :



Share the news now

Source : Viblo