Decentralized Poker
Play a game of poker with friends. The full deployment works 100% decentralized, with no server, all code on-chain, and game logic managed p2p.
Created on 1st July 2024
•
Decentralized Poker
Play a game of poker with friends. The full deployment works 100% decentralized, with no server, all code on-chain, and game logic managed p2p.
The problem Decentralized Poker solves
Decentralized poker is a working proof-of-concept that it's possible to increasingly develop complex, multiplayer applications that don't rely on any servers at all:
- The game creation / player matching code is in a smart contract
- The front-end UI is stored on-chain and can be viewed via a web3url-compatible browser, add-on, or routing website
- The game logic is managed by the "dealer" player
- The p2p communications is managed through XMTP, a project that aims to decentralized p2p comms
This shows that it is possible to create complex decentralized applications. There are improvements that can take this further:
- In the case of poker, a full application of the "mental poker" algorithm would mean that the dealer would not have any secret information, so players could bet money via the smart contract in the game of poker - creating the first 100% decentralized casino game
- The p2p communications could also be distributed further, potentially 100% so, if connection details were shared between players so that players could connect directly 1-1 with each other via WebRTC
Taking all of the above to the furthest extent, it's possible that with a combination of smart contracts (which can perform decision-making logic for games that does not require secrets, including multiplayer game creation), and clever game logic management using cryptographic techniques, that increasingly complex games could be entirely decentralized, allowing for new types of games to emerge.
From varying combinations of the above pieces, and proper cryptography, it's possible to create verifiable tabletop games like Battleship, Checkers, Chess, Poker, Blackjack, and more, all of which could be played with verifiable results, and result in player betting / payouts on-chain.
Challenges I ran into
The largest hurdle was the mental poker algorithm. My original intention was to include the mental poker code, but due to time constraints and difficulty of implementation, that was left out. When added, the game becomes trustless and verifiable, which allows for features like actual betting to be implemented.
The other hurdle has to do with implementing XMTP multi-user chat (which isn't a feature of the client-side code for XMTP - the game above does integrate multi-user chat, but it does so using workarounds to broadcast messages to all players, and using keys to identify which chat the message should be displayed in).
In particular, XMTP connections for multiple users require hacky workarounds in React that cause re-render bugs. I would likely re-write the code to not use React library, and instead use the XMTP JS library directly, and either find a way to work that into React, or replace React with a vanilla implementation or a different framework.
Tracks Applied (2)
OnchainKit
Gaming Track
GAMING with thirdweb
Technologies used
Cheer Project
Cheering for a project means supporting a project you like with as little as 0.0025 ETH. Right now, you can Cheer using ETH on Arbitrum, Optimism and Base.
