@block52/poker-vm-sdk

中文文档
1.24.0发布于 2026/11/05MITTypeScriptESM + CJS近 30 天下载 3038

Block52 扑克VM 的脚本 SDK

中文使用文档
文档目录29 节
  1. 特征
  2. 安装
  3. 快速启动
  4. 创建签名客户端
  5. 创建扑克游戏
  6. 与牌和德克牌合作
  7. 查询游戏状态
  8. 调试操作
  9. API 参考
  10. 签名空间
  11. 宇宙线
  12. 地标
  13. 扑克索尔
  14. 钱包公用事业
  15. 配置
  16. 网络终点
  17. 实例
  18. 发展
  19. 来源建筑
  20. 发布到 npm
  21. 项目结构
  22. 类型脚本支持
  23. 光圈类型
  24. 浏览器支持
  25. 捐款
  26. 许可证
  27. 支助
  28. 相关项目
  29. 更改日志

@ block52/ poker-vm- sdk (英语)

npm version SDK Tests License: MIT

TypeScript SDK for Block52 Poker VM - 一个以Cosmos为主的以块链为主的扑克平台.

特征

  • 🎮 完成扑克游戏逻辑 - 卡片交易、手评价、游戏状态管理
  • 🔐 Cosmos 区块链集成 - 交易签名、查询和钱包管理
  • 🎲 舱面管理 - 摇摆、交易和追踪卡状态 以区块链验证随机性
  • 🤝 类型安全 - 完整类型脚本支持,并用原生生物定义生成的类型
  • 🔄 实时更新 - 对游戏状态同步的WebSocket支持
  • 💰 调试操作 - 安装在USDC信号处理和转换中

安装

npm install @block52/poker-vm-sdk

或带线:

yarn add @block52/poker-vm-sdk

快速启动

创建签名客户端

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);

创建扑克游戏

// 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);

与牌和德克牌合作

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

查询游戏状态

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);

调试操作

// 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");

API 参考

签名空间

扩展 CosmosClient 具有交易签名能力。 包括所有查询方法 CosmosClient 加:

交易方法

  • createGame(gameFormat, gameVariant, minPlayers, maxPlayers, minBuyIn, maxBuyIn, smallBlind, bigBlind, timeout, rakeConfig?, sngConfig?) - 创建新的扑克游戏
  • joinGame(gameId, seat, buyInAmount) - 在一个特定位置加入已有的游戏
  • leaveGame(gameId) - 留下游戏和现金
  • performAction(gameId, action, amount?, data?) - 实施扑克动作(倍数、呼叫、提升、检查、全入、交易)
  • topUp(gameId, amount) - 将芯片添加到桌子上
  • sendTokens(fromAddress, toAddress, amount, denom?, memo?) - 向另一个地址发送签名
  • sendB52USDC(fromAddress, toAddress, amount, memo?) - 发送b52USDC令牌

桥梁方法

  • processDeposit(depositIndex) - 按指数处理伊特鲁姆的桥梁存款
  • initiateWithdrawal(baseAddress, amount) - 开始撤回基地
  • getWithdrawalRequest(nonce) - 询问非ce提出的具体退出请求
  • listWithdrawalRequests(cosmosAddress?) - 除名请求

钱包方法

  • getWalletAddress() - 获取当前钱包地址
  • setWallet(wallet) - 为签名设置一个新的钱包
  • getWallet() - 获取当前钱包实例
  • disconnect() - 关闭客户端连接

宇宙线

通过 REST API 读取块链状态的查询客户端 .

块链查询方法

  • getAccount(address) - 获取账户信息
  • getAllBalances(address) - 获得所有象征性余额的地址
  • getBalance(address, denom?) - 获得具体符号余额(默认:b52USDC)
  • getHeight() - 获取当前块高
  • getTx(txHash) -通过散列交易
  • getBlock(height) - 按高度逐个街区
  • getLatestBlock() - 获取最新块
  • getBlocks(startHeight, count?) - 从高处开始多块块
  • getLatestBlocks(count?) - 获取最新的N区块

游戏查询方法

  • getGame(gameId) - 通过ID获取游戏选项/配置
  • getGameState(gameId) - 通过 ID 获取当前游戏状态
  • listGames() - 获得所有活跃的游戏
  • findGames(min?, max?) - 按玩家容量查找游戏(minPlayers/maxPlayers)
  • getPlayerGames(playerAddress) - 为特定玩家获得所有游戏
  • getLegalActions(gameId, playerAddress?) - 为游戏中的玩家争取法律行动

调试方法( U)

  • getB52USDCBalance(address) - 获得B52USDC的地址余额
  • b52usdcToUsdc(amount) - 将b52USDC(微单位)转换为USDC显示格式
  • usdcToB52usdc(amount) - 将USDC转换为b52USDC(微单位)
  • calculateEquity(hands, board?, dead?, simulations?) - 通过Monte Carlo计算手股
  • calculateEquityFull(hands, board?, dead?, simulations?) - 用完整的元数据计算公平
  • listWithdrawalRequests(cosmosAddress?) - 除名请求(全部或具体地址)

地标

采用区块链集成的牌甲板管理.

方法

  • constructor(deck?: string) - 从元音字符串或新订购的甲板创建甲板
  • getNext() - 绘制下一张牌
  • deal(amount) - 发多张牌
  • toString() - 将甲板串起
  • shuffle(seed) - Shuffle甲板(仅测试,生产使用区块链随机性)

