I am looking for a way to find all the available connections and channels in the lightning network.
For example, if you go to www.1ml.com/testnet, you can see the number of nodes and number of connections. Somehow they achieve this information. How can I achieve it without going to their website and looking at it. Is there a code to do that?
Secondly, how can I find the list of all active nodes and channels in LN. Is there a code to do that?
Have a nice day!
Generally the information you seek is propagated through the gossip protocol of the peer 2 peer network of the lightning network protocol. (though this will only include public channels and nodes. Every node and channel owner can decide to keep their own information private)
Thus every lightning implementation will have access to most of the information displayed on 1ml.com. You can either use a client library to program against the api of an implementation.
Easier would be to just get the information on the command line. So in clightning you can call lightning-cli listchannels
and lightning-cli listnodes
. With lnd it should be only one api call describechannelgraph
to get both information. As mentioned both commands exist also in client libraries.
To see if nodes are online you have to connect to them.