OneCard Poker leverages the TEN Network's Trusted Execution Environment (TEE) technology to provide a truly private and fair poker experience on the blockchain.
The TEN Network offers unique capabilities that make this poker game possible:
-
Encrypted Private States: Player cards and game data are stored in TEE-encrypted states, ensuring only authorized parties can access sensitive information.
-
Secure Random Number Generation: Card shuffling and dealing utilize TEN's secure RNG, which is tamper-proof and verifiably fair.
-
Selective Information Disclosure: Card information is only revealed to the appropriate players through TEN's privacy-preserving event system.
-
Tamper-Proof Game Logic: All game rules are enforced within the TEE, preventing manipulation or cheating.
The codebase is organized into multiple contracts for modularity and gas efficiency:
- PokerCardLibrary.sol: Card representations and deck operations
- PokerGameLibrary.sol: Game state definitions and bitmap operations
- OneCard.sol: Core game contract with gameplay functionality
- SpectatorBetting.sol (AI version only): Enhanced functionality for spectators
OneCard Poker is a simplified poker variant where:
- Each player receives a single card
- Players can pay to peek at their card
- After peeking, players can optionally pay to swap their card
- Players place bets or fold during the betting round
- The highest card wins the pot
- At game end, all players' cards are publicly revealed
When deploying to the TEN Network:
- Deploy
PokerCardLibrary.solfirst - Deploy
PokerGameLibrary.sol - Deploy
OneCard.sol - Start the keeper service to manage game phase transitions
The keeper service is responsible for:
- Monitoring game events and managing phase transitions
- Ending the peek phase after the time limit expires
- Ending the betting phase and initiating showdown
- Cleaning up completed games
Players interact with the OneCard contract through these key functions:
createGame()- Create a new gamejoinGame(gameId)- Join an existing gamepeekAtCard(gameId)- Pay to peek at your cardswapCard(gameId)- Pay to swap your cardplaceBet(gameId, betAmount)- Place your betfold(gameId)- Fold your hand
- Game state events:
GameCreated,PeekPhaseStarted,BettingPhaseStarted, etc. - Card events:
CardPeeked(private),CardRevealed(public) - Player action events:
PlayerAction(private)
The contract emits two types of card events:
- CardPeeked: Private to the player who peeked (indexed by player address)
- CardRevealed: Public event revealing cards at game end (visible to everyone)
The frontend should:
- Listen for
CardPeekedevents to show the player their own card - Listen for
CardRevealedevents to show all cards at game end - Call
getRevealedCards()to get all cards when the game is in SHOWDOWN or ENDED state