常数

  • Deck.DECK_SIZE - 标准甲板上的牌数(52)
  • Deck.RANK_MAP - 排序值图到字符串(A、T、J、Q、K)
  • Deck.SUIT_MAP - 服饰值图到字符串(C、D、H、S)

扑克索尔

手评和扑克逻辑.

静态方法

  • evaluatePartialHand(cards) - 评估扑克手力(部分或完整的手)
  • evaluateSevenCardHand(cards) - 从7张牌上评估最好的5张牌手
  • compareHands(hand1, hand2) - 用两只手来决定赢家

钱包公用事业

钱包管理费.

  • generateWallet(prefix?, wordCount?) - 生成一个带有随机元件的新钱包( 12或24个字)
  • createWalletFromMnemonic(mnemonic, prefix?) - 从现有元件创建钱包
  • getAddressFromMnemonic(mnemonic, prefix?) - 来自元音的衍生地址
  • isValidMnemonic(mnemonic) - 验证元音短语
  • BLOCK52_HD_PATH - Block52的标准Cosmos HD衍生路径

配置

网络终点

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"
};

实例

看看这个 实例 完整工作示例目录 :

举例来说:

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

发展

来源建筑

# Clone the repository
git clone https://github.com/block52/poker-vm.git
cd poker-vm/sdk

# Install dependencies
yarn install

# Build the SDK
yarn build

# Run tests
yarn test

# Lint code
yarn lint

发布到 npm

SDK在创建发行时通过GitHub Actions自动发布到npm.

自动出版程序

  1. 更新版本 内 package.json数字 :

    cd sdk
    # Edit package.json to update version (e.g., "1.1.9")
    
  2. 提交和推 版本更改 :

    git add package.json
    git commit -m "chore: update SDK version to 1.1.9"
    git push
    
  3. 创建 GitHub 发布 带有标签匹配 sdk-v*数字 :

    gh release create sdk-v1.1.9 --title "SDK v1.1.9" --notes "Release notes here"
    

GitHub 动作工作流程将自动:

  • 安装依赖关系
  • 运行测试
  • 构建 SDK
  • 校验软件包。 json 版本匹配发行标记
  • 向 npm 公开发布

重要注释 :

  • 释放标签必须从 sdk-v (例如, sdk-v1.1.9(中文(简体) )
  • 版本在 package.json 必须匹配标签版本(例如, 1.1.9 标记 sdk-v1.1.9(中文(简体) )
  • 这个 NPM_TOKEN 密钥必须在 GitHub 仓库设置中配置
  • 工作流程使用 --ignore-scripts 跳过 prepublishOnly 脚本已构建 SDK

项目结构

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)

类型脚本支持

这个SDK被用TypeScript来写,包括了完整的类型定义. 无额外 @types 需要软件包.

import type { GameStateResponseDTO, PlayerDTO, ActionDTO } from '@block52/poker-vm-sdk';

光圈类型

SDK定义了 单一真相来源 所有游戏类型:

  • GameStateResponseDTO - 线上游戏数据的根类型
  • TexasHoldemStateDTO - 游戏状态( 包含) players, (中文(简体) ), communityCards页:1
  • GameOptionsDTO - 游戏配置( 无) format 或者说 owner - 使用根字段)
  • PlayerDTO - 玩家资讯

见 克劳德·姆德 为完整的类型规则.

浏览器支持

SDK同时在Node.js和浏览器环境中工作. 对于浏览器的使用,可能需要为节点.js内置配置多填充:

// Example webpack config
module.exports = {
  resolve: {
    fallback: {
      "stream": require.resolve("stream-browserify"),
      "crypto": require.resolve("crypto-browserify"),
      "buffer": require.resolve("buffer/")
    }
  }
};

捐款

欢迎捐款! 请看 主要仓库 捐款准则.

许可证

麻省理工学院执照 - 看 自由主义 详细文件.

支助

更改日志

见 释放 用于版本历史和更改.

版本与发布记录

@block52/poker-vm-sdk 共发布 69 个版本,首次发布于 2025/12/14;过去 12 个月发布了 69 个版本。

版本发布日期距今
1.24.0latest2026/11/053 天前
1.23.02026/11/026 天前
1.22.02026/10/318 天前
1.21.02026/10/309 天前
1.19.02026/10/309 天前
1.17.02026/10/2811 天前

关于 @block52/poker-vm-sdk 的常见问题

@block52/poker-vm-sdk 是什么?

Block52 扑克VM 的脚本 SDK

如何安装 @block52/poker-vm-sdk?

在项目目录运行 npm install @block52/poker-vm-sdk,或使用 pnpm add / yarn add / bun add。

@block52/poker-vm-sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@block52/poker-vm-sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@block52/poker-vm-sdk 可以商用吗?

@block52/poker-vm-sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@block52/poker-vm-sdk 的下载量有多少?

根据 npm 官方下载统计,@block52/poker-vm-sdk 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,038 次,日均约 101 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@block52/poker-vm-sdk 还在维护吗?

最新版本 1.24.0 发布于 2026/11/05(3 天前);至今共发布 69 个版本,其中过去 12 个月发布了 69 个;首次发布于 2025/12/14。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。