TypeScript SDK for Block52 Poker VM
npm install @block52/poker-vm-sdk

TypeScript SDK for Block52 Poker VM - A blockchain-based poker platform built on Cosmos.
- š® Complete Poker Game Logic - Card dealing, hand evaluation, and game state management
- š Cosmos Blockchain Integration - Transaction signing, querying, and wallet management
- š² Deck Management - Shuffle, deal, and track card states with blockchain-verified randomness
- š¤ Type-Safe - Full TypeScript support with generated types from protobuf definitions
- š Real-time Updates - WebSocket support for live game state synchronization
- š° Token Operations - Built-in USDC token handling and conversions
``bash`
npm install @block52/poker-vm-sdk
or with yarn:
`bash`
yarn add @block52/poker-vm-sdk
`typescript
import { createSigningClientFromMnemonic, getDefaultCosmosConfig } from '@block52/poker-vm-sdk';
// Connect to the blockchain
const config = getDefaultCosmosConfig("mainnet"); // or "testnet", "localhost"
const mnemonic = "your twelve word mnemonic phrase here...";
const client = await createSigningClientFromMnemonic(config, mnemonic);
const walletAddress = await client.getWalletAddress();
console.log("Wallet Address:", walletAddress);
`
`typescript
// Define game parameters
const gameParams = {
gameFormat: "cash", // or "tournament"
gameVariant: "texas-holdem",
minPlayers: 2,
maxPlayers: 6,
minBuyIn: client.usdcToB52usdc(10), // 10 USDC minimum
maxBuyIn: client.usdcToB52usdc(100), // 100 USDC maximum
smallBlind: client.usdcToB52usdc(0.5), // 0.5 USDC small blind
bigBlind: client.usdcToB52usdc(1), // 1 USDC big blind
timeout: 60 // 60 seconds per action
};
// Create the game on-chain
const txHash = await client.createGame(
gameParams.gameFormat,
gameParams.gameVariant,
gameParams.minPlayers,
gameParams.maxPlayers,
gameParams.minBuyIn,
gameParams.maxBuyIn,
gameParams.smallBlind,
gameParams.bigBlind,
gameParams.timeout
);
console.log("Game created! Transaction:", txHash);
`
`typescript
import { Deck, PokerSolver } from '@block52/poker-vm-sdk';
// Create and shuffle a deck
const deck = new Deck();
deck.shuffle([1, 2, 3, 4, 5]); // Seed for deterministic shuffle
// Deal cards
const playerHand = deck.deal(2); // Deal 2 cards to player
const communityCards = deck.deal(5); // Deal 5 community cards
// Evaluate hand strength
const allCards = [...playerHand, ...communityCards];
const evaluation = PokerSolver.evaluateSevenCardHand(allCards);
console.log("Hand type:", evaluation.type);
console.log("Hand rank:", evaluation.rank);
// Compare two hands
const player1Evaluation = PokerSolver.evaluateSevenCardHand(player1Cards);
const player2Evaluation = PokerSolver.evaluateSevenCardHand(player2Cards);
const result = PokerSolver.compareHands(player1Evaluation, player2Evaluation);
// result > 0: player1 wins, < 0: player2 wins, 0: tie
`
`typescript
import { CosmosClient, getDefaultCosmosConfig } from '@block52/poker-vm-sdk';
// Create a query-only client (no signing required)
const config = getDefaultCosmosConfig("mainnet");
const queryClient = new CosmosClient(config);
// Query a game by ID
const game = await queryClient.getGame(gameId);
console.log("Game options:", game);
// Get game state
const gameState = await queryClient.getGameState(gameId);
console.log("Game state:", gameState);
// List all games
const allGames = await queryClient.listGames();
console.log("Active games:", allGames.length);
// Get games for a specific player
const playerGames = await queryClient.getPlayerGames(playerAddress);
console.log("Player games:", playerGames.length);
`
`typescript
// Convert between USDC and b52usdc (blockchain representation)
const usdcAmount = 100; // 100 USDC
const b52usdcAmount = client.usdcToB52usdc(usdcAmount);
// Convert back
const usdcValue = client.b52usdcToUsdc(b52usdcAmount);
// Check balance
const balance = await client.getB52USDCBalance(walletAddress);
console.log("Balance:", client.b52usdcToUsdc(balance), "USDC");
`
The main client for interacting with the poker blockchain with signing capabilities.
#### Methods
- createGame(gameFormat, gameVariant, minPlayers, maxPlayers, minBuyIn, maxBuyIn, smallBlind, bigBlind, timeout, rakeConfig?, sngConfig?) - Create a new poker gamejoinGame(gameId, seat, buyInAmount)
- - Join an existing game at a specific seatperformAction(gameId, action, amount?, data?)
- - Perform a poker action (fold, call, raise, check)leaveGame(gameId)
- - Leave a game and cash outgetWalletAddress()
- - Get the current wallet addressgetB52USDCBalance(address)
- - Get USDC balance for an addressgetTx(hash)
- - Get transaction details by hashdisconnect()
- - Close the client connection
Query-only client for reading blockchain state.
#### Methods
- getGame(gameId) - Get game options/configuration by IDgetGameState(gameId)
- - Get current game state by IDlistGames()
- - Get all gamesfindGames(min?, max?)
- - Find games by blind rangegetPlayerGames(playerAddress)
- - Get games for a specific playergetLegalActions(gameId, playerAddress?)
- - Get legal actions for a gamegetBalance(address, denom?)
- - Query token balancegetAllBalances(address)
- - Get all token balancesgetAccount(address)
- - Get account informationgetHeight()
- - Get current block heightgetTx(txHash)
- - Get transaction by hash
Card deck management with blockchain integration.
#### Methods
- constructor(deck?: string) - Create deck from mnemonic string or new ordered deckgetNext()
- - Draw next carddeal(amount)
- - Deal multiple cardstoString()
- - Serialize deck to stringshuffle(seed)
- - Shuffle deck (testing only, production uses blockchain randomness)
#### Constants
- Deck.DECK_SIZE - Number of cards in a standard deck (52)Deck.RANK_MAP
- - Map of rank values to strings (A, T, J, Q, K)Deck.SUIT_MAP
- - Map of suit values to strings (C, D, H, S)
Hand evaluation and poker logic.
#### Static Methods
- evaluatePartialHand(cards) - Evaluate poker hand strength (partial or complete hand)evaluateSevenCardHand(cards)
- - Evaluate best 5-card hand from 7 cardscompareHands(hand1, hand2)
- - Compare two hands to determine winner
Utilities for wallet management.
- generateWallet(prefix?, wordCount?) - Generate a new wallet with random mnemonic (12 or 24 words)createWalletFromMnemonic(mnemonic, prefix?)
- - Create wallet from existing mnemonicgetAddressFromMnemonic(mnemonic, prefix?)
- - Derive address from mnemonicisValidMnemonic(mnemonic)
- - Validate mnemonic phraseBLOCK52_HD_PATH
- - Standard Cosmos HD derivation path for Block52
`typescript
import { getDefaultCosmosConfig } from '@block52/poker-vm-sdk';
// Mainnet
const mainnetConfig = getDefaultCosmosConfig("mainnet");
// Testnet
const testnetConfig = getDefaultCosmosConfig("testnet");
// Local development
const localConfig = getDefaultCosmosConfig("localhost");
// Custom configuration
const customConfig = {
rpcEndpoint: "https://your-node.example.com:26657",
restEndpoint: "https://your-node.example.com:1317",
chainId: "pokerchain-1",
prefix: "poker"
};
`
Check out the examples directory for complete working examples:
- create-game-example.ts - Complete example of creating a poker game
- wallet-example.ts - Wallet creation and management
To run the examples:
`bash`
git clone https://github.com/block52/poker-vm.git
cd poker-vm/sdk
yarn install
yarn build
npx ts-node examples/create-game-example.ts
`bashClone the repository
git clone https://github.com/block52/poker-vm.git
cd poker-vm/sdk
$3
`
sdk/
āāā src/
ā āāā index.ts # Main entry point
ā āāā client.ts # Base client implementation
ā āāā cosmosClient.ts # Query client
ā āāā signingClient.ts # Signing client
ā āāā deck.ts # Deck class
ā āāā pokerSolver.ts # Hand evaluation
ā āāā walletUtils.ts # Wallet utilities
ā āāā types/ # TypeScript type definitions
ā āāā utils/ # Utility functions
ā āāā pokerchain.poker.v1/ # Generated protobuf types
āāā examples/ # Usage examples
āāā tests/ # Test files
āāā dist/ # Built output (after yarn build)
`TypeScript Support
This SDK is written in TypeScript and includes full type definitions. No additional
@types packages are needed.`typescript
import type { GameStateResponseDTO, PlayerDTO, ActionDTO } from '@block52/poker-vm-sdk';
`$3
The SDK defines the single source of truth for all game types:
-
GameStateResponseDTO - Root type for game data over the wire
- TexasHoldemStateDTO - Game state (contains players, communityCards, etc.)
- GameOptionsDTO - Game configuration (NO format or owner - use root fields)
- PlayerDTO - Player informationSee CLAUDE.md for complete type rules.
Browser Support
The SDK works in both Node.js and browser environments. For browser usage, you may need to configure polyfills for Node.js built-ins:
`javascript
// Example webpack config
module.exports = {
resolve: {
fallback: {
"stream": require.resolve("stream-browserify"),
"crypto": require.resolve("crypto-browserify"),
"buffer": require.resolve("buffer/")
}
}
};
``Contributions are welcome! Please see the main repository for contribution guidelines.
MIT License - see LICENSE file for details.
- š Documentation: CLAUDE.md - Detailed SDK documentation
- š Issues: GitHub Issues
- š¬ Discussions: GitHub Discussions
- š Website: Block52
- Poker VM - Main repository
- Poker UI - Web-based poker client
- Poker Bot - AI poker bot
See Releases for version history and changes.