2

I want to write some scripts for experiments with Lightning. Python is the language I'm most comfortable with. From the three major implementations, LND has python-grpc and c-lightning has pylightning, but what about Eclair? How can I interact with an Eclair node from a Python script?

2 Answers 2

2

Here is a simple implementation that just works

import requests

class EclairClient():
    def __init__(self,host, port, password, service_name=None, session=None):
        self._host = host
        self._port = port
        self._password = password
        self._session = session
        if session is None:
            self._session = requests.Session()
        self._service_name = service_name
        self._url = "http://%s:%s/%s" % (self._host, self._port, self._service_name)

    def __getattr__(self, name):
        if name.startswith('__') and name.endswith('__'):
            # Python internal stuff
            raise AttributeError
        if self._service_name is not None:
            name = "%s.%s" % (self._service_name, name)
        return EclairClient(self._host, self._port, self._password, name, self._session )

    def __call__(self, *args, **kwargs):
        return self._session.post(self._url, data=kwargs,auth=('', self._password)).json()
password = "mypassword"
c = EclairClient("localhost", 8080, password)
c.getinfo()
>>> {u'alias': u'blinktrade DEV',
>>>  u'blockHeight': 1583023,
>>> u'chainHash': u'43497fd7f826957108f4a30fd9cec3aeba79972084e90ead01ea330900000000',
>>> u'nodeId': u'038b3f00c4a535238b748f025038dcbb825c4e2a03f08ab1c391f0bfada4b31b45',
>>> u'publicAddresses': []}

c.createinvoice(description="testing", amountMsat=15000)
>>>{u'amount': 15000,
>>> u'description': u'testing',
>>> u'expiry': 3600,
>>> u'nodeId': u'038b3f00c4a535238b748f025038dcbb825c4e2a03f08ab1c391f0bfada4b31b45',
>>> u'paymentHash': u'0eb6ea2dcb36b99a0e7ab3e09bff97c0e32277a5017034cf2e39859de00f4a8e',
>>> u'prefix': u'lntb',
>>> u'serialized': u'lntb150n1pw62a8zpp5p6mw5twtx6ue5rn6k0sfhluhcr3jyaa9q9crfnew8xzemcq0f28qdqvw3jhxarfdensxqrrssdwfxdxrvkdtaetg5k8dz3j42hpupffvdzljsl3nls9faujuxt5e4elu0cnvszg0vhs3m2gw28d4h9c83saxfk0qs4ygwd6yaa5dt8uqpamka3f',
>>> u'timestamp': 1571124450}
1
  • This script provides strange results for sendtoroute command. Given a route, it seems that it tries to route to the first element of the list (i.e. sending node), and the payment gets stuck in pending state. An analogous command in CLI works as expected. What may be the reason? Dec 16, 2019 at 11:49
2

This might not be a satisfying answer but if you look at the eclair git repo and their Wiki you will find that the eclair API is a JSON API and is exposed via http and web sockets and can be queried with regular http requests.

If you look at the c-lightning python client it is a tool that talks via a unixDomainSocket to the exposed lightningd api. So I guess you could in a smilar way quickly create a python wrapper to be able to talk to eclair.

It seems to me that currently no one has bothered to do so.

1
  • 1
    This is a good idea, the wrapper python for eclair should be an good training for my skill with python Sep 18, 2019 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.