Components for building on-chain game backends.
Game Core is a modular smart contract framework for creating fully on-chain games. It provides the foundational infrastructure -- game boards, player management, zone-based movement, rule systems, gas management, and randomness -- so game developers can focus on gameplay logic rather than boilerplate.
The framework follows a factory pattern: deploy the core infrastructure once, then dynamically create game instances with custom boards, zones, and rulesets.
Machine-readable repository context is available in llms.txt.
Recommended flow for autonomous tooling:
- Read
llms.txtand thisREADME.md - Validate JavaScript tests with
npm test - Validate Solidity transit lifecycle with
npm run test:solidity - Start integration from
contracts/src/v0.0/GameBoard.solandGameFactory.sol
Game Core is published to the Lucky Machines Verdaccio registry.
Set the registry profile for this repo:
npm run registry:local # http://localhost:4873
npm run registry:staging # https://staging-packages.luckymachines.io
npm run registry:prod # https://packages.luckymachines.io
npm run registry:set -- custom https://your-registry.example.com
npm run registry:pingThen install:
npm install @luckymachines/game-corePublish to the configured registry:
npm run publish:registryFor Hardhat projects, imports resolve automatically from node_modules:
import "@luckymachines/game-core/contracts/src/v0.0/GameBoard.sol";For Foundry projects, add a remapping to remappings.txt:
@luckymachines/game-core/=node_modules/@luckymachines/game-core/
forge install LuckyMachines/game-coreThen add the remapping to remappings.txt:
@luckymachines/game-core/=lib/game-core/
game-core/
├── contracts/
│ ├── src/v0.0/ # Solidity source contracts
│ │ ├── GameBoard.sol # Game board with zones and player positioning
│ │ ├── GameFactory.sol # Creates game boards and player registries
│ │ ├── GameRegistry.sol # Universal registry for all games
│ │ ├── GameController.sol # Player action submission
│ │ ├── GameEvents.sol # Centralized event emission
│ │ ├── GasStation.sol # Gas management for meta-transactions
│ │ ├── PlayerRegistry.sol # Player registration and management
│ │ ├── PlayZone.sol # Individual play zone logic
│ │ ├── PlayZoneFactory.sol # Factory for creating play zones
│ │ ├── RandomnessConsumer.sol # Chainlink VRF + Mock VRF
│ │ ├── Ruleset.sol # Game rule definitions
│ │ ├── libraries/
│ │ │ └── XYCoords.sol # Coordinate string generation (up to 50x50)
│ │ ├── custom_boards/
│ │ │ └── HexGrid.sol # Hexagonal grid board implementation
│ │ └── custom_zones/
│ │ ├── BackDoor.sol # Zone that kicks players to a specific path
│ │ └── LuckyDuck.sol # Zone with random path selection
│ └── abi/v0.0/ # Compiled contract ABIs
├── package.json
└── LICENSE # GPL-3.0-or-later
| Contract | Purpose |
|---|---|
| GameRegistry | Universal registry that tracks all game IDs and board addresses across the system |
| GameFactory | Creates new GameBoard + PlayerRegistry pairs; supports standard and custom boards |
| GameBoard | Manages game state, play zones, zone connections (inputs/outputs), and player positions |
| PlayerRegistry | Per-board player registration with limits, locking, and active/inactive tracking |
| PlayZone | Individual zone contract handling player entry/exit, capacity, and ruleset behavior |
| PlayZoneFactory | Factory for deploying new PlayZone instances |
| Ruleset | Configurable game rules: max capacity, entry/exit sizes, payouts, lockable rulesets |
| GameEvents | Centralized event emission contract decoupled from game state logic |
| GameController | Interface for players to submit actions |
| GasStation | Gas management contract for subsidizing player transactions |
| RandomnessConsumer | Randomness provider supporting Chainlink VRF v2 and mock VRF for testing |
| VRFVerifier | ECVRF-SECP256K1-SHA256-TAI proof verification library for AutoLoop VRF |
| Contract | Purpose |
|---|---|
| HexGrid | Extends GameBoard to create hexagonal grids of configurable width x height with coordinate-based zone aliases (e.g., "2,3") |
| BackDoor | Custom PlayZone that kicks players out to a designated path |
| LuckyDuck | Custom PlayZone with randomized path selection |
- Role-Based Access Control (RBAC): Uses OpenZeppelin's
AccessControlEnumerablewith custom roles (GAME_MASTER_ROLE,FACTORY_ROLE,VERIFIED_CONTROLLER_ROLE,PLAY_ZONE_ROLE,EVENT_SENDER_ROLE) - Factory Pattern:
GameFactoryandPlayZoneFactoryenable dynamic creation of game instances and zones - Registry Pattern:
GameRegistryandPlayerRegistryprovide enumerable tracking of games and players - Modular Zone Design:
PlayZoneserves as a base contract; custom zones inherit and override entry/exit behavior - Event-Driven Architecture:
GameEventscentralizes all event emission, allowing off-chain systems to subscribe to a single contract
- Deploy
GameRegistry(universal, one per ecosystem) - Deploy
GameFactory(points to the registry) - Deploy
Rulesetcontract(s) for your game rules - Deploy
PlayZoneimplementation(s) - Use
GameFactoryto createGameBoard+PlayerRegistrydynamically
GameBoard now includes first-class queued transit for moving multiple players in controlled batches:
queueExitToPaths(gameID, playerAddresses, pathIndices, transitID)- queue one transit batch from a PlayZonestartTransit(transitID)- mark the queued batch active_progressTransit(transitID)- controller processes up toMAX_BATCH_SIZEmoves per call
Status helpers:
getTransitLength(gameID, transitID)getTransitEntry(gameID, transitID, index)transitStarted(gameID, transitID)transitComplete(gameID, transitID)transitProgress(gameID, transitID)
Emitted events:
TransitQueuedTransitStartedTransitStepProcessedTransitCompleted
| Package | Version | Purpose |
|---|---|---|
@openzeppelin/contracts |
^5.5.0 | AccessControlEnumerable, ReentrancyGuard |
@chainlink/contracts |
^0.5.1 | VRF v2 randomness |
JavaScript tests:
npm testSolidity integration tests (Foundry):
npm run test:solidityThe transit lifecycle coverage lives in:
test/GameBoardTransit.t.soltest/GameBoardTransitBatch.t.sol(multi-call progression when queued actions exceedMAX_BATCH_SIZE)
Game Core supports three randomness approaches:
RandomnessConsumer provides a built-in mock VRF that uses blockhash-based pseudo-randomness. No external tokens or subscriptions required. Suitable for testing and low-cost deployments where provable fairness is not critical.
RandomnessConsumer also supports Chainlink VRF v2 for provably fair randomness. Requires a funded Chainlink VRF subscription and LINK tokens. Two-transaction pattern: request randomness, then a separate callback fulfills it.
VRFVerifier enables a single-transaction VRF pattern when combined with AutoLoop. The automation worker generates an ECVRF proof off-chain, passes it to progressLoop(), and the contract verifies the proof on-chain — all in one transaction.
Benefits over the 2-tx pattern:
- Cheaper — no separate VRF fulfillment transaction
- Faster — randomness arrives in the same call as game processing
- Cryptographically verifiable — ECVRF-SECP256K1-SHA256-TAI proof verified on-chain
- No Chainlink fees — no LINK tokens or VRF subscription needed
To use AutoLoop VRF in your game:
- Import
VRFVerifier.solfrom game-core - Use
AutoLoopVRFCompatiblefrom the autoloop repo as your base contract - Implement VRF proof generation in your automation worker (see Hexploration for a reference implementation)
An on-chain multiplayer explore & escape game played on a 10x10 hexagonal grid. Players explore zones, collect artifacts, draw event cards, and manage inventory across Day/Night phase cycles. 1-4 players per game. Uses 12+ contracts including the full Game Core framework with Chainlink VRF for randomness.
Repo: LuckyMachines/hexploration
A single-contract heist game where 2-4 rival operatives compete to crack a vault with 5 locks. Each round, players choose PICK, SEARCH, or SABOTAGE. Self-contained in one contract with on-chain pseudo-random resolution.
Repo: LuckyMachines/plundrix
games/ is treated as local workspace material (for example, local app builds or temporary checkouts) and is not the source of truth for Hexploration or Plundrix. The canonical code for those games is in their dedicated repositories above.
GPL-3.0-or-later (GNU General Public License v3)