{"id":19001435,"url":"https://github.com/bumi/rack-lightning","last_synced_at":"2025-04-22T17:46:59.473Z","repository":{"id":56890183,"uuid":"155064367","full_name":"bumi/rack-lightning","owner":"bumi","description":"Rack middleware to request lightning payments","archived":false,"fork":false,"pushed_at":"2019-10-27T16:47:04.000Z","size":38,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-29T17:23:18.279Z","etag":null,"topics":["api","bitcoin","lightning-network","micropayments","monetization","payments","rack"],"latest_commit_sha":null,"homepage":"http://michaelbumann.com/post/180389589277/bitcoin-lightning-machine-to-machine-api-payments","language":"Ruby","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/bumi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-28T11:36:19.000Z","updated_at":"2023-04-12T12:00:37.000Z","dependencies_parsed_at":"2022-08-21T00:50:22.690Z","dependency_job_id":null,"html_url":"https://github.com/bumi/rack-lightning","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bumi%2Frack-lightning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bumi%2Frack-lightning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bumi%2Frack-lightning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bumi%2Frack-lightning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bumi","download_url":"https://codeload.github.com/bumi/rack-lightning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249283001,"owners_count":21243656,"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":["api","bitcoin","lightning-network","micropayments","monetization","payments","rack"],"created_at":"2024-11-08T18:11:09.666Z","updated_at":"2025-04-16T22:31:16.569Z","avatar_url":"https://github.com/bumi.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rack::Lightning - micropayments for your rack app\n\n[Rack middleware](https://rack.github.io/) for requesting Bitcoin [Lightning payments](http://lightning.network/) for HTTP request.\n\nStatus: alpha - proof of concept\n\n## How does it work?\n\n1. On the first request a Lightning invoice is created and th `402 Payment Required` HTTP status code is returend \nwith a `application/vnd.lightning.bolt11` content type header and a Lightning invoice as a body.\n2. Once the client has paid the invoice it does a second request providing the proof of payment / the preimage of the Lightning\npayment in a `X-Preimage` header. The middleware checks the if the invoice was paid and continues with the rack app stack\n\n\nHave a look at the [Faraday HTTP client middleware](https://github.com/bumi/faraday_ln_paywall) to automatically handle the \npayment of the requested invoice.\n\n## Requirements\n\nThe middleware uses the gRPC service provided by the [Lightning Network Daemon(lnd)](https://github.com/lightningnetwork/lnd/).\nA running node with is required which is used to generate and validate invoices.\n\nDetails about lnd can be found on their [github page](https://github.com/lightningnetwork/lnd/)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'rack-lightning'\n```\n\n## Usage\n\nSimply add the `Rack::Lightning` middleware:\n\n```ruby\nrequire \"rack/lightning\"\n\nExample = Rack::Builder.new {\n  use Rack::Lightning, { price: 100 } \n  run Proc.new { |env| ['200', {'Content-Type' =\u003e 'text/html'}, ['get rack\\'d']] }\n}.to_app\n```\n\n## Configuration \n\nThe middleware accepts the following configuration options: \n\n* `price`: the price in satoshi (default: 100)\n* `address`: the address of the lnd gRPC service( default: localhost:10009)\n* `credentials_path`: path to the tls.cert (default: ~/.lnd/tls.cert)\n* `macaroon_path`: path to the macaroon path (default: ~/.lnd/data/chain/bitcoin/testnet/admin.macaroon)\n* `credentials`: instead of configuring a `credentials_path` you can pass the content of the tls.cert directly\n* `macaroon`: instead of configuring a `macaroon_path` you can pass the hex content of the macaroon directly\n\n### How to pass credentials or macaroon data from a variable like a environment varibale?\n\nThe tls.cert and the macaroon config can be loaded from a variable:\n\n```ruby\nENV['LND_CREDENTIALS'] = \"the content of your tls.cert file\"\nENV['LND_MACAROON'] = \"the hex encoded content of your macaroon file\"\n# you can get the macaroon content like this: xxd -p -c2000 admin.macaroon\n# or ::File.read(::File.expand_path(\"/path/to/admin.macaroon\")).each_byte.map { |b| b.to_s(16).rjust(2,'0') }.join\n\nExample = Rack::Builder.new {\n  use Rack::Lightning, { macaroon: ENV['LND_MACAROON'], credentials: ENV['LND_CREDENTIALS'] } \n  run Proc.new { |env| ['200', {'Content-Type' =\u003e 'text/html'}, ['get rack\\'d']] }\n}.to_app\n```\n\n\n## What is the Lightning Network?\n\nThe [Lightning Network](https://en.wikipedia.org/wiki/Lightning_Network) allows to send real near-instant microtransactions with extremely low fees. \nIt is a second layer on top of the Bitcoin network (and other crypto currencies). \nThanks to this properties it can be used to monetize APIs. \n\n## Similar projects\n\n* [philippgille/ln-paywall](https://github.com/philippgille/ln-paywall) - middleware for Go frameworks. looks great and very well designed!\n* [ElementsProject/paypercall](https://github.com/ElementsProject/paypercall) - express.js middelware for node.js applications\n\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/bumi/rack-lightning.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbumi%2Frack-lightning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbumi%2Frack-lightning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbumi%2Frack-lightning/lists"}