{"id":13499354,"url":"https://github.com/fiatjaf/lightningd-gjson-rpc","last_synced_at":"2025-04-07T12:09:43.814Z","repository":{"id":57494923,"uuid":"165879214","full_name":"fiatjaf/lightningd-gjson-rpc","owner":"fiatjaf","description":"Talk with a lightningd/c-lightning with minimal overhead and gjson responses.","archived":false,"fork":false,"pushed_at":"2024-11-13T23:47:16.000Z","size":2451,"stargazers_count":46,"open_issues_count":1,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-03-31T11:03:33.764Z","etag":null,"topics":["c-lightning","json-rpc-client","lightning-network","lightningd"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fiatjaf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-15T15:52:01.000Z","updated_at":"2024-11-13T23:47:21.000Z","dependencies_parsed_at":"2024-01-14T03:51:16.757Z","dependency_job_id":"ebfe6d94-d1d3-4771-b7dc-cd698e2f5256","html_url":"https://github.com/fiatjaf/lightningd-gjson-rpc","commit_stats":{"total_commits":178,"total_committers":7,"mean_commits":"25.428571428571427","dds":0.4213483146067416,"last_synced_commit":"b9505ba1a6651255af0115b78bad877493ceaf13"},"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiatjaf%2Flightningd-gjson-rpc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiatjaf%2Flightningd-gjson-rpc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiatjaf%2Flightningd-gjson-rpc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fiatjaf%2Flightningd-gjson-rpc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fiatjaf","download_url":"https://codeload.github.com/fiatjaf/lightningd-gjson-rpc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247648977,"owners_count":20972945,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-lightning","json-rpc-client","lightning-network","lightningd"],"created_at":"2024-07-31T22:00:32.419Z","updated_at":"2025-04-07T12:09:43.774Z","avatar_url":"https://github.com/fiatjaf.png","language":"Go","funding_links":[],"categories":["Developer Resources"],"sub_categories":["Libraries"],"readme":"Useful and fast interface for [lightningd](https://github.com/ElementsProject/lightning/). All methods return [`gjson.Result`](https://godoc.org/github.com/tidwall/gjson#Result), which is a good thing and very fast. [Try the GJSON playground to learn](https://gjson.dev/).\n\nSince RPC calls are just relayed and wrapped, you can use **lightningd-gjson-rpc** to call [custom RPC methods](https://lightning.readthedocs.io/PLUGINS.html) if your node has a plugin enabled on it.\n\n[![godoc.org](https://img.shields.io/badge/reference-godoc-blue.svg)](https://godoc.org/github.com/fiatjaf/lightningd-gjson-rpc)\n\nThis is a simple and resistant client. It is made to survive against faulty **lightning** node interruptions. It can also talk to [spark](https://github.com/shesek/spark-wallet)/[sparko](https://github.com/fiatjaf/lightningd-gjson-rpc/tree/master/cmd/sparko#client-libraries) HTTP-RPC using the same API, so you can run your app and your node on different machines.\n\n## Usage\n\n```go\npackage main\n\nimport (\n  \"github.com/fiatjaf/lightningd-gjson-rpc\"\n  \"github.com/tidwall/gjson\"\n)\n\nvar ln *lightning.Client\n\nfunc main () {\n    lastinvoiceindex := getFromSomewhereOrStartAtZero()\n\n    ln = \u0026lightning.Client{\n        Path:             \"/home/whatever/.lightning/lightning-rpc\",\n        LastInvoiceIndex: lastinvoiceindex, // only needed if you're going to listen for invoices\n        PaymentHandler:   handleInvoicePaid, // only needed if you're going to listen for invoices\n        CallTimeout: 10 * time.Second, // optional, defaults to 5 seconds\n    }\n    ln.ListenForInvoices() // optional\n\n    nodeinfo, err := ln.Call(\"getinfo\")\n    if err != nil {\n        log.Fatal(\"getinfo error: \" + err.Error())\n    }\n\n    log.Print(nodeinfo.Get(\"alias\").String())\n}\n\n// this is called with the result of `waitanyinvoice`\nfunc handlePaymentReceived(inv gjson.Result) {\n    index := inv.Get(\"pay_index\").Int()\n    saveSomewhere(index)\n\n    hash := inv.Get(\"payment_hash\").String()\n    log.Print(\"one of our invoices was paid: \" + hash)\n}\n```\n\n### Passing parameters\n\nThere are three modes of passing parameters, you can call either:\n\n```go\n// 1. `Call` with a list of parameters, in the order defined by each command;\nln.Call(\"invoice\", 1000000, \"my-label\", \"my description\", 3600)\n\n// 2. `Call` with a single `map[string]interface{}` with all parameters properly named; or\nln.Call(\"invoice\", map[string]interface{\n    \"msatoshi\": \"1000000,\n    \"label\": \"my-label\",\n    \"description\": \"my description\",\n    \"preimage\": \"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f\"\n})\n\n// 3. `CallNamed` with a list of keys and values passed in the proper order.\nln.CallNamed(\"invoice\",\n    \"msatoshi\", \"1000000,\n    \"label\", \"my-label\",\n    \"description\", \"my description\",\n    \"preimage\", \"000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f\",\n    \"expiry\", 3600,\n)\n```\n\n## Special methods\n\nBesides providing full access to the c-lightning RPC interface with `.Call` methods, we also have [ListenForInvoices](https://godoc.org/github.com/fiatjaf/lightningd-gjson-rpc#Client.ListenForInvoices), [PayAndWaitUntilResolution](https://godoc.org/github.com/fiatjaf/lightningd-gjson-rpc#Client.PayAndWaitUntilResolution) and [GetPrivateKey](https://godoc.org/github.com/fiatjaf/lightningd-gjson-rpc#Client.GetPrivateKey) to make your life better.\n\nIt's good to say also that since we don't have hardcoded methods here you can call [custom RPC methods](https://lightning.readthedocs.io/PLUGINS.html#json-rpc-passthrough) with this library.\n\n## Plugins\n\nIf you want to write a plugin, we provide [helpers](plugin) to make that easy. Take a look at https://github.com/fiatjaf/sparko or https://github.com/fiatjaf/lightningd-webhook for examples.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiatjaf%2Flightningd-gjson-rpc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffiatjaf%2Flightningd-gjson-rpc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffiatjaf%2Flightningd-gjson-rpc/lists"}