{"id":19001484,"url":"https://github.com/bumi/ln-markdown-to-pdf","last_synced_at":"2026-03-08T02:05:40.545Z","repository":{"id":66382332,"uuid":"158622420","full_name":"bumi/ln-markdown-to-pdf","owner":"bumi","description":"An example for machine to machine payments using the bitcoin lightning network","archived":false,"fork":false,"pushed_at":"2019-01-14T10:15:23.000Z","size":26,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-29T17:23:20.799Z","etag":null,"topics":["api","bitcoin","lightning","lightning-network","machine-to-machine","micropayments","rack","ruby"],"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":null,"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":null,"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":"2018-11-22T00:40:55.000Z","updated_at":"2023-05-01T08:54:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"a0205ea6-2477-4b30-ac3c-7add3ff5d4d5","html_url":"https://github.com/bumi/ln-markdown-to-pdf","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bumi%2Fln-markdown-to-pdf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bumi%2Fln-markdown-to-pdf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bumi%2Fln-markdown-to-pdf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bumi%2Fln-markdown-to-pdf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bumi","download_url":"https://codeload.github.com/bumi/ln-markdown-to-pdf/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","lightning-network","machine-to-machine","micropayments","rack","ruby"],"created_at":"2024-11-08T18:11:22.023Z","updated_at":"2026-03-08T02:05:35.517Z","avatar_url":"https://github.com/bumi.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Markdown to html/pdf \n\n## This is a demo for machine to machine bitcoin [lightning payments](https://en.wikipedia.org/wiki/Lightning_Network)\n\nThis app exposes HTTP endpoints to convert markdown files to HTML or PDF after the client paid a lightning invoice.\n\nThis is a simple [Sinatra.rb app](http://sinatrarb.com/) that uses the [rack-lightning middleware](https://github.com/bumi/rack-lightning) to handle lightning invoices.\n\n\n### Video Demo\n\nI've made a [video](https://vimeo.com/302338717) giving an overview of the setup and showing how it works: [https://vimeo.com/302338717](https://vimeo.com/302338717)\n\n\n## How does it work? \n\n1. If no proof of payment is provided the rack lightning middleware creates a Lightning invoice and returns a `402 Payment Required` HTTP status code with a `application/vnd.lightning.bolt11` content type header and a Lightning invoice as a body. \n2. The client pays the invoice and does a second request providing the proof of payment / the preimage of the Lightning\npayment in a `X-Preimage` header. \n3. Now the lightning middleware checks the if the invoice was paid and proceeds to the sinatra app doing the convertion.\n\nHave a look at the server code: \n\n* [config.ru](https://github.com/bumi/ln-markdown-to-pdf/blob/master/config.ru#L9) - where the magic happens: loading the lightning middleware\n* [converter.rb](https://github.com/bumi/ln-markdown-to-pdf/blob/master/converter.rb) - the actual sinatra app (no lightning related code in here; all handled by the middleware)\n\nUsage details about the [rack lightning middleware can be found here](https://github.com/bumi/rack-lightning)\n\n### Requirements\n\nServer and client are using connecting (gRPC) to the [Lightning Network Daemon(lnd)](https://github.com/lightningnetwork/lnd/) to create and pay invoices..\nA running node with funded channels is required. Details about lnd can be found on their [github page](https://github.com/lightningnetwork/lnd/)\n\n\n## API endpoints\n\nThe application is deployed on [https://lightning-2pdf.herokuapp.com](https://lightning-2pdf.herokuapp.com) and connected\nto the [lightning node on 79.137.71.183](https://1ml.com/testnet/node/038474ec195f497cf4036e5994bd820dd365bb0aaa7fb42bd9b536913a1a2dcc9e)\n\nThe following endpoints are available:\n\n### POST /convert/pdf\n\nconverts markdown in the request body to PDF and returns the PDF file content\n\n### POST /convert/html\n\nconverts the markdown in the request body to HTML and returns the html file content\n\n\n## Client\n\n**requirements:** you need a running lnd node with funded, open channels. Check the [lnd github page](https://github.com/lightningnetwork/lnd/#readme) for information about lnd.\n\nThe API client uses the [faraday HTTP library](https://github.com/lostisland/faraday) and the [faraday_ln_paywall middleware](https://github.com/bumi/faraday_ln_paywall) to automatically pay the lightning invoice for every request.\n\nHave a look at the [code in client.rb](https://github.com/bumi/ln-markdown-to-pdf/blob/master/client.rb) and have a look at the [faraday lightning middleware](https://github.com/bumi/faraday_ln_paywall#readme)\n\n### Usage:\n\n    $ ruby client.rb [path to markdown file] [format]\n    $\n    $ # example:\n    $ ruby client.rb ./README.md html\n\nThe client is using default lnd settings and loads `~/.lnd/data/chain/bitcoin/testnet/admin.macaroon` and `~/.lnd/tls.cert`\nYou can configure that in the [faraday middleware](https://github.com/bumi/ln-markdown-to-pdf/blob/master/client.rb#L7). ([documentation](https://github.com/bumi/faraday_ln_paywall#configuration))\n\n## Questions?\n\nPlease let me know if you have any questions and I'd love to hear feedback and your ideas on this: hello@michaelbumann.com   \nmore contact details on my website: [michaelbumann.com](http://michaelbumann.com)\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 easily used for automated machine to machine payments.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbumi%2Fln-markdown-to-pdf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbumi%2Fln-markdown-to-pdf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbumi%2Fln-markdown-to-pdf/lists"}