Play chess on the Lightning Network.
This project allows you to play chess against others and win satoshis. Early on in the days of Lightning there were some projects that built a chess app on LN, (some discussions can be found here and here), but since those projects don't seem to exist anymore, I decided to build this prototype.
I took heavy inspiration from the Lightning Labs sample LAPP. The demo can be tested locally by using Polar.
Here's how you can connect your node to the app. In this demo, I'm using Polar:
lightning-chess-connect-demo.mov
Once 2 players have connected, start a game by sharing a URL (just like playing with a friend in Lichess). Once both players have paid 1000 satoshis, the game begins. The winner will get paid back 2000 satoshis when the game is over.
lightning-chess-demo.mov
To run it locally, pull the repo and install Polar (follow instructions here). Also make sure that you have Go >1.19.
- Create a network like in the Lightning Labs tutorial. You can also import the
lightning-chess-simnet.polar.zip
simnet. - Create a
.env
file inbackend/
and include theLND_HOST
,LND_CERT
, andLND_MACAROON
(admin macaroon) from one of the nodes in the simnet. This node will belong to the backend. - Install dependencies:
$ cd backend
$ go get .
$ cd ../client
$ npm install
To run the backend, run:
$ cd backend
$ air
And to run the client, in a seperate terminal window, run:
$ cd client
$ npm run start
- Each user connects their node using the Host, TLS Certificate, and Macaroon.
- To begin a game, both players have to pay 1000 satoshis. On the backend, the backend LND node is creating invoices, and sending each client their respective Payment Request.
- On the backend, we are subscribed to any invoice activity on our node. Once those invoices are settled by the users, the game can begin.
- The game is played until one of the players wins. Once they do, we generate an invoice for 2000 satoshis on their behalf, and pay it from our backend node.
This is a simple prototype. Some next steps include:
- Making the chess interface much better (move history, timed games, chat, pre-moves, etc...)
- Add proper persistance and clean up the code
- Detecting different game outcomes. In the event of a draw, both players should get their sats back.
- Using HODL invoices and an escrow in order to minimize the trust in the third-party. Here are some resources:
- https://lists.linuxfoundation.org/pipermail/lightning-dev/2016-January/000403.html
- https://www.reddit.com/r/lightningnetwork/comments/pgkkrq/are_escrow_payments_feasible_with_the_ln/
- https://stacker.news/items/7340
- https://suredbits.com/payment-points-part-3-escrow-contracts/
- https://lists.linuxfoundation.org/pipermail/lightning-dev/2019-June/002051.html
- https://github.com/supertestnet/hodlcontracts
- Launch it!