Skip to content

RRustom/lightning-chess

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

lightning-chess

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.

Demo

Here's how you can connect your node to the app. In this demo, I'm using Polar:

lightning-chess-connect-demo.mov

YouTube

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

YouTube

Getting Started

To run it locally, pull the repo and install Polar (follow instructions here). Also make sure that you have Go >1.19.

  1. Create a network like in the Lightning Labs tutorial. You can also import the lightning-chess-simnet.polar.zip simnet.
  2. Create a .env file in backend/ and include the LND_HOST, LND_CERT, and LND_MACAROON (admin macaroon) from one of the nodes in the simnet. This node will belong to the backend.
  3. 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

How it works

  1. Each user connects their node using the Host, TLS Certificate, and Macaroon.
  2. 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.
  3. 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.
  4. 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.

Next steps

This is a simple prototype. Some next steps include:

  1. Making the chess interface much better (move history, timed games, chat, pre-moves, etc...)
  2. Add proper persistance and clean up the code
  3. Detecting different game outcomes. In the event of a draw, both players should get their sats back.
  4. Using HODL invoices and an escrow in order to minimize the trust in the third-party. Here are some resources:
  5. Launch it!

Resources

About

Play chess on the Lightning Network

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published