GithubHelp home page GithubHelp logo

kowalewskipawel / lnapp-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from moogmodular/lnapp-starter

0.0 0.0 0.0 667 KB

Convenient starter for Lightning Network driven web apps.

Home Page: https://lnapp-starter.up.railway.app

License: MIT License

JavaScript 2.52% TypeScript 97.10% CSS 0.38%

lnapp-starter's Introduction

Next.js - tRPC - LN App starter

Convenient starter for Lightning Network driven web apps. This starter is based on @alexdotjs's tRPC starter project. Since the inception of the lightning network and the development of the ln-url standard, the holy grail of "bank as a web app" is not only a reality but only 5 minutes of set up time and about 30$ of hosting costs away. This starter implements such an app. Authentication and Users are already there, and basic in- and out flow of purchasing power is taken care of. Users can authenticate themselves, deposit and withdraw up to 1000 sats. Basic accounting and inter user tipping has been added so can also tip each other sats. Whatever happens in between is up to the developer. Since the latest update basic nostr interaction has been added so that the website owner gets notified when a new account has been created and individual users can get a message to their nostr public key given that they provided one.

Much of the backend lnd interaction was inspired by open source projects like stacker.news, lightning-poker.com and ln-jukebox

Happy Hacking!

The King

Features

  • ๐ŸŒฝ๏ธ 0nly
  • ๐Ÿง™โ€โ™‚๏ธ E2E typesafety with tRPC
  • ๐Ÿšช Full-stack React with Next.js
  • ๐Ÿซ™ Database with Prisma
  • โšก lnd connection with ln-service/lightning
  • ๐Ÿ’ป webln enabled
  • ๐Ÿ”ญ notifications for website owner and users with the nostr protocol
  • ๐Ÿช™ simple bloatless auth with jsonwebtoken
  • ๐Ÿข state management zustand
  • ๐ŸŒฌ๏ธ easy to use styling with tailwind
  • ๐Ÿ—๏ธ๏ธ UI components with MUI
  • ๐Ÿ”ฎ REST endpoints with trpc-openapi
  • ๐ŸŽญ e2e testing with Playwright
  • ๐Ÿ–Š๏ธ form handling with react-hook-form
  • โœจ๏ธ validation with zod
  • ๐Ÿฆ‹๏ธ formatting with prettier

Setup

yarn:

yarn
yarn dx

Start Development

yarn:

yarn dev -H <YOUR_LOCAL_IP>

Requirements

  • Node >= 14
  • Postgres

Notes

tRPC vs. REST

While tRPC does an amazing job handling the contracts between our Backend and Frontend, ln-url enabled wallets all use REST endpoints. This is why we have exposed some procedures as REST endpoints for ln-url using trpc-openapi which gives us full control on the shape of our responses.

  • auth is exposed as /api/authenticate
  • create withdrawal is exposed as /api/create-withdrawal
  • execute withdrawal is exposed as /api/do-withdrawal

Ln-url QR-codes

There is a DOMAIN=192.168.0.XXX entry in the .env file which is used to generate LN_AUTH_URL=http://${DOMAIN}:3000/api/authenticate. This is used to generate the ln-url QR-codes.

const encoded = encodedUrl(process.env.LN_AUTH_URL ?? 'http://localhost:3000/api/authenticate', 'login', secret)

If you want the wallet on your cell phone to reach the server on your local machine which is connected to your local network, you need to find out your local ip-address. Keep in mind that public keys generated with this method will always be bound to a certain url (in this case http://192.168.0.XXX:3000/api/authenticate or https://myapp.app/api/authenticate).

Hosting

By experience railway.app's setup was the easiest but there is no reason why this shouldnt work on any other Next.js compatible service like Render or Vercel.

e2e tests

In order to run the e2e tests the vars in .jest/setEnvVars.js have to be completed.

Lightning Node

While at first glance it might look attractive to be independent and cool to use a self hosted node like Umbrel i would not recommend making your production LN app dependent on a raspberry pi stored inside your tv cabinet. Also Umbrel is still quite buggy: this bug prevents you from ever connecting from the outside to your node because lnd.conf entries are ignored while generating your tls.cert. Save yourself the trouble. The way with least friction seems to a hosted lnd node on voltage.

Development

Start project

yarn dx

Commands

yarn build      # runs `prisma generate` + `prisma migrate` + `next build`
yarn db-reset   # resets local db
yarn dev        # starts next.js
yarn dx         # starts postgres db + runs migrations + seeds + starts next.js
yarn test-dev   # runs e2e tests on dev
yarn test-start # runs e2e tests on `next start` - build required before
yarn test:unit  # runs normal jest unit tests
yarn test:e2e   # runs e2e tests

Help this project with geyser.fund or [email protected].

zeRealSchlausKwab@stacker.news


Created by @SchlausKwab, zeRealSchlausKwab.

lnapp-starter's People

Contributors

zeschlauskwab avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.