Start writing Core Lightning plugins with pyln-client TODAY!

LNROOM #10April 21, 2023

In this episode, we register a JSON-RPC method in Core Lightning using pyln-client Python package.

Transcript with corrections and improvements

Note that in this video we have 2 nodes running on regtest and we communicate with to node l1 with the following alias:

◉ tony@tony:~/clnlive:
$ alias l1-cli
alias l1-cli='lightning-cli --lightning-dir=/tmp/l1-regtest'

To get more information you can refer to this biweekly live coding session where the material of this video comes from.

Source code

#!/usr/bin/env python

from pyln.client import Plugin

plugin = Plugin()

@plugin.method("myplugin")
def myplugin_func(plugin,foo1="foo1", foo2="foo2"):
    node_id = plugin.rpc.getinfo()["id"]
    foo_opt = plugin.get_option("foo_opt")
    return {
        "node_id": node_id,
        "options": {
            "foo_opt": foo_opt
        },
        "cli_params": {
            "foo1": foo1,
            "foo2": foo2
        }
    }

plugin.add_option(name="foo_opt",
                  default="bar",
                  description="'foo_opt description")

plugin.run()